useDApp icon indicating copy to clipboard operation
useDApp copied to clipboard

changing network must wait for new block to update state

Open gsteenkamp89 opened this issue 3 years ago • 1 comments

Consider the following simple example where I am reading the user's balance:

const { account, active } = useEthers();
const balance = useEtherBalance(account);

<div>
      {`Balance: ${balance ? formatEther(balance).slice(0, 5) : "0.00"} ETH`}
</div>

If the user switches networks in Metamask wallet, almost everything works as expected.

Dev tools output for reference:

Screenshot 2022-03-18 at 12 12 46

The following happens immediately:

  • (New Network) connected
  • A new multicall address is used.
  • 1 call updated (get Eth balacne now using the multicall address).

But NO state is updated... Only when a new block is found does the eth balance state update.

I'm not sure if this is a bug or an implementation detail, but I'd like to see an immediate update of any state based on chain reads as soon as either account or network changes.

gsteenkamp89 avatar Mar 18 '22 10:03 gsteenkamp89

Hello,

does the issue persist for you with the latest useDApp version?

yivlad avatar Jun 08 '22 12:06 yivlad