From f5406ef7a29e8a48d7dffd4f3edfe16f7eb39c2f Mon Sep 17 00:00:00 2001 From: Berteotti Date: Wed, 2 Aug 2023 11:41:21 +0100 Subject: [PATCH] feat: create StackTokenPair --- .DS_Store | Bin 6148 -> 0 bytes packages/app/components/TokenIcon.tsx | 11 +-- packages/app/components/stackbox/Stackbox.tsx | 81 +++++++++++++++++- packages/app/ui/buttons/ChipButton.tsx | 15 ++-- packages/app/ui/buttons/base.ts | 4 +- 5 files changed, 96 insertions(+), 15 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 { const searchTokenBarRef = useRef(null); const [isConfirmStackOpen, setConfirmStackIsOpen] = useState(false); @@ -48,8 +56,16 @@ export const Stackbox = () => { const [tokenFrom, setTokenFrom] = useState(); const [tokenTo, setTokenTo] = useState(); - const [frequency, setFrequency] = useState(HOUR_OPTION); + const { chain } = useNetwork(); + const { address } = useAccount(); + const { data: balance } = useBalance({ + address: Boolean(tokenFrom) ? address : undefined, + token: tokenFrom?.address as `0x${string}`, + chainId: chain?.id, + }); + const [tokenAmount, setTokenAmount] = useState(""); + const [frequency, setFrequency] = useState(HOUR_OPTION); const [startDateTime, setStartDateTime] = useState( new Date(startDateTimeTimestamp) ); @@ -70,6 +86,28 @@ export const Stackbox = () => { setEndDateTime(new Date(endDateByFrequency[frequency])); }, [frequency]); + const formattedBalance = (balanceData: NonNullable) => { + const SIGNIFICANT_DIGITS = 5; + + /* parseFloat has limitations with big numbers, if number is too big it only shows part of it */ + const valueFloat = parseFloat(balanceData.formatted); + const [integer] = balanceData.formatted.split("."); + + const significantDigits = + integer === "0" + ? SIGNIFICANT_DIGITS + : integer.length + SIGNIFICANT_DIGITS; + + let valueString = "0"; + + if (valueFloat !== 0) + valueString = valueFloat.toLocaleString(undefined, { + maximumSignificantDigits: significantDigits, + }); + + return valueString; + }; + return ( <>
@@ -93,9 +131,48 @@ export const Stackbox = () => {
+ ["e", "E", "+", "-"].includes(evt.key) && evt.preventDefault() + } + onChange={(event) => { + setTokenAmount(event.target.value); + }} /> + {tokenFrom && balance && ( +
+
+ {balanceOptions.map(({ name, divider }) => ( + + ))} +
+
+ + + Balance:{" "} + {formattedBalance(balance)} + +
+
+ )}
diff --git a/packages/app/ui/buttons/ChipButton.tsx b/packages/app/ui/buttons/ChipButton.tsx index dbb03e65..06f413d1 100644 --- a/packages/app/ui/buttons/ChipButton.tsx +++ b/packages/app/ui/buttons/ChipButton.tsx @@ -14,18 +14,19 @@ interface ChipButtonProps extends ButtonHTMLAttributes { const chipButtonStyles = cva(["rounded-full px-3 py-2 space-x-1.5 text-xs"], { variants: { active: { - true: ["bg-gray-75"] + true: ["bg-gray-75"], }, size: { icon: "p-2", lg: "px-14 py-3 md:py-4 text-lg md:px-24 space-x-4", md: "px-8 md:px-12 py-2 space-x-2", - sm: "px-4 py-2 text-sm space-x-2" - } + sm: "px-4 py-2 text-sm space-x-2", + xs: "px-2 py-1 text-xs space-x-1", + }, }, defaultVariants: { - size: "sm" - } + size: "sm", + }, }); export function ChipButton({ @@ -35,7 +36,7 @@ export function ChipButton({ disabled, id, onClick, - size + size, }: ChipButtonProps) { return (