Skip to content

Commit 1af8bfc

Browse files
committed
feat(app): using watchWalletUpdated and watchDisconnect
1 parent 0b39443 commit 1af8bfc

File tree

3 files changed

+28
-38
lines changed

3 files changed

+28
-38
lines changed

Diff for: app/app.vue

+10-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ useHead({
2121
},
2222
})
2323
24-
const { addConnectors, onWalletUpdated, onDisconnected } = useVueDapp()
24+
const { addConnectors, watchWalletUpdated, watchDisconnect } = useVueDapp()
2525
if (process.client) {
2626
addConnectors([
2727
new BrowserWalletConnector(),
@@ -49,11 +49,16 @@ if (process.client) {
4949
5050
const { setWallet, resetWallet } = useEthers()
5151
52-
onWalletUpdated(async (wallet: ConnWallet) => {
53-
setWallet(wallet.provider)
54-
})
52+
watchWalletUpdated(
53+
async (wallet: ConnWallet) => {
54+
setWallet(wallet.provider)
55+
},
56+
{
57+
immediate: true,
58+
},
59+
)
5560
56-
onDisconnected(() => {
61+
watchDisconnect(() => {
5762
resetWallet()
5863
})
5964

Diff for: app/components/content/Multicall.vue

+9-20
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ const tokenList = computed(() => {
7777
7878
const balances = ref<{ mainnet: number[]; arbitrum: number[] }>({ mainnet: [], arbitrum: [] })
7979
80-
const { isConnected, wallet, onWalletUpdated, onDisconnected } = useVueDapp()
80+
const { watchWalletUpdated, watchDisconnect } = useVueDapp()
8181
82-
onMounted(async () => {
83-
if (isConnected.value) {
82+
watchWalletUpdated(
83+
async (wallet: ConnWallet) => {
8484
const mainnetBalance = await Promise.all([
8585
mainnetDai.balanceOf(wallet.address),
8686
mainnetUsdc.balanceOf(wallet.address),
@@ -92,24 +92,13 @@ onMounted(async () => {
9292
arbitrumAusdc.balanceOf(wallet.address),
9393
])
9494
balances.value = { mainnet: mainnetBalance, arbitrum: arbitrumBalance }
95-
}
96-
})
97-
98-
onWalletUpdated(async (wallet: ConnWallet) => {
99-
const mainnetBalance = await Promise.all([
100-
mainnetDai.balanceOf(wallet.address),
101-
mainnetUsdc.balanceOf(wallet.address),
102-
mainnetAusdc.balanceOf(wallet.address),
103-
])
104-
const arbitrumBalance = await Promise.all([
105-
arbitrumDai.balanceOf(wallet.address),
106-
arbitrumUsdc.balanceOf(wallet.address),
107-
arbitrumAusdc.balanceOf(wallet.address),
108-
])
109-
balances.value = { mainnet: mainnetBalance, arbitrum: arbitrumBalance }
110-
})
95+
},
96+
{
97+
immediate: true,
98+
},
99+
)
111100
112-
onDisconnected(() => {
101+
watchDisconnect(() => {
113102
balances.value = { mainnet: [], arbitrum: [] }
114103
})
115104

Diff for: app/pages/index.vue

+9-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ useHead({
1111
1212
const defaultProvider = new ethers.JsonRpcProvider('https://ethereum-rpc.publicnode.com')
1313
14-
const { wallet, isConnected, disconnect, onWalletUpdated, onDisconnected } = useVueDapp()
14+
const { wallet, isConnected, disconnect, watchWalletUpdated, watchDisconnect } = useVueDapp()
1515
1616
const {
1717
ensName,
@@ -27,19 +27,15 @@ const {
2727
ignorePreviousFetch: ignorePreviousFetchBalance,
2828
} = useBalance(defaultProvider)
2929
30-
onMounted(() => {
31-
if (isConnected.value) {
32-
fetchEnsName(wallet.address!)
33-
fetchBalance(wallet.address!)
34-
}
35-
})
36-
37-
onWalletUpdated((wallet: ConnWallet) => {
38-
fetchEnsName(wallet.address)
39-
fetchBalance(wallet.address)
40-
})
30+
watchWalletUpdated(
31+
(wallet: ConnWallet) => {
32+
fetchEnsName(wallet.address)
33+
fetchBalance(wallet.address)
34+
},
35+
{ immediate: true },
36+
)
4137
42-
onDisconnected(() => {
38+
watchDisconnect(() => {
4339
ignorePreviousFetchEnsName()
4440
ignorePreviousFetchBalance()
4541
})

0 commit comments

Comments
 (0)