Skip to content

Commit

Permalink
Fix balance input formatted value (#540)
Browse files Browse the repository at this point in the history
* fix balance input formated value

* update check by decimals
  • Loading branch information
JayJay1024 authored Oct 19, 2023
1 parent 3b097db commit fa3aadc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 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,14 @@ export function BalanceInput({
}
}, [value, dynamic]);

useEffect(() => {
// Fire onChange to update `formatted`
if (tokenRef.current?.decimals !== token?.decimals) {
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 fa3aadc

Please sign in to comment.