Skip to content

Commit d0b689c

Browse files
brunota20kernelwhisperer
authored andcommitted
fix(wallet): detect restoring state when reconnectOnMount is false
1 parent 4197ad2 commit d0b689c

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1+
import { useSyncExternalStore } from 'react'
2+
13
import { useConnection } from 'wagmi'
24

35
import { useWalletInfo } from '../../api/hooks'
6+
import { config } from '../config'
7+
8+
function getCurrentConnectorUid(): string | null {
9+
return config.state.current ?? null
10+
}
11+
12+
function subscribeToCurrentConnectorUid(callback: () => void): () => void {
13+
return config.subscribe((state) => state.current, callback)
14+
}
415

516
export function useIsRestoringConnection(): boolean {
617
const { status } = useConnection()
718
const { account } = useWalletInfo()
819

9-
// WalletInfo is backed by an atom updated from wagmi, so account can lag behind
10-
// the connected status for one render. Keep showing reconnecting during that gap.
11-
return status === 'reconnecting' || (status === 'connected' && !account)
20+
const currentConnectorUid = useSyncExternalStore(subscribeToCurrentConnectorUid, getCurrentConnectorUid, () => null)
21+
22+
if (status === 'reconnecting') return true
23+
if (status === 'connected' && !account) return true
24+
if (!!currentConnectorUid && !account) return true
25+
26+
return false
1227
}

0 commit comments

Comments
 (0)