TrueFiEng / useDApp

Framework for rapid Dapp development. Simple. Robust. Extendable. Testable
https://usedapp.io
MIT License
1.59k stars 368 forks source link

changing network must wait for new block to update state #608

Open gsteenkamp89 opened 2 years ago

gsteenkamp89 commented 2 years ago

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:

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.

yivlad commented 2 years ago

Hello,

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