-
Notifications
You must be signed in to change notification settings - Fork 7
/
WagmiReads.tsx
48 lines (45 loc) · 1.81 KB
/
WagmiReads.tsx
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
36
37
38
39
40
41
42
43
44
45
46
47
48
import { WagmiMintExample } from '../../contracts/WagmiMintExample.sol'
import { Address, useAccount, useChainId, useContractRead } from 'wagmi'
import styles from './WagmiReads.module.css'
export const WagmiReads = () => {
const chainId = useChainId()
const { address, isConnected } = useAccount()
const { data: balance } = useContractRead({
/**
* Spreading in a method will spread abi, address and args
* Hover over balanceOf and click go-to-definition should take you to the method definition in solidity if compiling from solidity
*/
...WagmiMintExample.read({ chainId }).balanceOf(address as Address),
enabled: isConnected,
})
const { data: totalSupply } = useContractRead({
...WagmiMintExample.read({ chainId }).totalSupply(),
enabled: isConnected,
})
const { data: symbol } = useContractRead({
...WagmiMintExample.read({ chainId }).symbol(),
enabled: isConnected,
})
return (
<div className={styles.container}>
<div className={styles.infoItem}>
<div className={styles.columnContainer}>
<div className={styles.methodName}>client balanceOf(<span className={styles.highlight}>{address}</span>):</div>
<div className={styles.methodValue}><span className={styles.highlight}>{balance?.toString()}</span></div>
</div>
</div>
<div className={styles.infoItem}>
<div className={styles.columnContainer}>
<div className={styles.methodName}>totalSupply():</div>
<div className={styles.methodValue}><span className={styles.highlight}>{totalSupply?.toString()}</span></div>
</div>
</div>
<div className={styles.infoItem}>
<div className={styles.columnContainer}>
<div className={styles.methodName}>symbol():</div>
<div className={styles.methodValue}><span className={styles.highlight}>{symbol?.toString()}</span></div>
</div>
</div>
</div>
);
}