Skip to content

Instantly share code, notes, and snippets.

@nedrocks
Created April 8, 2022 21:13
Show Gist options
  • Save nedrocks/4f54cf8a8189294926f3b27962610451 to your computer and use it in GitHub Desktop.
Save nedrocks/4f54cf8a8189294926f3b27962610451 to your computer and use it in GitHub Desktop.
Wallet connect hook first section
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