diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 5008ddfc..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/packages/app/components/TokenIcon.tsx b/packages/app/components/TokenIcon.tsx index 2e28638c..fc8adca6 100644 --- a/packages/app/components/TokenIcon.tsx +++ b/packages/app/components/TokenIcon.tsx @@ -10,7 +10,7 @@ import { useState } from "react"; interface TokenIconProps { className?: string; - size?: "lg" | "md" | "sm" | "xs"; + size?: "lg" | "md" | "sm" | "xs" | "2xs"; token: Token; } @@ -65,11 +65,12 @@ export const tokenIconStyles = cva( lg: ["w-10 h-10 text-[7px]"], md: ["w-8 h-8 text-[6px]"], sm: ["w-6 h-6 text-[5px]"], - xs: ["w-5 h-5 text-[4px]"] - } + xs: ["w-5 h-5 text-[4px]"], + "2xs": ["w-4 h-4 text-[4px]"], + }, }, defaultVariants: { - size: "sm" - } + size: "sm", + }, } ); diff --git a/packages/app/components/stackbox/Stackbox.tsx b/packages/app/components/stackbox/Stackbox.tsx index 39a5bfa0..905de4ae 100644 --- a/packages/app/components/stackbox/Stackbox.tsx +++ b/packages/app/components/stackbox/Stackbox.tsx @@ -11,6 +11,8 @@ import { DatePicker, } from "@/components"; import { TokenFromTokenlist } from "@/models/token"; +import { useAccount, useBalance, useNetwork } from "wagmi"; +import { formatUnits } from "viem"; interface SelectTokenButtonProps { label: string; @@ -40,6 +42,12 @@ const startDateTimeTimestamp = new Date().setMinutes( new Date().getMinutes() + 30 ); +const balanceOptions = [ + { name: "25%", divider: 4 }, + { name: "50%", divider: 2 }, + { name: "Max", divider: 1 }, +]; + export const Stackbox = () => { 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,14 @@ export const Stackbox = () => { setEndDateTime(new Date(endDateByFrequency[frequency])); }, [frequency]); + const formattedBalance = (balanceData: NonNullable) => + balanceData.formatted === "0" + ? "0" + : parseFloat(balanceData.formatted).toLocaleString(undefined, { + maximumSignificantDigits: + balanceData.formatted.length - balanceData.decimals + 3, + }); + return ( <>
@@ -93,9 +117,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 (