Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions packages/nextjs/components/scaffold-eth/Balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import { useState } from "react";
import { Address } from "viem";
import { useAccountBalance } from "~~/hooks/scaffold-eth";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@

import { useBalance } from "wagmi";
import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork";
import { useGlobalState } from "~~/services/store/store";

type BalanceProps = {
address?: Address;
Expand All @@ -16,7 +17,17 @@ type BalanceProps = {
*/
export const Balance = ({ address, className = "", usdMode }: BalanceProps) => {
const { targetNetwork } = useTargetNetwork();
const { balance, price, isError, isLoading } = useAccountBalance(address);

const price = useGlobalState(state => state.nativeCurrencyPrice);
const {
data: balance,
isError,
isLoading,
} = useBalance({
address,
watch: true,
});

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

const toggleBalanceMode = () => {
Expand Down Expand Up @@ -44,6 +55,8 @@ export const Balance = ({ address, className = "", usdMode }: BalanceProps) => {
);
}

const formattedBalance = Number(balance?.formatted);

return (
<button
className={`btn btn-sm btn-ghost flex flex-col font-normal items-center hover:bg-transparent ${className}`}
Expand All @@ -53,11 +66,11 @@ export const Balance = ({ address, className = "", usdMode }: BalanceProps) => {
{displayUsdMode ? (
<>
<span className="text-[0.8em] font-bold mr-1">$</span>
<span>{(balance * price).toFixed(2)}</span>
<span>{(formattedBalance * price).toFixed(2)}</span>
</>
) : (
<>
<span>{balance?.toFixed(4)}</span>
<span>{formattedBalance.toFixed(4)}</span>
<span className="text-[0.8em] font-bold ml-1">{targetNetwork.nativeCurrency.symbol}</span>
</>
)}
Expand Down
8 changes: 6 additions & 2 deletions packages/nextjs/components/scaffold-eth/FaucetButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { useState } from "react";
import { createWalletClient, http, parseEther } from "viem";
import { hardhat } from "viem/chains";
import { useAccount, useNetwork } from "wagmi";
import { useBalance } from "wagmi";
import { BanknotesIcon } from "@heroicons/react/24/outline";
import { useAccountBalance, useTransactor } from "~~/hooks/scaffold-eth";
import { useTransactor } from "~~/hooks/scaffold-eth";

// Number of ETH faucet sends to an address
const NUM_OF_ETH = "1";
Expand All @@ -21,7 +22,10 @@ const localWalletClient = createWalletClient({
*/
export const FaucetButton = () => {
const { address } = useAccount();
const { balance } = useAccountBalance(address);

const { data: balance } = useBalance({
address,
});

const { chain: ConnectedChain } = useNetwork();

Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/hooks/scaffold-eth/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./useAccountBalance";
export * from "./useAnimationConfig";
export * from "./useBurnerWallet";
export * from "./useDeployedContractInfo";
Expand Down
36 changes: 0 additions & 36 deletions packages/nextjs/hooks/scaffold-eth/useAccountBalance.ts

This file was deleted.