Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Slow portfolio balance calls can cause balance to show incorrectly #5027

Closed
kylehickinson opened this issue Feb 24, 2022 · 2 comments · Fixed by #5098
Closed

Slow portfolio balance calls can cause balance to show incorrectly #5027

kylehickinson opened this issue Feb 24, 2022 · 2 comments · Fixed by #5098

Comments

@kylehickinson
Copy link
Collaborator

If you switch to the same network multiple times (which will cause balance calls to execute) there is a chance for the balance calls to double-up as the assets for that network will be the same. The balances will then add up incorrectly.

Most likely there are race conditions between fetching balances and prices where userVisibleAssets is already set with some balances and thus its adding balances to a state that isn't currently 0.

@Pavneet-Sing
Copy link

After further usage:

  • It keeps on adding the original amount to the balance
  • The incorrect balance remains there after lock/unlock

Possible quick fixes:

  • Don't do anything if the newly selected network is same as the previous one
  • Show loading to block the selection until the balance is refreshed

@StephenHeaps StephenHeaps self-assigned this Mar 10, 2022
StephenHeaps added a commit that referenced this issue Mar 11, 2022
…which could cause us to double our balance if update is called repeatedly (changing networks, or choosing same network).
StephenHeaps added a commit that referenced this issue Mar 16, 2022
…which could cause us to double our balance if update is called repeatedly (changing networks, or choosing same network).
StephenHeaps added a commit that referenced this issue Mar 16, 2022
…5098)

* Fix race condition in `PortfolioStore`s update function which could cause us to double our balance if update is called repeatedly (changing networks, or choosing same network).
* Add `PortfolioStoreTests` for unit testing the `PortfolioStore`. Currently verifies `update()` will publish changes to it's various publishers correctly.
@iccub iccub added this to the 1.37 milestone Mar 17, 2022
@kjozwiak
Copy link
Member

kjozwiak commented Apr 7, 2022

Verification PASSED on iPhone 10 running 15.4.1 using 1.37 (22.4.6.8)

Went through the STR/Cases outlined via #5098 (comment) and ensured that the current balance wasn't appearing as $0.00 or was exceeding what's actually present.

Example Example
image image

Verification PASSED on iPhone 6+ running 14.6 using 1.37 (22.4.6.8)

Went through the STR/Cases outlined via #5098 (comment) and ensured that the current balance wasn't appearing as $0.00 or was exceeding what's actually present.

Example Example
image image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.