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

refactor: simplify refresh balance triggers #6232

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kathaypacific
Copy link
Collaborator

@kathaypacific kathaypacific commented Nov 14, 2024

Description

This PR consolidates the way we are refreshing the token balances. I think we let this evolve organically for some time and it has become buggy and inconsistent.

Currently, before this change:

  • we have a bunch of watcher functions that seem overcomplicated (dispatching intermediate actions to trigger other sagas)
  • we need to remember to dispatch the fetchTokenBalances action after every flow that initiates a transaction. i think it is probably unavoidable to need to remember to trigger a balance fetch, but currently we dispatch a success action for the flow and a separate action for the balances (the dreaded double dispatch)
  • we forget to refresh balances in a bunch of places (e.g. swap flow) which means users can try (and fail) to execute other transactions with outdated balances.

This change:

  • remove the fetchTokenBalances action entirely and instead, trigger the balance refresh sagas on specific actions. i've tried to document them all.
  • there is a loading state that seems unnecessary in the home reducer, most flows were never allowing this loading state to be set. only the send flow was, i think that's a bug. balance refreshes should be a background task and not affect whether we show or hide the balance....
  • define balance refresh as a combination of refreshing token balances, exchange rates (the total balance is wrong if the exchange rate is outdated), positions so trigger all those sagas

Test plan

I should see a network request to refresh token balance, exchange rate, positions, shortcuts when I have:

  • completed onboarding
  • received a payment (transaction feed updated)
  • executed a transaction via any app flow

Related issues

Backwards compatibility

yes

Network scalability

If a new NetworkId and/or Network are added in the future, the changes in this PR will:

  • Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)

@kathaypacific kathaypacific marked this pull request as ready for review November 14, 2024 15:18
createFiatConnectTransferCompleted.type,
depositTransactionSucceeded.type,
swapSuccess.type,
],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is the main change

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 86.66667% with 4 lines in your changes missing coverage. Please review.

Project coverage is 88.96%. Comparing base (e34ca3b) to head (f9b094b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/fiatExchanges/saga.ts 50.00% 1 Missing ⚠️
src/home/saga.ts 92.30% 1 Missing ⚠️
src/localCurrency/saga.ts 50.00% 1 Missing ⚠️
src/positions/saga.ts 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6232      +/-   ##
==========================================
- Coverage   88.98%   88.96%   -0.02%     
==========================================
  Files         737      737              
  Lines       31449    31423      -26     
  Branches     5828     5521     -307     
==========================================
- Hits        27984    27955      -29     
- Misses       3267     3424     +157     
+ Partials      198       44     -154     
Files with missing lines Coverage Δ
src/account/saga.ts 75.35% <ø> (-0.35%) ⬇️
src/components/TokenBalance.tsx 97.65% <100.00%> (-0.02%) ⬇️
src/earn/saga.ts 95.65% <ø> (-0.07%) ⬇️
src/import/saga.ts 83.76% <ø> (-0.28%) ⬇️
src/localCurrency/actions.ts 77.77% <ø> (-22.23%) ⬇️
src/localCurrency/reducer.ts 68.42% <ø> (+6.51%) ⬆️
src/redux/migrations.ts 97.08% <100.00%> (+<0.01%) ⬆️
src/redux/store.ts 80.00% <ø> (ø)
src/send/saga.ts 77.01% <ø> (-0.52%) ⬇️
src/tokens/saga.ts 96.82% <100.00%> (+1.44%) ⬆️
... and 8 more

... and 65 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e34ca3b...f9b094b. Read the comment docs.

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.

1 participant