From 1d930e2fa58618b01af5f0f18fb4967105b86b45 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 30 Jun 2025 20:16:54 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .idea/dictionaries/romanpotapov.xml | 9 --- .../repository/DefaultCurrenciesRepository.kt | 70 +++++++++++-------- 2 files changed, 41 insertions(+), 38 deletions(-) delete mode 100644 .idea/dictionaries/romanpotapov.xml diff --git a/.idea/dictionaries/romanpotapov.xml b/.idea/dictionaries/romanpotapov.xml deleted file mode 100644 index 9973a9778a..0000000000 --- a/.idea/dictionaries/romanpotapov.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - blockchain - passcode - tangem - - - \ No newline at end of file diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt index ce4c171722..82139c298f 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt @@ -28,11 +28,7 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.FeePaidCurrency import com.tangem.domain.tokens.repository.CurrenciesRepository import com.tangem.domain.walletmanager.WalletManagersFacade -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.domain.wallets.models.isLocked -import com.tangem.domain.wallets.models.isMultiCurrency -import com.tangem.domain.wallets.models.requireColdWallet +import com.tangem.domain.wallets.models.* import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.* import kotlinx.coroutines.flow.* @@ -502,36 +498,14 @@ internal class DefaultCurrenciesRepository( currencyRawId: CryptoCurrency.RawID, ): Flow>> { return userWalletsStore.userWallets.flatMapLatest { userWallets -> + userWallets.filter { it.isMultiCurrency } .forEach { fetchTokensIfCacheExpired(userWallet = it, refresh = false) } val userWalletsWithCurrencies = userWallets .filterNot(UserWallet::isLocked) .map { userWallet -> - if (userWallet.isMultiCurrency) { - getSavedUserTokensResponse(userWallet.walletId).map { storedTokens -> - val filterResponse = storedTokens.tokens.filter { - getL2CompatibilityTokenComparison(it, currencyRawId.value) - } - - responseCurrenciesFactory.createCurrencies( - response = storedTokens.copy(tokens = filterResponse), - scanResponse = userWallet.requireColdWallet().scanResponse, - ) - } - } else { - flow { - val currency = getSingleCurrencyWalletPrimaryCurrency(userWalletId = userWallet.walletId) - - val currencies = if (currency.id.rawCurrencyId == currencyRawId) { - listOf(currency) - } else { - emptyList() - } - - emit(currencies) - } - }.map { userWallet to it } + getCurrenciesForWallet(userWallet, currencyRawId).map { userWallet to it } } combine(userWalletsWithCurrencies) { it.toMap() } @@ -539,6 +513,44 @@ internal class DefaultCurrenciesRepository( } } + private suspend fun getCurrenciesForWallet( + userWallet: UserWallet, + currencyRawId: CryptoCurrency.RawID, + ): Flow> { + userWallet.requireColdWallet() // TODO [REDACTED_TASK_KEY] + return when { + userWallet.isMultiCurrency -> { + getSavedUserTokensResponse(userWallet.walletId).map { storedTokens -> + val filterResponse = storedTokens.tokens.filter { + getL2CompatibilityTokenComparison(it, currencyRawId.value) + } + + responseCurrenciesFactory.createCurrencies( + response = storedTokens.copy(tokens = filterResponse), + scanResponse = userWallet.requireColdWallet().scanResponse, + ) + } + } + else -> { + val currencies = if (userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()) { + getSingleCurrencyWalletWithCardCurrencies(userWallet.walletId) + } else { + val currency = + getSingleCurrencyWalletPrimaryCurrency(userWalletId = userWallet.walletId) + + if (currency.id.rawCurrencyId == currencyRawId) { + listOf(currency) + } else { + emptyList() + } + } + flow { + emit(currencies) + } + } + } + } + override fun isNetworkFeeZero(userWalletId: UserWalletId, network: Network): Boolean { val blockchain = Blockchain.fromNetworkId(network.backendId) return blockchain?.isNetworkFeeZero() ?: false