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

[ABW-3254] Account resources background refresh #1194

Merged
merged 4 commits into from
Jul 5, 2024

Conversation

danvleju-rdx
Copy link
Contributor

@danvleju-rdx danvleju-rdx commented Jul 2, 2024

Jira ticket: ABW-3254

Description

This PR implements the logic for background refresh of account resources on the Home screen and Account Details screen.

The following reload use cases were added:

  • When a user navigates to a specific account, that account's balances are immediately reloaded.
  • When a user stays on an account screen with the wallet open, that account's balances are reloaded every 1 minute.
  • When a user returns to the Home screen and keeps the wallet open, all account balances are reloaded every 5 minutes.

How to test

The refresh interval can be decreased by adjusting the values of accountPortfoliosRefreshIntervalInSeconds and accountPortfolioRefreshIntervalInSeconds.

Copy link
Contributor

@matiasbzurovski matiasbzurovski left a comment

Choose a reason for hiding this comment

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

Looking great! one small comment only on the code.

One thing I had discussed with @kugel3 in the past is that we have many reducers that could probably be removed. For example, each of the children displayed on the AssetsView (FungibleAssetList, NonFungibleAssetList, StakeUnitList & PoolUnitsList) have its own reducer and state, and in 3 of these cases they are just about displaying data and calling delegate when selected.

The reason I am bringing this up is because now that we want to perform updates on the parent (AssetsView), it makes even less sense to have the children with their state allowing a mutating func from given class. It would make more sense in my opinion to just handle the updates in one place.


private func scheduleFetchAccountPortfolioTimer(_ state: State) -> Effect<Action> {
.run { [address = state.account.address] _ in
await withTaskCancellation(id: CancellableId.fetchAccountPortfolio, cancelInFlight: true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any difference between this withTaskCancellation and adding .cancellable(id: CancellableId.fetchAccountPortfolio, cancelInFlight: true) to the .run effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does the same thing, and yes, .cancellable looks cleaner. Updated

for sectionID: Section.State.ID
) -> FungibleAssetList.Section.Row.State? {
guard
let xrdSection = sections.first(where: { $0.id == sectionID }),
Copy link
Contributor

Choose a reason for hiding this comment

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

this should probably be named section since it doesn't need to be for XRD

@danvleju-rdx
Copy link
Contributor Author

@matiasbzurovski Yes, we could remove those reducers, but since we plan to add UITableView here, it’s probably not worth refactoring right now. However, I did some refactoring and split the AssetsView code into separate files for better readability. Additionally, I moved the update functions to AssetsView+Update.

Copy link
Contributor

@GhenadieVP GhenadieVP left a comment

Choose a reason for hiding this comment

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

LGTM!
nice and much awaited improvement.

@danvleju-rdx danvleju-rdx merged commit 93513e5 into main Jul 5, 2024
6 checks passed
@danvleju-rdx danvleju-rdx deleted the ABW-3254-account-resources-background-refresh branch July 5, 2024 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants