Skip to content

Commit

Permalink
fix: app.tsx rerendering bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashshah committed Sep 14, 2023
1 parent c98dcb0 commit 9a65b4f
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions src/hooks/useAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useEffect, useState } from 'react';
import { useConnectWallet, useSetChain } from '@web3-onboard/react';
import { ethers } from 'ethers';

export const useAccount = () => {
const [{ wallet, connecting }, connect, disconnect, updateBalances, setWalletModules, setPrimaryWallet] =
useConnectWallet();
const [address, setAddress] = useState<string>(wallet && wallet.accounts.length > 0 ? wallet.accounts[0].address : undefined);

const [{ chains, connectedChain, settingChain }, setChain] = useSetChain();

Expand All @@ -17,18 +15,6 @@ export const useAccount = () => {
setChain({ chainId: ethers.utils.hexValue(desiredChain) });
};

useEffect(() => {
if(wallet && wallet.accounts.length > 0) {
setAddress(wallet.accounts[0].address);
(async () => {
const ethersProvider = new ethers.providers.Web3Provider(wallet.provider);
const signer = ethersProvider.getSigner();
const walletAddress = await signer.getAddress();
setAddress(walletAddress);
})();
}
}, [wallet]);

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

0 comments on commit 9a65b4f

Please sign in to comment.