Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connector fails to update chain after wallet chain switch and page refresh #3998

Closed
1 task done
chybisov opened this issue May 31, 2024 · 5 comments
Closed
1 task done

Comments

@chybisov
Copy link
Contributor

chybisov commented May 31, 2024

Check existing issues

Describe the bug

After establishing the connection and changing the chain in the wallet, the new chain doesn't get picked up after the page refresh, and the connector shows the initially connected chain.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/vitejs-vite-wdirrm

Steps To Reproduce

  1. Connect wallet to MetaMask connector (let's say the initial chain is Optimism - 10)
  2. Switch chain inside MetaMask (e.g., switch to Polygon - 137) - this gets reflected correctly and shows a new chain
  3. Refresh the page
  4. After reconnection, the connector shows that the chainId is 10, while it should be 137

What Wagmi package(s) are you using?

wagmi, @wagmi/connectors

Wagmi Version

2.9.6

Viem Version

2.12.1

TypeScript Version

No response

Anything else?

This also affects all hooks returning current chain information like useAccount

@tmm
Copy link
Member

tmm commented Jun 6, 2024

Looks like a MetaMask Chrome extension issue. You can reproduce by running RPC requests in the browser console directly.

// start with extension on mainnet, then request accounts:
> await window.ethereum.request({ method: 'eth_requestAccounts' })
[...]
> await window.ethereum.request({ method: 'eth_chainId' })
'0x1'
> await window.ethereum.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: '0x89' }] })
> await window.ethereum.request({ method: 'eth_chainId' })
'0x89'
// switch in mm extension ui, then run the following:
> await window.ethereum.request({ method: 'eth_chainId' })
'0x89' // should be 0x1

In the video, you can see that the listener is fired for when the chain switches back to Mainnet via the MetaMask extension UI, but when you call 'eth_chainId' again, the response is not updated.

000930_Google.Chrome_2024-06-06-16.48.44.mp4

Confirmed that this is not an issue with the MetaMask Firefox Add-on or Rainbow Chrome extension.

@tmm tmm closed this as not planned Won't fix, can't repro, duplicate, stale Jun 6, 2024
@tmm
Copy link
Member

tmm commented Jun 6, 2024

Linking up MetaMask/metamask-extension#25097

@tmm
Copy link
Member

tmm commented Jun 6, 2024

Small patch if anyone wants to apply while MM fixes the issue

71b49b1

@chybisov
Copy link
Contributor Author

chybisov commented Jun 7, 2024

@tmm thank you for taking a look! I'll track MM issue 🙂

Copy link
Contributor

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Wagmi version. If you have any questions or comments you can create a new discussion thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants