diff --git a/packages/dev-tools/src/summary/AccountSummary.tsx b/packages/dev-tools/src/summary/AccountSummary.tsx index 813f48238e..a2c9aa3c23 100644 --- a/packages/dev-tools/src/summary/AccountSummary.tsx +++ b/packages/dev-tools/src/summary/AccountSummary.tsx @@ -1,12 +1,15 @@ import { useEffect, useState } from "react"; -import { formatUnits } from "viem"; +import { formatUnits, parseEther, testActions } from "viem"; import { useDevToolsContext } from "../DevToolsContext"; export function AccountSummary() { const { publicClient, walletClient } = useDevToolsContext(); + const walletAddress = walletClient?.account?.address; + const testClient = publicClient.chain.id === 31337 ? publicClient.extend(testActions({ mode: "anvil" })) : null; const [balance, setBalance] = useState(null); + // TODO: switch to wagmi hooks useEffect(() => { if (!publicClient || !walletClient) return setBalance(null); const account = walletClient.account; @@ -18,21 +21,30 @@ export function AccountSummary() { }; updateBalance(); - const interval = setInterval(updateBalance, 5000); + const interval = setInterval(updateBalance, publicClient.pollingInterval); return () => clearInterval(interval); }, [publicClient, walletClient]); return (
Address
-
{walletClient?.account?.address}
+
{walletAddress}
Balance
-
+
{publicClient && balance != null ? ( - <> + {formatUnits(balance, publicClient.chain.nativeCurrency.decimals).replace(/(\.\d{4})\d+$/, "$1")}{" "} {publicClient.chain.nativeCurrency.symbol} - + + ) : null} + {walletAddress && testClient ? ( + ) : null}