Skip to content

Instantly share code, notes, and snippets.

@nedrocks
Created April 8, 2022 21:19
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 nedrocks/cfd749fab9e89e6a66c8cb8e70aebff4 to your computer and use it in GitHub Desktop.
Save nedrocks/cfd749fab9e89e6a66c8cb8e70aebff4 to your computer and use it in GitHub Desktop.
Use wallet connect 3
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