Fujicracy / fuji-v2

Cross-chain money market aggregator
https://fuji-v2-frontend.vercel.app
15 stars 10 forks source link

Balance polling #357

Closed ferostabio closed 1 year ago

ferostabio commented 1 year ago

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.

ferostabio commented 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.

brozorec commented 1 year ago

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.

ferostabio commented 1 year ago

@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 commented 1 year ago

@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.

Ok, let's do that :+1:

ferostabio commented 1 year ago

@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...