Skip to content

Commit

Permalink
fix balance input formated value
Browse files Browse the repository at this point in the history
  • Loading branch information
JayJay1024 committed Oct 19, 2023
1 parent 3b097db commit 0f8f347
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/apps/src/components/balance-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function BalanceInput({
token?: Token;
onChange?: (value: BalanceInputValue) => void;
}) {
const tokenRef = useRef(token);
const spanRef = useRef<HTMLSpanElement | null>(null);
const inputRef = useRef<HTMLInputElement | null>(null);
const [dynamicStyle, setDynamicStyle] = useState("text-sm font-normal");
Expand Down Expand Up @@ -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 (
<div
className={`lg:px-middle px-small py-small gap-small bg-app-bg normal-input-wrap relative flex items-center justify-between ${
Expand Down

0 comments on commit 0f8f347

Please sign in to comment.