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

MOB-1922 - Fixed issue when porfolio values were missing sometimes #476

Merged
merged 1 commit into from
Apr 4, 2024
Merged
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
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