threshold-network / token-dashboard

22 stars 23 forks source link

Bug caused by racing conditions in sdk initialization hook #749

Closed evandrosaturnino closed 2 months ago

evandrosaturnino commented 4 months ago

A bug was found in useInitializeTbtcSdk hook that causes a racing condition.

Video that illustrate the issue:

https://github.com/threshold-network/token-dashboard/assets/60587527/19a0594c-6468-4096-816c-c3137ef54baf

In order to reproduce the issue, the app should be refreshed and the wallet connected right after (Before the sdk without signer initialization process concludes), then you will see the "Connect Wallet" change to "Upgrade" on connection, then regressing to "Connect Wallet" after a few seconds.

The observed issue occurs because the SDK initializes at the launch of the decentralized application (dApp), and this initialization process is slower without a signer than with one. Specifically, when an account is connected, initialization with a signer is faster. However, if an account gets connected before the SDK has completed its initial setup, the SDK object reverts to the state it would be in if initialized without a signer.

michalsmiarowski commented 4 months ago

Here is a conversation for more context: https://github.com/threshold-network/token-dashboard/pull/736#discussion_r1556100655