From 104d60aebd8df546bec567267c924117934d8962 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 28 Feb 2025 17:30:29 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../tokens/repository/DefaultQuotesRepository.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultQuotesRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultQuotesRepository.kt index 1a40fa78b5..4957144d0d 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultQuotesRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultQuotesRepository.kt @@ -46,7 +46,7 @@ internal class DefaultQuotesRepository( fetchExpiredQuotes( currenciesIds = currenciesIds, appCurrencyId = appCurrency.id, - refresh = true, + refresh = false, ) quotesStore.get(currenciesIds) @@ -120,6 +120,7 @@ internal class DefaultQuotesRepository( val expiredCurrenciesIds = filterExpiredCurrenciesIds( currenciesIds = currenciesIds, + appCurrencyId = appCurrencyId, refresh = refresh || quotesFetchedForAppCurrency != appCurrencyId, ) if (expiredCurrenciesIds.isEmpty()) return @@ -150,7 +151,7 @@ internal class DefaultQuotesRepository( onError = { error -> Timber.e(error) - cacheRegistry.invalidate(rawCurrenciesIds.map { getQuoteCacheKey(it) }) + cacheRegistry.invalidate(rawCurrenciesIds.map { getQuoteCacheKey(it, appCurrencyId) }) quotesStore.storeEmptyQuotes(currenciesIds = rawCurrenciesIds) }, ) @@ -158,12 +159,13 @@ internal class DefaultQuotesRepository( private suspend fun filterExpiredCurrenciesIds( currenciesIds: Set, + appCurrencyId: String, refresh: Boolean, ): Set { return currenciesIds.fold(hashSetOf()) { acc, currencyId -> if (currencyId !in acc) { cacheRegistry.invokeOnExpire( - key = getQuoteCacheKey(currencyId), + key = getQuoteCacheKey(currencyId, appCurrencyId), skipCache = refresh, block = { acc.add(currencyId) }, ) @@ -172,5 +174,7 @@ internal class DefaultQuotesRepository( } } - private fun getQuoteCacheKey(rawCurrencyId: CryptoCurrency.RawID): String = "quote_${rawCurrencyId.value}" + private fun getQuoteCacheKey(rawCurrencyId: CryptoCurrency.RawID, appCurrencyId: String): String { + return "quote_${rawCurrencyId.value}_$appCurrencyId" + } } \ No newline at end of file