react-moralis icon indicating copy to clipboard operation
react-moralis copied to clipboard

deactivateWeb3 not working (I think)

Open PatrickAlphaC opened this issue 3 years ago • 3 comments

New Bug Report

Checklist

Issue Description

I have a component that looks like this:

import { useMoralis } from "react-moralis"

// Top navbar
export default function Navbar() {
  const { enableWeb3, isWeb3Enabled, deactivateWeb3, isWeb3EnableLoading } = useMoralis()

  return (
    <nav>
      <ul>
        <li>
          {isWeb3Enabled ? (
            <button
              onClick={() => {
                deactivateWeb3()
              }}
            >
              Disconnect
            </button>
          ) : (
            <button
              onClick={() => enableWeb3()}
              disabled={isWeb3EnableLoading}
            >
              Connect
            </button>
          )}
        </li>
      </ul>
    </nav>
  )
}

However, when you click Disconnect, the wallet is still connected and doesn't disconnet. What is going on?

Expected Outcome

I expect my metamask to "disconnet" but it stays connected.

Server

  • Moralis server version: None

Environment

"react-moralis": "^1.2.4",
"moralis": "^1.2.7",

MacOS Montery 12.1 Brave & Chrome browser

PatrickAlphaC avatar Feb 09 '22 01:02 PatrickAlphaC

Ah... looks like Metamask sort of overloads the term connected. https://docs.metamask.io/guide/ethereum-provider.html#methods

Note that this method has nothing to do with the user's accounts.

You may often encounter the word "connected" in reference to whether a web3 site can access the user's accounts. In the provider interface, however, "connected" and "disconnected" refer to whether the provider can make RPC requests to the current chain.

It might be nice to have a hook for like "disconnect" or something that actually truly disconnects.

PatrickAlphaC avatar Feb 09 '22 02:02 PatrickAlphaC

Leaving open for visibility on that comment.

PatrickAlphaC avatar Feb 09 '22 02:02 PatrickAlphaC

I am not sure if that's even possible to do with Metamask. As far as I know, it is not possible to disconnect a metamask wallet from code, only via their app-extention

ErnoW avatar Feb 09 '22 19:02 ErnoW