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-3630] Fix NFTs collection background refresh #1230

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions RadixWallet/Features/AssetsFeature/AssetsView+Reducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ public struct AssetsView: Sendable, FeatureReducer {
state.isLoadingResources = false
state.isRefreshing = false
portfolio.account = portfolio.account.nonEmptyVaults
updateFromPortfolio(state: &state, from: portfolio)
return .none
let nftRowsToRefresh = updateFromPortfolio(state: &state, from: portfolio)

return !nftRowsToRefresh.isEmpty ? .send(.child(.nonFungibleTokenList(.internal(.refreshRows(nftRowsToRefresh))))) : .none
}
}

Expand Down
13 changes: 12 additions & 1 deletion RadixWallet/Features/AssetsFeature/AssetsView+Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import ComposableArchitecture
import SwiftUI

extension AssetsView {
typealias NFTRowsToRefresh = [ResourceAddress]

func updateFromPortfolio(
state: inout State,
from portfolio: AccountPortfoliosClient.AccountPortfolio
) {
) -> NFTRowsToRefresh {
let mode = state.mode
let xrd = portfolio.account.fungibleResources.xrdResource.map { token in
let updatedRow = state.resources.fungibleTokenList?.updatedRow(token: token, for: .xrd)
Expand Down Expand Up @@ -35,6 +37,13 @@ extension AssetsView {
selectedAssets: mode.nftRowSelectedAssets(resource.resourceAddress)
)
}
let nftRowsToRefresh: [ResourceAddress] = portfolio.account.nonFungibleResources.compactMap { resource in
state.resources.nonFungibleTokenList?.rows.first {
$0.id == resource.resourceAddress &&
$0.resource.nonFungibleIdsCount != resource.nonFungibleIdsCount &&
$0.isExpanded
}?.id
}

let fungibleTokenList: FungibleAssetList.State? = {
var sections: IdentifiedArrayOf<FungibleAssetList.Section.State> = []
Expand Down Expand Up @@ -116,6 +125,8 @@ extension AssetsView {
stakeUnitList: stakeUnitList,
poolUnitsList: poolUnitList
)

return nftRowsToRefresh
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extension NonFungibleAssetList {
}

case tokensLoaded(TaskResult<TokensLoadResult>)
case refreshResources
}

@Dependency(\.onLedgerEntitiesClient) var onLedgerEntitiesClient
Expand Down Expand Up @@ -131,6 +132,9 @@ extension NonFungibleAssetList {
state.isLoadingResources = false
}
return .none

case .refreshResources:
return loadResources(&state, pageIndex: 0)
GhenadieVP marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public struct NonFungibleAssetList: Sendable, FeatureReducer {
case asset(NonFungibleAssetList.Row.State.ID, NonFungibleAssetList.Row.Action)
}

public enum InternalAction: Sendable, Equatable {
case refreshRows([ResourceAddress])
}

public enum DelegateAction: Sendable, Equatable {
case selected(OnLedgerEntity.OwnedNonFungibleResource, token: OnLedgerEntity.NonFungibleToken)
}
Expand All @@ -36,4 +40,11 @@ public struct NonFungibleAssetList: Sendable, FeatureReducer {
return .none
}
}

public func reduce(into state: inout State, internalAction: InternalAction) -> Effect<Action> {
switch internalAction {
case let .refreshRows(rows):
.merge(rows.map { .send(.child(.asset($0, .internal(.refreshResources)))) })
}
}
}
Loading