Closed ferostabio closed 1 year ago
I think we have two basic choices here.
1- Use something like wagmi
and its useBalance
hook. We would have to call it for each token (at least, the ones selected) plus the chain's main one and we would be notified when it changes. As far as I could see in they're code, they do it on a block basis so it would be pretty quick.
2- Use our own sdk's getTokenBalancesFor
function each x seconds.
I'm all about 2
and eventually adding events to the sdk, so it's the sdk the one doing the polling and the frontend is simply notified whenever there's a change.
Hey @ferostar "Token" exposes some methods that return rxjs observables about the balances and the allowances:balanceOfStream()
and allowanceStream()
.
We have never used them. Check it out and let me know if smth like this could work. We can refactor them so that they suit better the need of the FE. If not, I was thinking to remove them because rxjs is pretty heavy.
@brozorec I think simple, good old polling each n
seconds would be better. I would remove those functions and rxjs
from the sdk
, the whole interface is... I can do it, as part of the task.
@brozorec I think simple, good old polling each
n
seconds would be better. I would remove those functions andrxjs
from thesdk
, the whole interface is... I can do it, as part of the task.
Ok, let's do that :+1:
@brozorec have a look at the balance-polling
branch, haven't implemented anything yet but already removed the streaming functionality from the sdk
. If I'm not mistaken, it only reduced its size by 2kb, but we weren't using it, so...
If the user makes any transaction that changes its balance, the user needs to refresh the webpage in order to see the updated balance. We need to add an event and listen to balance changes in order to reflect all changes as soon as possible.