rainbow-me / rainbowkit

The best way to connect a wallet 🌈 🧰
https://rainbowkit.com
MIT License
2.36k stars 617 forks source link

ConnectButton Displays Wallet Connected to Last Stored Chain, Not Current Chain in MetaMask #2038

Closed QalbeHabib closed 1 week ago

QalbeHabib commented 3 weeks ago

Is there an existing issue for this?

RainbowKit Version

2.0.5

wagmi Version

2.5.20

Current Behavior

I encountered an issue when using RainbowKit with MetaMask in my application as well as in some of the popular application like

https://www.rainbowkit.com/docs/connect-button https://app.cabana.fi/ https://www.base.org/ecosystem https://swap.defillama.com/ https://pro.opensea.io/

. The problem arises when the user changes the network in MetaMask after initially connecting to the application. Here are the steps to reproduce the issue:

Connect to the application using MetaMask. Ensure MetaMask is connected to a supported chain. Change the network in MetaMask to the unsupported chain. Reload the browser tab. It shows the connected button with the last chain instead of showing "Wrong wallet" as the chain is not supported in Metamask.

Expected Behavior

Steps To Reproduce

  1. Connect to the application with MetaMask on a supported chain.
  2. Change the network in MetaMask to another supported chain.
  3. Observe the ConnectButton showing "Wrong network."
  4. Reload the page.
  5. Observe the ConnectButton displaying the wallet connected to the last stored chain, not the current chain in MetaMask.

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

No response

Anything else?

I have attached a reference video showcasing the issue for better understanding: Watch Video

The video demonstrates the problem where the ConnectButton displays the wallet connected to the last stored chain instead of the current chain in MetaMask after a network change. This issue is reproducible and affects user experience, especially in scenarios where network changes are frequent.

Your attention to this matter and feedback on resolving this issue would be highly appreciated.

magiziz commented 3 weeks ago

@QalbeHabib Thanks for spotting the bug, i'm able to reproduce this as well. We've had a few unusual behaviors from MetaMask lately and i'll report this to the Wagmi team 👍

magiziz commented 3 weeks ago

@QalbeHabib This seems to be a MetaMask issue. Wagmi is also impacted by this https://github.com/wevm/wagmi/issues/3998

magiziz commented 1 week ago

Closing this issue since this is a MetaMask specific issue which is impacted by all dApps.