From 7527a7d5b2998a7af41d06de52b4b4cfdf8e8f56 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 4 Apr 2024 11:47:24 +0700 Subject: [PATCH] MOB-1922 - Fixed issue when porfolio values were missing sometimes --- .../WalletsDataService/WalletsDataService.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/unstoppable-ios-app/domains-manager-ios/Services/WalletsDataService/WalletsDataService.swift b/unstoppable-ios-app/domains-manager-ios/Services/WalletsDataService/WalletsDataService.swift index 7d6368097..6a3e8b589 100644 --- a/unstoppable-ios-app/domains-manager-ios/Services/WalletsDataService/WalletsDataService.swift +++ b/unstoppable-ios-app/domains-manager-ios/Services/WalletsDataService/WalletsDataService.swift @@ -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 } } } @@ -524,7 +526,8 @@ private extension WalletsDataService { return balances } - func loadAdditionalBalancesFor(addresses: Set) async -> [WalletTokenPortfolio] { + func loadAdditionalBalancesFor(addresses: Set, + using cachedBalances: [WalletTokenPortfolio]) async -> [WalletTokenPortfolio] { var balances = [WalletTokenPortfolio]() await withTaskGroup(of: [WalletTokenPortfolio].self) { group in @@ -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 }) } } }