[Feature Request] Update balance
useEtherBalance never seems to update the balance.
The problem is there is a Transfer button in my app, which then should decrease the displayed balance once done. What is the recommended way to show the updated balance?
@cwagner22 It should update, so maybe there is some problem of misconfiguration.
- Does the value update correctly after you refresh the page or open it again in new tab?
- Do you have maybe
refreshparameter configured in your useDApp config?
Hi @rzadp,
If I understand you correctly the solution if we want to implement a "subscription" for the balance is:
- We change the config file to include an
everyBlockparameter, which will refresh on every x block that gets created.
If this is correct my follow-up question would be - is this not resource extensive? Given that the confirmation rate on the polygon network can be around 2 seconds.
What I would rather do in our specific scenario is to:
- Wait for the transaction to be processed, then subtract a given amount from the user's cached balance.
Let me know if am mistaken and there are in fact no resource issues with the refresh option outlined above.
Hey @Xzirez,
If you don't have refresh parameter in your config, it defaults to everyBlock - that's why I feel there is something wrong, because it should just update automatically.
If this is correct my follow-up question would be - is this not resource extensive? Given that the confirmation rate on the polygon network can be around 2 seconds.
Yes it could be, that's why we introduced the option to refresh every N blocks. So there is a tradeoff between updating frequently, or having stale data but less impact on RPC provider.
Wait for the transaction to be processed, then subtract a given amount from the user's cached balance.
Sounds good, BUT - if the user receives some ether from an unrelated transaction, or sends some other transaction in a different tab, the data displayed is incorrect. But it might be an acceptable risk.
Thanks, I wasn't aware of refresh: 'everyBlock' but I had another issue in my code preventing the balance update.
@cwagner22 Awesome. If it's feasible, feel free to share the issue you had and the solution, maybe it could help others.