From ce006ff9b7f5cea90739fd6d34a43ac971962ab7 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 26 Oct 2023 20:16:50 +0800 Subject: [PATCH] Updated on 2026-08-14 --- .../local/quote/DefaultQuotesStore.kt | 4 +++- .../domain/tokens/mock/MockTokenLists.kt | 2 +- .../repository/MockCurrenciesRepository.kt | 7 ++++++ .../viewmodels/TokenDetailsViewModel.kt | 24 +++++++++++-------- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/quote/DefaultQuotesStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/quote/DefaultQuotesStore.kt index 115d68dcbb..2b8de0afd9 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/quote/DefaultQuotesStore.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/quote/DefaultQuotesStore.kt @@ -24,7 +24,9 @@ internal class DefaultQuotesStore( merge(*flows.toTypedArray()) .scan>(emptySet()) { acc, quote -> acc.addOrReplace(quote) { it.rawCurrencyId == quote.rawCurrencyId } - }.collect(::send) + } + .filter(Set::isNotEmpty) + .collect(::send) } } diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt index 0cbc4a5d5c..b831c9595a 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt @@ -42,7 +42,7 @@ internal object MockTokenLists { ) val noQuotesUngroupedTokenList = failedUngroupedTokenList.copy( - totalFiatBalance = TokenList.FiatBalance.Loaded(amount = BigDecimal.ZERO, isAllAmountsSummarized = false), + totalFiatBalance = TokenList.FiatBalance.Failed, currencies = MockTokensStates.noQuotesTokensStatuses, ) diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt index c3ae45ed54..df656f33fb 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt @@ -7,6 +7,7 @@ import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.Network import com.tangem.domain.wallets.models.UserWalletId import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map @@ -78,6 +79,7 @@ internal class MockCurrenciesRepository( override suspend fun getMultiCurrencyWalletCurrency( userWalletId: UserWalletId, id: CryptoCurrency.ID, + contractAddress: String?, derivationPath: Network.DerivationPath, ): CryptoCurrency { val token = token.getOrElse { e -> throw e } @@ -87,6 +89,11 @@ internal class MockCurrenciesRepository( return token } + override fun getMissedAddressesCryptoCurrencies(userWalletId: UserWalletId): Flow> { + /* no-op */ + return emptyFlow() + } + override suspend fun getNetworkCoin( userWalletId: UserWalletId, networkId: Network.ID, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt index 2909ad4fa6..43546d8ba5 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt @@ -292,18 +292,22 @@ internal class TokenDetailsViewModel @Inject constructor( networkId = tokenCurrency.network.id, derivationPath = tokenCurrency.network.derivationPath, isSingleWalletWithTokens = wallet.scanResponse.cardTypesResolver.isSingleWalletWithToken(), - ).firstOrNull() + ) + .conflate() + .distinctUntilChanged() + .firstOrNull() - maybeCoinStatus?.onRight { coinStatus -> - reduxStateHolder.dispatch( - action = TradeCryptoAction.New.SendToken( - userWallet = wallet, - tokenCurrency = tokenCurrency, - tokenFiatRate = tokenFiatRate, - coinFiatRate = coinStatus.value.fiatRate, + reduxStateHolder.dispatch( + action = TradeCryptoAction.New.SendToken( + userWallet = wallet, + tokenCurrency = tokenCurrency, + tokenFiatRate = tokenFiatRate, + coinFiatRate = maybeCoinStatus?.fold( + ifLeft = { null }, + ifRight = { it.value.fiatRate }, ), - ) - } + ), + ) } }