From 1600a19c76563b7d1b3af28f6ed731d942f75a92 Mon Sep 17 00:00:00 2001 From: fabryscript Date: Wed, 12 Jun 2024 18:55:11 +0200 Subject: [PATCH] feat: add price-selector --- .../components/control/token-select-limit.tsx | 59 +------ .../components/swap-tool/price-selector.tsx | 160 ++++++++++++++++++ 2 files changed, 168 insertions(+), 51 deletions(-) create mode 100644 packages/web/components/swap-tool/price-selector.tsx diff --git a/packages/web/components/control/token-select-limit.tsx b/packages/web/components/control/token-select-limit.tsx index ea98677655..5c16268af2 100644 --- a/packages/web/components/control/token-select-limit.tsx +++ b/packages/web/components/control/token-select-limit.tsx @@ -8,6 +8,7 @@ import { FunctionComponent, useMemo } from "react"; import { Icon } from "~/components/assets"; import { TokenSelectModalLimit } from "~/components/modals/token-select-modal-limit"; +import PriceSelector from "~/components/swap-tool/price-selector"; import { Disableable } from "~/components/types"; import { EventName } from "~/config"; import { useAmplitudeAnalytics, useWindowSize } from "~/hooks"; @@ -175,57 +176,13 @@ export const TokenSelectLimit: FunctionComponent< )} -
-
- {quoteAsset && ( -
- - {orderDirection === OrderDirection.Bid - ? "Pay with" - : "Receive"} - - {quoteAsset.coinImageUrl && ( -
- token icon -
- )} - - {quoteAsset.coinDenom} - -
- )} -
- {showQuoteBalance && ( - - {formatPretty(quoteFiatBalance, { - minimumFractionDigits: 5, - })}{" "} - available - - )} - -
-
-
+ setIsSelectOpen(false)} diff --git a/packages/web/components/swap-tool/price-selector.tsx b/packages/web/components/swap-tool/price-selector.tsx new file mode 100644 index 0000000000..ba4722638d --- /dev/null +++ b/packages/web/components/swap-tool/price-selector.tsx @@ -0,0 +1,160 @@ +import { Menu, Transition } from "@headlessui/react"; +import { CoinPretty, PricePretty } from "@keplr-wallet/unit"; +import classNames from "classnames"; +import Image from "next/image"; +import { parseAsString, useQueryState } from "nuqs"; +import React, { Fragment } from "react"; + +import { Icon } from "~/components/assets"; +import { Disableable } from "~/components/types"; +import { SwapAsset } from "~/hooks/use-swap"; +import { formatPretty } from "~/utils/formatter"; + +interface PriceSelectorProps { + quoteAsset: SwapAsset & + Partial<{ + amount: CoinPretty; + usdValue: PricePretty; + }>; + tokenSelectionAvailable: boolean; + showQuoteBalance: boolean; + quoteFiatBalance: PricePretty; +} + +const UI_DEFAULT_STABLES = [ + { + name: "USDC", + symbol: "USDC", + logoURIs: { + svg: "https://raw.githubusercontent.com/cosmos/chain-registry/master/_non-cosmos/ethereum/images/usdc.svg", + }, + }, + { + name: "Tether", + symbol: "USDT", + logoURIs: { + svg: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/usdt.svg", + }, + }, +]; + +export default function PriceSelector({ + quoteAsset, + tokenSelectionAvailable, + disabled, + showQuoteBalance, + quoteFiatBalance, +}: PriceSelectorProps & Disableable) { + const [tab] = useQueryState("tab"); + const [quote, setQuote] = useQueryState( + "quote", + parseAsString.withDefault("USDC") + ); + + return ( + + +
+ {quoteAsset && ( +
+ + {tab === "buy" ? "Pay with" : "Receive"} + + {quoteAsset.coinImageUrl && ( +
+ token icon +
+ )} + + {quoteAsset.coinDenom} + +
+ )} +
+ {showQuoteBalance && ( + + {formatPretty(quoteFiatBalance, { + minimumFractionDigits: 5, + })}{" "} + available + + )} +
+ +
+
+
+
+ + +
+ {UI_DEFAULT_STABLES.map(({ name, symbol, logoURIs }) => { + const isSelected = quote === symbol; + + return ( + + {({ active }) => ( + + )} + + ); + })} +
+
+
+
+ ); +}