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] Metamask window is not opening after disconnect #2033

Open
1 task done
josadcha opened this issue Jun 6, 2024 · 9 comments
Open
1 task done

[bug] Metamask window is not opening after disconnect #2033

josadcha opened this issue Jun 6, 2024 · 9 comments

Comments

@josadcha
Copy link

josadcha commented Jun 6, 2024

Is there an existing issue for this?

  • I have searched the existing issues

RainbowKit Version

2.1.1

wagmi Version

2.9.9

Current Behavior

After disconnecting from Metamask and doing an attempt to connect again, the Metamask window is not opened. Issue resolves after refreshing the page:

Screen.Recording.2024-06-06.at.12.34.44.PM.mp4

Expected Behavior

After disconnecting from Metamask and trying to initiate the connection again, the Metamask is triggered to be connected.

Steps To Reproduce

  1. Connect to Metamask
  2. DIsconnect
  3. Try to connect to Metamask again

(Sometimes the issue appears on the 2nd attempt, sometimes on the 3rd.

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

No response

Anything else?

No response

@magiziz
Copy link
Contributor

magiziz commented Jun 6, 2024

@josadcha Looking into this now

@REPTILEHAUS
Copy link

+1 Im also getting this and with the same Wagmi / Rainbowkit versions

@magiziz
Copy link
Contributor

magiziz commented Jun 7, 2024

I'm able to reproduce this as well. Reporting this to the wagmi team to see what's going on.

@ducls-2223
Copy link

+1 I'm also getting this with Wagmi/Rainbowkit version "latest"

@magiziz
Copy link
Contributor

magiziz commented Jun 12, 2024

Seems like this is a EIP-1193 and EIP-6963 issue. We should be deprecating EIP-1193 pretty soon and fix this. I'll keep this issue open meanwhile 👍

@babkenmes
Copy link

The problem is in disconnecting the wallet.

it becomes obvious after debugging packages/rainbowkit/src/components/ConnectOptions/DesktopOptions.tsx

  const connectToWallet = (wallet: WalletConnector) => {
    setConnectionError(false);
    if (wallet.ready) {
      wallet?.connect?.()?.catch(() => {
        setConnectionError(true);
      });
    }
  };

wallet.connect() throws ConnectorAlreadyConnectedError

The solution is to disconnect via direct connector. To achieve this you can utilize useAccount from wagmi.

const { connector } = useAccount()
const handleDisconnect = ()=>{
        connector && await connector.disconnect()
}

@babkenmes
Copy link

babkenmes commented Jun 18, 2024

In case you need more context on the issue, please don't hesitate to let me know. You can debug packages/core/src/actions/connect.ts and in case of disconnecting directly from connecter config.state.current becomes undefined but if useDisconnect hook is used it remains and wagmi throws the error.

  // Check if connector is already connected
  if (connector.uid === config.state.current)
    throw new ConnectorAlreadyConnectedError()

So it is not EIP-1193 or EIP-6963 issue but wagmi useDisconnect hook issue

@magiziz
Copy link
Contributor

magiziz commented Jun 19, 2024

@babkenmes We have metaMaskWallet EIP-1193 and EIP-6963 connector which shares the same window.ethereum instance, that's why it throws that error since it's marked as already "connected" from Wagmi.

Feel free to check out the wagmi issue here wevm/wagmi#4027. The issue should be resolved once we deprecate the EIP-1193 connectors 👍

@magiziz
Copy link
Contributor

magiziz commented Jun 19, 2024

Here is another EIP-1193 bug we've encountered wevm/wagmi#3606. As i said all these EIP-1193 breaking behaviours should be resolved once we migrate fully over to EIP-6963.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@REPTILEHAUS @babkenmes @josadcha @magiziz @ducls-2223 and others