useDApp icon indicating copy to clipboard operation
useDApp copied to clipboard

[Feature Request] Update balance

Open cwagner22 opened this issue 3 years ago • 2 comments

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 avatar Aug 15 '22 13:08 cwagner22

@cwagner22 It should update, so maybe there is some problem of misconfiguration.

  1. Does the value update correctly after you refresh the page or open it again in new tab?
  2. Do you have maybe refresh parameter configured in your useDApp config?

rzadp avatar Aug 16 '22 11:08 rzadp

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 everyBlock parameter, 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.

Xzirez avatar Aug 17 '22 13:08 Xzirez

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.

rzadp avatar Aug 22 '22 09:08 rzadp

Thanks, I wasn't aware of refresh: 'everyBlock' but I had another issue in my code preventing the balance update.

cwagner22 avatar Aug 26 '22 14:08 cwagner22

@cwagner22 Awesome. If it's feasible, feel free to share the issue you had and the solution, maybe it could help others.

rzadp avatar Aug 26 '22 14:08 rzadp