Skip to content

Commit

Permalink
MOB-1922 - Fixed issue when porfolio values were missing sometimes (#476
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Oleg-Pecheneg authored Apr 4, 2024
1 parent a83778f commit 22b01a4
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,19 @@ extension WalletsDataService: WalletsDataServiceProtocol {
}

func loadAdditionalBalancesFor(domainName: DomainName) async -> [WalletTokenPortfolio] {
let cachedBalances = WalletBalancesStorage.instance.getCachedBalancesFor(domainName: domainName)
do {
let additionalAddresses = try await getAdditionalWalletAddressesToLoadBalanceFor(domainName: domainName)
guard !additionalAddresses.isEmpty else { return [] }

let balances = await loadAdditionalBalancesFor(addresses: additionalAddresses)
let balances = await loadAdditionalBalancesFor(addresses: additionalAddresses,
using: cachedBalances)
WalletBalancesStorage.instance.cacheBalances(balances, for: domainName)

return balances
} catch {
Debugger.printFailure("Failed to load additional tokens for domain: \(domainName)")
return WalletBalancesStorage.instance.getCachedBalancesFor(domainName: domainName)
return cachedBalances
}
}
}
Expand Down Expand Up @@ -524,7 +526,8 @@ private extension WalletsDataService {
return balances
}

func loadAdditionalBalancesFor(addresses: Set<String>) async -> [WalletTokenPortfolio] {
func loadAdditionalBalancesFor(addresses: Set<String>,
using cachedBalances: [WalletTokenPortfolio]) async -> [WalletTokenPortfolio] {
var balances = [WalletTokenPortfolio]()

await withTaskGroup(of: [WalletTokenPortfolio].self) { group in
Expand All @@ -535,7 +538,7 @@ private extension WalletsDataService {
return tokens
} catch {
// Do not fail everything if one of additional tokens failed
return []
return cachedBalances.filter({ $0.address == address })
}
}
}
Expand Down

0 comments on commit 22b01a4

Please sign in to comment.