From 51ce614b7b77691ecad62e146dd1a09128c6279d Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 16 Jul 2024 16:49:16 +0100 Subject: [PATCH] Updated on 2026-08-14 --- .../data/tokens/paging/CoinsPagingSource.kt | 26 +++++++++++-------- .../feature/swap/domain/SwapInteractorImpl.kt | 10 ++++++- .../viewmodels/ExchangeStatusFactory.kt | 11 +++++++- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/paging/CoinsPagingSource.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/paging/CoinsPagingSource.kt index e5c4c36e1a..9cf7b0092c 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/paging/CoinsPagingSource.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/paging/CoinsPagingSource.kt @@ -52,19 +52,23 @@ internal class CoinsPagingSource( suffix = CryptoCurrency.ID.Suffix.RawID(coin.id), ) } - val quotes = quotesRepository.getQuotesSync(currenciesIds = coinsIds.toSet(), refresh = false) - LoadResult.Page( - data = CoinsResponseConverter.convert( - CoinsData( - response.coins, - response.imageHost, - quotes, + try { + val quotes = quotesRepository.getQuotesSync(currenciesIds = coinsIds.toSet(), refresh = false) + LoadResult.Page( + data = CoinsResponseConverter.convert( + CoinsData( + response.coins, + response.imageHost, + quotes, + ), ), - ), - prevKey = if (page == 0) null else page.minus(other = 1), - nextKey = if (response.coins.isEmpty()) null else page.plus(other = 1), - ) + prevKey = if (page == 0) null else page.minus(other = 1), + nextKey = if (response.coins.isEmpty()) null else page.plus(other = 1), + ) + } catch (t: Throwable) { + LoadResult.Error(t) + } }, onFailure = { LoadResult.Error(it) }, ) diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt index df53e5e0e7..99a1b3e2b9 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt @@ -1814,13 +1814,21 @@ internal class SwapInteractorImpl @Inject constructor( } private suspend fun getQuotes(vararg ids: CryptoCurrency.ID): Map { - val set = quotesRepository.getQuotesSync(ids.toSet(), false) + val set = ids.toSet().getQuotesOrEmpty(false) return ids .mapNotNull { id -> set.find { it.rawCurrencyId == id.rawCurrencyId }?.let { id to it } } .toMap() } + private suspend fun Set.getQuotesOrEmpty(refresh: Boolean): Set { + return try { + quotesRepository.getQuotesSync(this, refresh) + } catch (t: Throwable) { + emptySet() + } + } + private fun getDemoFees(cryptoCurrency: CryptoCurrency): ProxyFees.MultipleFees { val demoFee = ProxyAmount( currencySymbol = cryptoCurrency.symbol, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt index e77952c869..fb15bd476d 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt @@ -70,7 +70,8 @@ internal class ExchangeStatusFactory( .map { savedTransactions -> val quotes = savedTransactions ?.flatMap { setOf(it.fromCryptoCurrency.id, it.toCryptoCurrency.id) } - ?.let { quotesRepository.getQuotesSync(it.toSet(), true) } + ?.toSet() + ?.getQuotesOrEmpty(true) ?: emptySet() getExchangeStatusState( @@ -176,4 +177,12 @@ internal class ExchangeStatusFactory( else -> null } } + + private suspend fun Set.getQuotesOrEmpty(refresh: Boolean): Set { + return try { + quotesRepository.getQuotesSync(this, refresh) + } catch (t: Throwable) { + emptySet() + } + } } \ No newline at end of file