Updated on 2026-08-14

This commit is contained in:
Tangem 2025-06-30 20:16:54 +03:00
parent 218f6f83b7
commit 1d930e2fa5
2 changed files with 41 additions and 38 deletions

View file

@ -1,9 +0,0 @@
<component name="ProjectDictionaryState">
<dictionary name="romanpotapov">
<words>
<w>blockchain</w>
<w>passcode</w>
<w>tangem</w>
</words>
</dictionary>
</component>

View file

@ -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,13 +498,28 @@ internal class DefaultCurrenciesRepository(
currencyRawId: CryptoCurrency.RawID,
): Flow<Map<UserWallet, List<CryptoCurrency>>> {
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) {
getCurrenciesForWallet(userWallet, currencyRawId).map { userWallet to it }
}
combine(userWalletsWithCurrencies) { it.toMap() }
.onEmpty { emit(value = emptyMap()) }
}
}
private suspend fun getCurrenciesForWallet(
userWallet: UserWallet,
currencyRawId: CryptoCurrency.RawID,
): Flow<List<CryptoCurrency>> {
userWallet.requireColdWallet() // TODO [REDACTED_TASK_KEY]
return when {
userWallet.isMultiCurrency -> {
getSavedUserTokensResponse(userWallet.walletId).map { storedTokens ->
val filterResponse = storedTokens.tokens.filter {
getL2CompatibilityTokenComparison(it, currencyRawId.value)
@ -519,23 +530,24 @@ internal class DefaultCurrenciesRepository(
scanResponse = userWallet.requireColdWallet().scanResponse,
)
}
}
else -> {
val currencies = if (userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()) {
getSingleCurrencyWalletWithCardCurrencies(userWallet.walletId)
} else {
flow {
val currency = getSingleCurrencyWalletPrimaryCurrency(userWalletId = userWallet.walletId)
val currency =
getSingleCurrencyWalletPrimaryCurrency(userWalletId = userWallet.walletId)
val currencies = if (currency.id.rawCurrencyId == currencyRawId) {
if (currency.id.rawCurrencyId == currencyRawId) {
listOf(currency)
} else {
emptyList()
}
}
flow {
emit(currencies)
}
}.map { userWallet to it }
}
combine(userWalletsWithCurrencies) { it.toMap() }
.onEmpty { emit(value = emptyMap()) }
}
}