react-moralis
react-moralis copied to clipboard
deactivateWeb3 not working (I think)
New Bug Report
Checklist
- [x ] I am not disclosing a vulnerability.
- [x ] I have searched through existing issues and the Moralis Forum.
- [ \x] I can reproduce the issue with the latest react-moralis release, latest SDK release, and my server is updated to the latest version.
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
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.
Leaving open for visibility on that comment.
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