Skip to content

Instantly share code, notes, and snippets.

@Josh4324
Last active May 10, 2022 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Josh4324/9e6d01d35759f51ea881a67276fd220c to your computer and use it in GitHub Desktop.
Save Josh4324/9e6d01d35759f51ea881a67276fd220c to your computer and use it in GitHub Desktop.
disconnect
const disconnectWallet = async () => {
localStorage.removeItem("wall");
web3Modal = new Web3Modal({
network: "rinkeby", // optional
cacheProvider: true, // optional
providerOptions, // required
});
await web3Modal.clearCachedProvider();
setAddress("");
};
useEffect(() => {
if (localStorage.getItem("wall")) {
// Assign the Web3Modal class to the reference object by setting it's `current` value
// The `current` value is persisted throughout as long as this page is open
web3ModalRef.current = new Web3Modal({
network: "rinkeby",
providerOptions: {},
disableInjectedProvider: false,
});
connectWallet();
}
setBalance(0);
// if wallet is not connected, create a new instance of Web3Modal and connect the MetaMask wallet
}, [address]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment