osiastedian / syscoin-bridge

syscoin-bridge.vercel.app
1 stars 1 forks source link

Pali balance update only when Pali extension is invoked #5

Closed sidhujag closed 2 years ago

sidhujag commented 2 years ago

When is Pali balance updated in the site? i had 0.09 but then i did 2 0.1 transfers from NEVM to SYS and I have 0.29.. but the website kept showing 0.09 until i opened Pali then it updated the balance on the site, possible to update Pali balance when you click on the site sections which show the balance?

osiastedian commented 2 years ago

We are monitoring the wallet state on this part of the code. onWalletUpdate based on example: https://docs.paliwallet.com/guide/Wallet.html#onwalletupdate

https://github.com/osiastedian/syscoin-bridge/blob/main/contexts/PaliWallet/Provider.tsx#L101

We then store the walletState and derive the balance from there on this line:

https://github.com/osiastedian/syscoin-bridge/blob/main/contexts/PaliWallet/Provider.tsx#L222

sidhujag commented 2 years ago

can you also trigger calling wallet balance when you load the section of site that reads balance

osiastedian commented 2 years ago

@sidhujag

Added fix above to use react-query https://github.com/osiastedian/syscoin-bridge/commit/a09d32d74dad08716c7fff6cdeb26d9b955545ec

Should fetch on window focus which is an event fired after interacting with PaliWallet.

osiastedian commented 2 years ago

Added a refetch interval of every 1s incase there are other background transactions done outside bridge.

sidhujag commented 2 years ago

Doesn't work, this change introduces a new bug:

Go to new transfer page, goto pali send sys from account 1 to account 2, go back to new transfer page and your page will be now stuck, try to go to my transfers and it will be stuck loading or really slow (even get 500 sometimes)

osiastedian commented 2 years ago

Okay. will revert fix and try to another.

osiastedian commented 2 years ago

@sidhujag

Updated loading of controller.

https://user-images.githubusercontent.com/11253903/185287405-31678de4-2b2e-4ddc-bfde-9688eace13f0.mov

sidhujag commented 2 years ago

@osiastedian why do you register that callback once, that is the fix because on multiple loads there becomes multiple callbacks? shouldn't the callback state be destroyed when you switch context so you can register again next time you goto that screen?

osiastedian commented 2 years ago

@sidhujag

So PaliWalletContext is available on AppLevel as a Singleton context and ideally should just load the controller once upon initialization of the app.

sidhujag commented 2 years ago

So why if its singleton do you still check and register it once explicitly? How does that fix it?

osiastedian commented 2 years ago

Yeah debugged it and the cause was the dependency array was incorrect.

https://github.com/osiastedian/syscoin-bridge/commit/06d95ec5d9e15f9fea80729f1ddd6203fed2bbf1#diff-2dd85a0b44d5d96274579b4be9f1b05d6979b062994953badf8ca134c95f1709L123

I've been calling "setController" but it doesn't really take effect since it was not declared on the deps array.

sidhujag commented 2 years ago

ok cool