Updated on 2026-08-14

This commit is contained in:
Tangem 2024-07-15 23:11:52 +04:00
parent d7f661a854
commit ac87667f88
2 changed files with 44 additions and 37 deletions

View file

@ -442,21 +442,23 @@ internal class DefaultCurrenciesRepository(
}
private suspend fun fetchTokensIfCacheExpired(userWallet: UserWallet, refresh: Boolean) {
try {
isMultiCurrencyWalletCurrenciesFetching.update {
it + (userWallet.walletId to true)
}
cacheRegistry.invokeOnExpire(
key = getTokensCacheKey(userWallet.walletId),
skipCache = refresh,
block = {
isMultiCurrencyWalletCurrenciesFetching.update {
it + (userWallet.walletId to true)
}
cacheRegistry.invokeOnExpire(
key = getTokensCacheKey(userWallet.walletId),
skipCache = refresh,
block = { fetchTokens(userWallet) },
)
} finally {
isMultiCurrencyWalletCurrenciesFetching.update {
it - userWallet.walletId
}
}
try {
fetchTokens(userWallet)
} finally {
isMultiCurrencyWalletCurrenciesFetching.update {
it - userWallet.walletId
}
}
},
)
}
private suspend fun fetchTokens(userWallet: UserWallet) {

View file

@ -183,24 +183,22 @@ internal class DefaultNetworksRepository(
networks: Set<Network>,
refresh: Boolean,
) {
try {
isNetworkStatusesFetching.update {
it + (userWalletId to true)
}
val currencies = getCurrencies(userWalletId, networks)
val networksDeferred = networks.mapNotNull { network ->
fetchNetworkStatusIfCacheExpired(userWalletId, network, currencies, refresh)
}
val currencies = getCurrencies(userWalletId, networks)
coroutineScope {
networks
.map { network ->
async {
fetchNetworkStatusIfCacheExpired(userWalletId, network, currencies, refresh)
}
}
.awaitAll()
}
} finally {
isNetworkStatusesFetching.update {
it - userWalletId
if (networksDeferred.isNotEmpty()) {
try {
isNetworkStatusesFetching.update {
it + (userWalletId to true)
}
networksDeferred.awaitAll()
} finally {
isNetworkStatusesFetching.update {
it - userWalletId
}
}
}
}
@ -226,12 +224,19 @@ internal class DefaultNetworksRepository(
network: Network,
currencies: Sequence<CryptoCurrency>,
refresh: Boolean,
) {
cacheRegistry.invokeOnExpire(
key = getNetworksStatusesCacheKey(userWalletId, network),
skipCache = refresh,
block = { fetchNetworkStatus(userWalletId, network, currencies) },
)
): Deferred<Unit>? = coroutineScope {
val key = getNetworksStatusesCacheKey(userWalletId, network)
if (refresh || cacheRegistry.isExpired(key)) {
async {
cacheRegistry.invokeOnExpire(
key = key,
skipCache = refresh,
block = { fetchNetworkStatus(userWalletId, network, currencies) },
)
}
} else {
null
}
}
private suspend fun fetchNetworkStatus(