Skip to content

Commit

Permalink
fix: prevent usd values flashing when input changes
Browse files Browse the repository at this point in the history
Signed-off-by: Griko Nibras <[email protected]>
  • Loading branch information
grikomsn committed Nov 23, 2023
1 parent a22908f commit 3b9e0cf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/UsdValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export const UsdValue = ({
}: UsdValueProps) => {
const { data: usdValue = 0, isLoading } = useUsdValue(args);

const prevValue = useRef(usdValue);
useEffect(() => {
if (!isLoading && prevValue.current !== usdValue) {
prevValue.current = usdValue;
}
}, [isLoading, usdValue]);

const contextStore = useContext(ctx);
useEffect(() => {
if (contextStore && context) {
Expand All @@ -25,6 +32,9 @@ export const UsdValue = ({
}
});

if (isLoading && prevValue.current) {
return <>{`$${prevValue.current.toFixed(2)}`}</>;
}
return <>{isLoading ? loading : `$${usdValue.toFixed(2)}`}</>;
};

Expand Down

0 comments on commit 3b9e0cf

Please sign in to comment.