Skip to content

Commit

Permalink
fix: app re-render when connected to scw
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashshah committed Sep 18, 2023
1 parent 9a65b4f commit 69949c7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/hooks/useAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useConnectWallet, useSetChain } from '@web3-onboard/react';
import { ethers } from 'ethers';
import { useMemo } from 'react';

export const useAccount = () => {
const [{ wallet, connecting }, connect, disconnect, updateBalances, setWalletModules, setPrimaryWallet] =
Expand All @@ -15,6 +16,10 @@ export const useAccount = () => {
setChain({ chainId: ethers.utils.hexValue(desiredChain) });
};

const provider = useMemo(() => {
return wallet ? new ethers.providers.Web3Provider(wallet.provider, 'any') : undefined;
}, [wallet]);

return {
wallet,
connecting,
Expand All @@ -23,7 +28,7 @@ export const useAccount = () => {
updateBalances,
setWalletModules,
setPrimaryWallet,
provider: wallet ? new ethers.providers.Web3Provider(wallet.provider, 'any') : undefined,
provider,
account: wallet && wallet.accounts.length > 0 ? ethers.utils.getAddress(wallet.accounts[0].address) : undefined,
chainId: connectedChain ? Number(connectedChain.id) : undefined,
isActive,
Expand Down

0 comments on commit 69949c7

Please sign in to comment.