Skip to content

Commit

Permalink
Add use effect on Balance component for the price (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
carletex committed May 31, 2024
1 parent c670c1f commit 5df118e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/nextjs/components/scaffold-eth/Balance.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useState } from "react";
import { useEffect, useState } from "react";
import { Address, formatEther } from "viem";
import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork";
import { useWatchBalance } from "~~/hooks/scaffold-eth/useWatchBalance";
Expand Down Expand Up @@ -28,6 +28,10 @@ export const Balance = ({ address, className = "", usdMode }: BalanceProps) => {

const [displayUsdMode, setDisplayUsdMode] = useState(price > 0 ? Boolean(usdMode) : false);

useEffect(() => {
setDisplayUsdMode(price > 0 ? Boolean(usdMode) : false);
}, [usdMode, price]);

const toggleBalanceMode = () => {
if (price > 0) {
setDisplayUsdMode(prevMode => !prevMode);
Expand Down

0 comments on commit 5df118e

Please sign in to comment.