Created
April 8, 2022 21:19
-
-
Save nedrocks/cfd749fab9e89e6a66c8cb8e70aebff4 to your computer and use it in GitHub Desktop.
Use wallet connect 3
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 activateProvider = async () => { | |
setInternalState({ | |
...internalState, | |
loading: true, | |
}); | |
const web3Modal = getWeb3Modal(); | |
try { | |
const provider = await web3Modal.connect(); | |
await activate(provider); | |
setInternalState({ | |
...internalState, | |
error: null, | |
loading: false, | |
}); | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
} catch (error: any) { | |
setInternalState({ | |
...internalState, | |
error: error, | |
loading: false, | |
}); | |
} | |
}; | |
const handleDeactivate = () => { | |
deactivate(); | |
getWeb3Modal().clearCachedProvider(); | |
}; | |
return { | |
loading: internalState.loading || isLoading, | |
active, | |
account: account || null, | |
ensAddress: ens || null, | |
library, | |
error: internalState.error || error?.toString() || null, | |
activateProvider, | |
deactivate: handleDeactivate, | |
activateBrowserWallet, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment