Last active
May 10, 2022 13:50
-
-
Save Josh4324/9e6d01d35759f51ea881a67276fd220c to your computer and use it in GitHub Desktop.
disconnect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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