Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuo-xu committed Nov 27, 2023
1 parent a0a72dd commit 26bf728
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Sources/BraveWallet/Crypto/Stores/NFTStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ public class NFTStore: ObservableObject, WalletObserverStore {
private var metadataCache: [String: NFTMetadata] = [:]
/// Spam from SimpleHash in form of `NetworkAssets`
private var simpleHashSpamNFTs: [NetworkAssets] = []
/// All User NFTs that includes visible, hidden, spam
private var allUserNFTs: [BraveWallet.BlockchainToken] = []

var isObserving: Bool {
rpcServiceObserver != nil && keyringServiceObserver != nil && walletServiveObserber != nil
Expand Down Expand Up @@ -271,12 +269,13 @@ public class NFTStore: ObservableObject, WalletObserverStore {
simpleHashSpamNFTs: simpleHashSpamNFTs
)

(userNFTGroups, allUserNFTs) = buildNFTGroupModels(
let (userNFTGroups, allUserNFTs) = buildNFTGroupModels(
groupBy: filters.groupBy,
spams: unionedSpamNFTs,
selectedAccounts: selectedAccounts,
selectedNetworks: selectedNetworks
)
self.userNFTGroups = userNFTGroups

// if we're not hiding unowned or grouping by account, balance isn't needed
if filters.isHidingUnownedNFTs || filters.groupBy == .accounts {
Expand Down Expand Up @@ -318,25 +317,27 @@ public class NFTStore: ObservableObject, WalletObserverStore {
}

guard !Task.isCancelled else { return }
(userNFTGroups, allUserNFTs) = buildNFTGroupModels(
let (userNFTGroupsWithBalance, _) = buildNFTGroupModels(
groupBy: filters.groupBy,
spams: unionedSpamNFTs,
selectedAccounts: selectedAccounts,
selectedNetworks: selectedNetworks
)
self.userNFTGroups = userNFTGroupsWithBalance

// fetch nft metadata for all NFTs
let allMetadata = await rpcService.fetchNFTMetadata(tokens: allUserNFTs, ipfsApi: ipfsApi)
for (key, value) in allMetadata { // update cached values
metadataCache[key] = value
}
guard !Task.isCancelled else { return }
(userNFTGroups, allUserNFTs) = buildNFTGroupModels(
let (userNFTGroupsWithMetadata, _) = buildNFTGroupModels(
groupBy: filters.groupBy,
spams: unionedSpamNFTs,
selectedAccounts: selectedAccounts,
selectedNetworks: selectedNetworks
)
self.userNFTGroups = userNFTGroupsWithMetadata

isShowingNFTLoadingState = false
}
Expand Down Expand Up @@ -525,10 +526,7 @@ public class NFTStore: ObservableObject, WalletObserverStore {
computedSpamNFTs: spams
)

var allUserNFTs: [BraveWallet.BlockchainToken] = []
for networkAssets in [userVisibleNFTs, userHiddenNFTs, spams] {
allUserNFTs.append(contentsOf: networkAssets.flatMap(\.tokens))
}
let allUserNFTs = (userVisibleNFTs + userHiddenNFTs + spams).flatMap(\.tokens)

let groups: [NFTGroupViewModel]
switch filters.groupBy {
Expand Down

0 comments on commit 26bf728

Please sign in to comment.