Updated on 2026-08-14
This commit is contained in:
parent
218f6f83b7
commit
1d930e2fa5
2 changed files with 41 additions and 38 deletions
9
.idea/dictionaries/romanpotapov.xml
generated
9
.idea/dictionaries/romanpotapov.xml
generated
|
|
@ -1,9 +0,0 @@
|
|||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="romanpotapov">
|
||||
<words>
|
||||
<w>blockchain</w>
|
||||
<w>passcode</w>
|
||||
<w>tangem</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
|
|
@ -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<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) {
|
||||
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<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)
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue