From 0f8f347f781dc4a2385a06f548d6a702042bdbdb Mon Sep 17 00:00:00 2001 From: JayJay1024 Date: Thu, 19 Oct 2023 13:39:59 +0800 Subject: [PATCH] fix balance input formated value --- packages/apps/src/components/balance-input.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/apps/src/components/balance-input.tsx b/packages/apps/src/components/balance-input.tsx index 8728bf1f4..97cbdd473 100644 --- a/packages/apps/src/components/balance-input.tsx +++ b/packages/apps/src/components/balance-input.tsx @@ -30,6 +30,7 @@ export function BalanceInput({ token?: Token; onChange?: (value: BalanceInputValue) => void; }) { + const tokenRef = useRef(token); const spanRef = useRef(null); const inputRef = useRef(null); const [dynamicStyle, setDynamicStyle] = useState("text-sm font-normal"); @@ -66,6 +67,13 @@ export function BalanceInput({ } }, [value, dynamic]); + useEffect(() => { + if (!tokenRef.current && token) { + onChange({ value: value?.value || "", formatted: parseUnits(value?.value || "0", token?.decimals || 0) }); + } + tokenRef.current = token; + }, [value, token, onChange]); + return (