wagmi: bug: The useWalletClient() hook returns undefined after opening the application in a new tab while using MetaMask.
Is there an existing issue for this?
- I have searched the existing issues
Package Version
1.3.9
Current Behavior
After connecting to the application with the MetaMask wallet using the browser and attempting to open the app in a different tab multiple times, the useWalletClient() hook randomly returns undefined. but MetaMask shows that wallet is connected, it’s even possible to retrieve connected account address.
However, after refreshing the page, the useWalletClient() hook starts behaving correctly.
Expected Behavior
Every time when user opens tab useWalletClient() should return data when wallet is connected.
Expected behavior is correct for “WalletConnect” provider.
Steps To Reproduce
1.Connect your MetaMask Wallet to application (Link Below)
2.You can see useWalletClient() data been printed.
3.Try to open application in different tab multiple time (As it described in below video)
4.Randomly useWalletClient() data is undefined, and wallet is still connected
Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)
https://sandbox-snowy-ten.vercel.app/
Anything else?
SandBox: url
https://github.com/wagmi-dev/wagmi/assets/58769030/f033c6ed-1758-473c-be41-84a799c088ff
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 3
- Comments: 21 (9 by maintainers)
I have the same issue.
const handleConnect = useCallback(async () => { if (address) return try { const result = await metaMaskConnector?.connect() config.store?.setState(prevState => ({ …prevState, data: result, status: ‘reconnecting’, })) } catch { /** * Don’t do anything */ } }, [metaMaskConnector, address])
I had to use the next action from
@wagmi/corehttps://wagmi.sh/core/actions/getWalletClient