Created
April 8, 2022 21:13
-
-
Save nedrocks/4f54cf8a8189294926f3b27962610451 to your computer and use it in GitHub Desktop.
Wallet connect hook first section
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
import { | |
useEthers, | |
useLookupAddress, | |
} from '@usedapp/core'; | |
import { JsonRpcProvider } from '@ethersproject/providers'; | |
import WalletConnectProvider from '@walletconnect/web3-provider'; | |
import Web3Modal from 'web3modal'; | |
import { useState } from 'react'; | |
type InternalState = { | |
loading: boolean; | |
error?: string | null; | |
}; | |
const initialState = { | |
loading: false, | |
error: null, | |
}; | |
export type WalletConnectState = { | |
loading: boolean; | |
active: boolean; | |
account: string | null; | |
ensAddress: string | null; | |
library: JsonRpcProvider | undefined; | |
error: string | null, | |
activateProvider: () => void, | |
deactivate: () => void, | |
activateBrowserWallet: () => void, | |
} | |
export const useWalletConnect = () => { | |
const [internalState, setInternalState] = | |
useState<InternalState>(initialState); | |
const ens = useLookupAddress(); | |
const { | |
isLoading, | |
active, | |
account, | |
library, | |
error, | |
activate, | |
deactivate, | |
activateBrowserWallet, | |
} = useEthers(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment