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

[bug] Disconnects after switching network #563

Closed
1 task done
enesozturk opened this issue Jun 7, 2022 · 6 comments
Closed
1 task done

[bug] Disconnects after switching network #563

enesozturk opened this issue Jun 7, 2022 · 6 comments

Comments

@enesozturk
Copy link

enesozturk commented Jun 7, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

^0.4.6

Current Behavior

I'm using Wagmi with Rainbow Kit for our project. Today I realized that when I change the network I connected, data from the useAccount hook and activeChain from the useNetwork start returning null and undefined. The weird thing is that it's not happening every time, looks like there is a race condition and when I keep switching networks, it disconnects me at a point.

You can try with the link I created on CodeSandbox.

Expected Behavior

Keep returning data with the switched network. As a result, it disconnects me, I mean I see the rainbow button in the disconnected state.

Steps To Reproduce

  • Sign in with MetaMask on Mainnet
  • On MetaMask extension, switch another network from dropdown
  • Keep doing this. Especially when you switch from Mainnet to Polygon or vice versa cause it faster.

Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)

https://codesandbox.io/s/magical-gwen-8zx2x8?file=/src/App.js:253-263

Anything else?

Screen.Recording.2022-06-07.at.19.41.42.mov
@tmm
Copy link
Member

tmm commented Jun 7, 2022

Unfortunately, there is a bug with MetaMask that causes this when using the extension interface MetaMask/metamask-extension#13375 (comment)

We try to mitigate this as much as possible when switching networks programmatically with wagmi (e.g. useNetwork and shimChainChangedDisconnect defaulted to true for MetaMaskConnector).

@tmm tmm closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2022
@enesozturk
Copy link
Author

Thanks for the response @tmm 🤞🏽

@ryanberckmans
Copy link

ryanberckmans commented Feb 21, 2023

hey @tmm 👋

As indicated in this thread and in MetaMask/metamask-extension#13375, despite passing { shimDisconnect: true, shimChainChangedDisconnect: true }, the wallet can still involuntarily disconnect when the user switches the chain from inside the metamask browser extension.

Yet, when testing this on a mature non-wagmi app such as Uniswap, we're able to switch (to, from) any chain in the metamask browser extension without the Uniswap UI involuntarily disconnecting. What is it that the Uniswap UI is doing that wagmi isn't doing now, and could we start doing it?

Alternatively, maybe my wagmi is misconfigured and there is something else I should be doing to prevent the metamask browser extension from involuntarily disconnecting when switching chains inside the extension?

For reference:

new MetaMaskConnector({
  chains,
  options: {
    shimDisconnect: true,
    shimChainChangedDisconnect: true,
  },
}),

@tmm
Copy link
Member

tmm commented Mar 3, 2023

Looks correct! Want to create a new issue with a minimal reproducible example and I can take a look?

@ryanberckmans
Copy link

Looks correct! Want to create a new issue with a minimal reproducible example and I can take a look?

#1941

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 other comments you can create a new discussion.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 12, 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

3 participants