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

feat(wallet): Apply persistent token/account balance for the rest of the wallet #24072

Merged
merged 5 commits into from
Jun 14, 2024

Conversation

nuo-xu
Copy link
Contributor

@nuo-xu nuo-xu commented Jun 7, 2024

Resolves brave/brave-browser#36764
brave/brave-browser#36693
Wallet has now cached account/token balance since brave/brave-browser#35986
But only Portfolio/Assets is reading the cached balance.
This PR make the rest of the wallet first checking cached value and will fetch via core api if there is none cached balance.

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Perform a sanity test to make sure balances are displayed correctly in wallet.
Most of the screens should have faster rendering since we are reading the cached value. But some screens have limited improvement since we are still asynchronously fetching asset prices and NFT metadata.

@nuo-xu nuo-xu added CI/skip-android Do not run CI builds for Android CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-windows-x64 Do not run CI builds for Windows x64 labels Jun 7, 2024
@nuo-xu nuo-xu requested a review from StephenHeaps June 7, 2024 18:59
@nuo-xu nuo-xu self-assigned this Jun 7, 2024
@nuo-xu nuo-xu requested a review from a team as a code owner June 7, 2024 18:59
Copy link
Collaborator

@StephenHeaps StephenHeaps left a comment

Choose a reason for hiding this comment

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

Do these stores need WalletUserAssetDataObserver.cachedBalanceRefreshed() implemented?

@nuo-xu nuo-xu force-pushed the wallet/ios-balance-caching branch from 89a02a2 to 1b31dc5 Compare June 13, 2024 18:15
Copy link
Contributor

[puLL-Merge] - brave/brave-core@24072

Description

This PR updates the logic for fetching and caching token balances across various wallet stores in the Brave iOS app. It introduces the use of WalletUserAssetDataObserver to observe changes in cached balances and trigger updates in the UI. The motivation seems to be to improve performance by utilizing cached balances where possible instead of always fetching from the network.

Changes

Changes

  • AccountActivityStore.swift:
    • Updates the logic to first fetch balances from cache if available, falling back to fetching from network if not found in cache
    • Adds support for WalletUserAssetDataObserver to observe balance changes and trigger updates
  • AccountsStore.swift:
    • Updates balance fetching logic to use cached balances if available
    • Adds support for WalletUserAssetDataObserver
  • AssetDetailStore.swift, NFTDetailStore.swift, NFTStore.swift, PortfolioStore.swift, SelectAccountTokenStore.swift, SendTokenStore.swift, SwapTokenStore.swift, TransactionConfirmationStore.swift:
    • Similar changes to use cached balances and support WalletUserAssetDataObserver
  • RpcServiceExtensions.swift:
    • Removes unused fetchTotalBalance function
  • WalletUserAssetManager.swift:
    • Removes data observers on deinit

Possible Issues

  • The changes add more complexity around balance fetching and caching. It will be important to thoroughly test various scenarios to ensure balances are being accurately cached and invalidated when necessary.
  • There is some code duplication around the caching logic that could potentially be refactored and consolidated.

Overall, the changes seem reasonable to improve performance by better utilizing cached data. Just need to be diligent with testing and monitoring after the changes to watch out for any balance inconsistencies or caching bugs.

Copy link
Collaborator

@StephenHeaps StephenHeaps left a comment

Choose a reason for hiding this comment

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

No need for assignment to transactionsSections (causes uneeded view update), otherwise lgtm.

@nuo-xu nuo-xu merged commit 46c0d37 into master Jun 14, 2024
19 checks passed
@nuo-xu nuo-xu deleted the wallet/ios-balance-caching branch June 14, 2024 14:18
@github-actions github-actions bot added this to the 1.69.x - Nightly milestone Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip-android Do not run CI builds for Android CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-windows-x64 Do not run CI builds for Windows x64 puLL-Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wallet: Persist balance for the rest of wallet other than Portfolio/Assets
2 participants