Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge-ui): fix wrong balance updates on network switch #15980

Merged
merged 2 commits into from
Feb 22, 2024
Merged

fix(bridge-ui): fix wrong balance updates on network switch #15980

merged 2 commits into from
Feb 22, 2024

Conversation

shak58
Copy link
Contributor

@shak58 shak58 commented Feb 22, 2024

Description:

There's a race condition in balance updates when switching networks. The updateBalance function is concurrently called by onNetworkChange and onAccountChange handlers leading to incorrect balance displays. This was because of the asynchronous execution of updateBalance, which when invoked by onNetworkChange, would update to the new network's balance. However, a simultaneous call from onAccountChange would still be running with data from the old network, sometimes resulting in the balance being updated with the outdated balance.
Due to being a race condition, the issue only happens some of the time when switching the network.

Steps to Reproduce:

  1. Navigate to the network switch interface where you can select between different blockchain networks.
  2. Observe the current network's displayed balance.
  3. Use the network dropdowns to switch to a different network.
  4. Switch back and forth between the two networks multiple times.
  5. Notice that occasionally the balance label does not update accordingly and remains displaying the balance from the previous network despite the network change being reflected in the UI.

Resolution:

To address this issue, I added a check within the onAccountChange handler. Now, it verifies whether onNetworkChange already triggeres a updateBalance call due to a network switch. Thus updateBalance is not called with stale data on network change.

Screenshot of the issue:

The screenshot bellow demonstrates the issue. It shows the user interface when executing the network switch, and how the balance was erroneously updated to 1 ETH instead of 10 ETH.

Balance Update Issue and Fix

@dantaik dantaik requested a review from KorbinianK February 22, 2024 01:15
@shak58 shak58 changed the title fix(bridge-ui-v2): fix wrong balance updates on network switch fix(bridge-ui): fix wrong balance updates on network switch Feb 22, 2024
@dantaik dantaik requested a review from je4nt0nic February 22, 2024 01:17
Copy link
Contributor

@KorbinianK KorbinianK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will remove the onNetwork util, as with wagmi v2 it is all handled via account events. But good spot :)

@KorbinianK KorbinianK requested review from dionysuzx, dantaik, davidtaikocha and xiaodino and removed request for je4nt0nic February 22, 2024 08:01
@dantaik dantaik added this pull request to the merge queue Feb 22, 2024
Merged via the queue into taikoxyz:main with commit b556e00 Feb 22, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants