-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathBalance.tsx
More file actions
35 lines (32 loc) · 876 Bytes
/
Balance.tsx
File metadata and controls
35 lines (32 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React from "react";
import type { Token } from "@ant-design/web3";
import { CryptoPrice } from "@ant-design/web3";
import { useReadErc20BalanceOf } from "@/utils/contracts";
import { useAccount } from "wagmi";
import useTokenAddress from "@/hooks/useTokenAddress";
interface Props {
token?: Token;
}
export default function Balance(props: Props) {
const { address } = useAccount();
const tokenAddress = useTokenAddress(props.token);
const { data: balance } = useReadErc20BalanceOf({
address: tokenAddress,
args: [address as `0x${string}`],
query: {
enabled: !!tokenAddress,
// 每 3 秒刷新一次
refetchInterval: 3000,
},
});
return balance === undefined ? (
"-"
) : (
<CryptoPrice
value={balance}
symbol={props.token?.symbol}
decimals={props.token?.decimal}
fixed={2}
/>
);
}