Skip to content

Commit c4a40f5

Browse files
committed
update
1 parent 7c74d7f commit c4a40f5

File tree

4 files changed

+8429
-4528
lines changed

4 files changed

+8429
-4528
lines changed

examples/nextjs/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"superjson": "^2.0.0",
2222
"undici": "^5.26.3",
2323
"valtio": "^1.11.2",
24-
"viem": "^1.20.0",
25-
"wagmi": "^1.4.4",
24+
"viem": "^2.17.11",
25+
"wagmi": "^2.12.0",
2626
"zod": "^3.22.4"
2727
},
2828
"devDependencies": {

examples/nextjs/src/app/page.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ import { EditionInfo } from '@/components/editionInfo'
55
import { WalletPrivateKeyInput } from '@/components/walletInput'
66
import { useContractAddress } from '@/context/contractAddress'
77
import { useWallet } from '@/context/wallet'
8-
import { useBalance } from 'wagmi'
8+
import { useQueryClient } from '@tanstack/react-query'
9+
import { useEffect } from 'react'
10+
import { useBlockNumber, useBalance } from 'wagmi'
911

1012
export default function Home() {
1113
const { wallet } = useWallet()
1214

13-
const balance = useBalance({
15+
const queryClient = useQueryClient()
16+
const { data: blockNumber } = useBlockNumber({ watch: true })
17+
const { data: balance, queryKey } = useBalance({
1418
address: wallet?.account.address,
15-
watch: true,
1619
})
20+
useEffect(() => {
21+
queryClient.invalidateQueries({ queryKey })
22+
}, [blockNumber, queryClient, queryKey])
1723

1824
const {
1925
contractAddress,
@@ -33,7 +39,7 @@ export default function Home() {
3339
{wallet && (
3440
<>
3541
<p>Balance of {wallet.account.address}</p>
36-
<p>{balance.data ? `${Number(balance.data.formatted).toFixed(5)} eth` : 'Loading...'}</p>
42+
<p>{balance?.decimals != null ? `${Number(balance.decimals).toFixed(5)} eth` : 'Loading...'}</p>
3743
<br />
3844
</>
3945
)}

examples/nextjs/src/context/wagmi.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ export const publicClient = createPublicClient({
3434
.extend(soundEditionVersionPublicActions)
3535

3636
const config = createConfig({
37-
autoConnect: true,
38-
publicClient,
37+
chains: [chain],
38+
transports: {
39+
[chain.id]: http(RPC_URL),
40+
},
3941
})
4042

4143
export function WagmiContext({ children }: { children: React.ReactNode }) {

0 commit comments

Comments
 (0)