Skip to content

Commit

Permalink
metamask refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
H34D committed Mar 7, 2023
1 parent 8680279 commit 2c9d487
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/provider/use-metamask.ts
Expand Up @@ -77,17 +77,18 @@ export const useMetamask = ({
]);

/**
* Disconnect
* Disconnect from metamask
*/
const disconnectMetamask = useCallback(async (): Promise<void> => {
localStorageSet<boolean>(metamaskStorageKey, false);

if (walletAddress) {
await handleLogout?.();
localStorageSet<boolean>(metamaskStorageKey, false);
}
}, [walletAddress, handleLogout, localStorageSet]);

/**
* try to connect metamask but not if already connected
* try to connect metamask on page load
*/
useEffect(() => {
const connectMetamaskOnPageLoad = async (): Promise<void> => {
Expand Down Expand Up @@ -137,7 +138,7 @@ export const useMetamask = ({
/**
* on accounts change
*/
window?.ethereum?.on(
window.ethereum?.on(
'accountsChanged',
async (accounts: unknown): Promise<void> => {
const accountsArray = accounts as string[];
Expand All @@ -157,7 +158,7 @@ export const useMetamask = ({
/**
* on network / chain changed
*/
window?.ethereum?.on('chainChanged', async () => {
window.ethereum?.on('chainChanged', async () => {
setProvider?.(getWeb3Provider()?.getSigner());
});
}
Expand Down

0 comments on commit 2c9d487

Please sign in to comment.