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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions RadixWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,8 @@
E7B7A0FD2BBBFB6100EEE900 /* HeaderListViewContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B7A0FC2BBBFB6100EEE900 /* HeaderListViewContainer.swift */; };
E7B7A1052BC904E800EEE900 /* NewConnectionApproval+Reducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B7A1042BC904E800EEE900 /* NewConnectionApproval+Reducer.swift */; };
E7B7A1072BC904EE00EEE900 /* NewConnectionApproval+View.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B7A1062BC904EE00EEE900 /* NewConnectionApproval+View.swift */; };
E7D8D8C22C35349F00032417 /* AssetsView+Selection.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7D8D8C12C35349F00032417 /* AssetsView+Selection.swift */; };
E7D8D8C42C35373800032417 /* AssetsView+Update.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7D8D8C32C35373800032417 /* AssetsView+Update.swift */; };
E7FAE65D2BF0F2EC00620273 /* NewConnectionFeatureTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7FAE65B2BF0F2EC00620273 /* NewConnectionFeatureTests.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -2304,6 +2306,8 @@
E7B7A0FC2BBBFB6100EEE900 /* HeaderListViewContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderListViewContainer.swift; sourceTree = "<group>"; };
E7B7A1042BC904E800EEE900 /* NewConnectionApproval+Reducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NewConnectionApproval+Reducer.swift"; sourceTree = "<group>"; };
E7B7A1062BC904EE00EEE900 /* NewConnectionApproval+View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NewConnectionApproval+View.swift"; sourceTree = "<group>"; };
E7D8D8C12C35349F00032417 /* AssetsView+Selection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AssetsView+Selection.swift"; sourceTree = "<group>"; };
E7D8D8C32C35373800032417 /* AssetsView+Update.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AssetsView+Update.swift"; sourceTree = "<group>"; };
E7FAE65B2BF0F2EC00620273 /* NewConnectionFeatureTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewConnectionFeatureTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -3812,6 +3816,8 @@
children = (
48CFBE342ADC10D800E77A5C /* AssetsView+Reducer.swift */,
48CFBE672ADC10D800E77A5C /* AssetsView+View.swift */,
E7D8D8C12C35349F00032417 /* AssetsView+Selection.swift */,
E7D8D8C32C35373800032417 /* AssetsView+Update.swift */,
48CFBE352ADC10D800E77A5C /* Components */,
);
path = AssetsFeature;
Expand Down Expand Up @@ -7216,6 +7222,7 @@
48CFC33B2ADC10D900E77A5C /* DappInteractionLoading.swift in Sources */,
48CFC34A2ADC10D900E77A5C /* PersonaDataPermission+View.swift in Sources */,
48CFC53D2ADC10DA00E77A5C /* MetadataI32ArrayValue.swift in Sources */,
E7D8D8C42C35373800032417 /* AssetsView+Update.swift in Sources */,
A462B5A42B8384FB00C26D20 /* CoreAPI_PlaintextMessageContent.swift in Sources */,
48CFC4312ADC10DA00E77A5C /* PublicKey+Extensions.swift in Sources */,
48CFC2CE2ADC10D900E77A5C /* ReceivingAccount+Reducer.swift in Sources */,
Expand Down Expand Up @@ -7358,6 +7365,7 @@
48CFC56E2ADC10DA00E77A5C /* TransactionStatus.swift in Sources */,
48CFC5392ADC10DA00E77A5C /* NonFungibleResourcesCollectionItemVaultAggregated.swift in Sources */,
48CFC36D2ADC10D900E77A5C /* FungibleAssetList+Row+Reducer.swift in Sources */,
E7D8D8C22C35349F00032417 /* AssetsView+Selection.swift in Sources */,
A462B5B92B90C57400C26D20 /* ResourceBalanceButton.swift in Sources */,
48CFC4EC2ADC10DA00E77A5C /* NonFungibleResourcesCollectionItemVaultAggregatedVault.swift in Sources */,
A47809082BDBDB4C006B68C0 /* RadixDateFormatter.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import SwiftUI

// MARK: - AccountDetails
public struct AccountDetails: Sendable, FeatureReducer {
private enum CancellableId: Hashable {
case fetchAccountPortfolio
}

public struct State: Sendable, Hashable, AccountWithInfoHolder {
public var accountWithInfo: AccountWithInfo
var assets: AssetsView.State
Expand All @@ -29,6 +33,7 @@ public struct AccountDetails: Sendable, FeatureReducer {

public enum ViewAction: Sendable, Equatable {
case task
case onDisappear
case backButtonTapped
case preferencesButtonTapped
case transferButtonTapped
Expand Down Expand Up @@ -116,6 +121,9 @@ public struct AccountDetails: Sendable, FeatureReducer {
@Dependency(\.appPreferencesClient) var appPreferencesClient
@Dependency(\.dappInteractionClient) var dappInteractionClient
@Dependency(\.securityCenterClient) var securityCenterClient
@Dependency(\.accountPortfoliosClient) var accountPortfoliosClient

private let accountPortfolioRefreshIntervalInSeconds = 60

public init() {}

Expand All @@ -141,6 +149,10 @@ public struct AccountDetails: Sendable, FeatureReducer {
}
}
.merge(with: securityProblemsEffect())
.merge(with: scheduleFetchAccountPortfolioTimer(state))

case .onDisappear:
return .cancel(id: CancellableId.fetchAccountPortfolio)

case .backButtonTapped:
return .send(.delegate(.dismiss))
Expand Down Expand Up @@ -277,4 +289,14 @@ public struct AccountDetails: Sendable, FeatureReducer {
}
}
}

private func scheduleFetchAccountPortfolioTimer(_ state: State) -> Effect<Action> {
.run { [address = state.account.address] _ in
for await _ in clock.timer(interval: .seconds(accountPortfolioRefreshIntervalInSeconds)) {
GhenadieVP marked this conversation as resolved.
Show resolved Hide resolved
guard !Task.isCancelled else { return }
_ = try? await accountPortfoliosClient.fetchAccountPortfolio(address, true)
}
}
.cancellable(id: CancellableId.fetchAccountPortfolio, cancelInFlight: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ extension AccountDetails {
.background(viewStore.appearanceID.gradient)
.navigationBarBackButtonHidden()
.task {
viewStore.send(.task)
await viewStore.send(.task).finish()
}
.onDisappear {
viewStore.send(.onDisappear)
}
.toolbar {
ToolbarItem(placement: .principal) {
Expand Down
Loading
Loading