Skip to content

Commit 256b41c

Browse files
committed
refactor: network sync
1 parent c85ac29 commit 256b41c

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/hooks/useNetworkStatus.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,27 @@ export function useNetworkStatus({
3838
const network = networks.find((x) => x.rpcUrl === client.key)
3939

4040
if (network) {
41-
let updatedNetwork = {}
42-
4341
// If chain becomes out of sync, update to the new chain.
4442
if (
4543
chainId &&
4644
network.rpcUrl === client.key &&
4745
network.chainId !== chainId
48-
)
49-
updatedNetwork = { ...updatedNetwork, chainId }
46+
) {
47+
upsertNetwork({
48+
network: { chainId },
49+
rpcUrl: client.key,
50+
})
51+
}
5052

5153
// If there is no fork block number, update to the current block number.
5254
if (typeof network.forkBlockNumber !== 'bigint') {
53-
updatedNetwork = {
54-
...updatedNetwork,
55-
forkBlockNumber: await client.getBlockNumber(),
56-
}
55+
;(async () => {
56+
upsertNetwork({
57+
network: { forkBlockNumber: await client.getBlockNumber() },
58+
rpcUrl: client.key,
59+
})
60+
})()
5761
}
58-
59-
if (Object.keys(updatedNetwork).length > 0)
60-
upsertNetwork({
61-
network: updatedNetwork,
62-
rpcUrl: client.key,
63-
})
6462
}
6563

6664
return chainId

0 commit comments

Comments
 (0)