Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed useAccountBalance #788

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 = balance ? Number(balance.formatted) : 0;

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
13 changes: 10 additions & 3 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,11 @@ const localWalletClient = createWalletClient({
*/
export const FaucetButton = () => {
const { address } = useAccount();
const { balance } = useAccountBalance(address);

const { data: balance } = useBalance({
technophile-04 marked this conversation as resolved.
Show resolved Hide resolved
address,
technophile-04 marked this conversation as resolved.
Show resolved Hide resolved
watch: true,
});

const { chain: ConnectedChain } = useNetwork();

Expand Down Expand Up @@ -50,10 +55,12 @@ export const FaucetButton = () => {
return null;
}

const isBalanceZero = balance && balance.value === 0n;

return (
<div
className={
balance
!isBalanceZero
? "ml-1"
: "ml-1 tooltip tooltip-bottom tooltip-secondary tooltip-open font-bold before:left-auto before:transform-none before:content-[attr(data-tip)] before:right-0"
}
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.