Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-11 17:48:20 +05:00
parent 6ed1946ac3
commit aac48015b3
88 changed files with 335 additions and 239 deletions

View file

@ -2,7 +2,7 @@ package com.tangem.feature.wallet.presentation.organizetokens.utils
import com.tangem.domain.account.models.AccountStatusList
import com.tangem.domain.account.status.model.AccountCryptoCurrencies
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.account.filterCryptoPortfolio
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.tokenlist.TokenList
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
@ -34,6 +34,7 @@ internal class CryptoCurrenciesIdsResolver {
}
}
@Suppress("UseOrEmpty")
fun resolveV2(tokensListUM: OrganizeTokensListUM, accountStatusList: AccountStatusList?): AccountCryptoCurrencies {
val draggableTokens = when (tokensListUM) {
OrganizeTokensListUM.EmptyList -> return emptyMap()
@ -43,10 +44,11 @@ internal class CryptoCurrenciesIdsResolver {
}
return accountStatusList?.accountStatuses
?.filter { it.getCryptoTokenList() != TokenList.Empty }
?.filterCryptoPortfolio()
?.filter { it.tokenList != TokenList.Empty }
?.associate { accountStatus ->
val currencies = accountStatus.flattenCurrencies()
accountStatus.account as Account.CryptoPortfolio to draggableTokens
accountStatus.account to draggableTokens
.asSequence()
.filter { it.accountId == accountStatus.account.accountId.value }
.mapNotNull { sortedToken ->

View file

@ -6,7 +6,7 @@ import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.models.TokensGroupType
import com.tangem.domain.models.TokensSortType
import com.tangem.domain.models.TotalFiatBalance
import com.tangem.domain.models.account.AccountStatus
import com.tangem.domain.models.account.filterCryptoPortfolio
import com.tangem.domain.models.tokenlist.TokenList
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListUM
@ -61,7 +61,7 @@ internal class AccountTokenItemConverter(
isGrouped = isGrouping,
items = value.accountStatuses
.asSequence()
.filterIsInstance<AccountStatus.CryptoPortfolio>()
.filterCryptoPortfolio()
.flatMap { accountStatus ->
if (accountStatus.tokenList != TokenList.Empty) {
buildList {

View file

@ -2,7 +2,6 @@ package com.tangem.feature.wallet.presentation.organizetokens.utils.converter.it
import com.tangem.domain.account.status.model.AccountCryptoCurrencyStatus
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.account.AccountStatus
import com.tangem.domain.models.tokenlist.TokenList
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
@ -13,27 +12,26 @@ import kotlinx.collections.immutable.toPersistentList
internal class OrganizedTokenListConverter(
private val appCurrency: AppCurrency,
) : Converter<AccountStatus, PersistentList<DraggableItem>> {
) : Converter<AccountStatus.CryptoPortfolio, PersistentList<DraggableItem>> {
private val tokensConverter by lazy { CryptoCurrencyToDraggableItemConverterV2(appCurrency) }
private val groupsConverter by lazy {
NetworkGroupToDraggableItemsConverterV2(tokensConverter)
}
override fun convert(value: AccountStatus): PersistentList<DraggableItem> {
val cryptoAccount = value.account as? Account.CryptoPortfolio ?: return persistentListOf()
return when (val tokenList = value.getCryptoTokenList()) {
override fun convert(value: AccountStatus.CryptoPortfolio): PersistentList<DraggableItem> {
return when (val tokenList = value.tokenList) {
is TokenList.GroupedByNetwork -> groupsConverter.convertList(
tokenList.groups.map { cryptoAccount to it },
tokenList.groups.map { value.account to it },
)
.flatten()
.toPersistentList()
is TokenList.Ungrouped -> tokensConverter.convertList(
value.flattenCurrencies().map {
value.flattenCurrencies().map { cryptoCurrencyStatus ->
AccountCryptoCurrencyStatus(
account = cryptoAccount,
status = it,
account = value.account,
status = cryptoCurrencyStatus,
)
},
).toPersistentList()

View file

@ -241,10 +241,11 @@ internal class GetSingleWalletWarningsFactory @Inject constructor(
}
}
private fun getAccountStatusFlow(userWallet: UserWallet): Flow<AccountStatus> {
private fun getAccountStatusFlow(userWallet: UserWallet): Flow<AccountStatus.CryptoPortfolio> {
val accountId = AccountId.forMainCryptoPortfolio(userWalletId = userWallet.walletId)
return singleAccountStatusSupplier(SingleAccountStatusProducer.Params(accountId))
.filterIsInstance<AccountStatus.CryptoPortfolio>()
.distinctUntilChanged()
.conflate()
}

View file

@ -14,6 +14,7 @@ import com.tangem.domain.models.TotalFiatBalance
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.account.AccountStatus
import com.tangem.domain.models.account.filterCryptoPortfolio
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.tokenlist.TokenList
@ -144,6 +145,7 @@ internal class TokenListStateConverter(
}
val accountItems = accountList.accountStatuses
.filterCryptoPortfolio()
.map { accountStatus ->
when (accountStatus) {
is AccountStatus.CryptoPortfolio -> accountStatus.map()

View file

@ -4,6 +4,7 @@ import com.tangem.domain.account.models.AccountStatusList
import com.tangem.domain.account.status.producer.SingleAccountStatusListProducer
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.models.account.AccountStatus
import com.tangem.domain.models.account.filterCryptoPortfolio
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet
import kotlinx.coroutines.flow.Flow
@ -45,11 +46,9 @@ internal abstract class BasicWalletSubscriber : WalletSubscriber() {
protected fun getMainAccountStatusFlow(): Flow<AccountStatus.CryptoPortfolio> {
return getAccountStatusListFlow()
.mapNotNull { accountStatusList ->
accountStatusList.accountStatuses.find { accountStatus ->
when (accountStatus) {
is AccountStatus.CryptoPortfolio -> accountStatus.account.isMainAccount
}
} as? AccountStatus.CryptoPortfolio
accountStatusList.accountStatuses
.filterCryptoPortfolio()
.find { accountStatus -> accountStatus.account.isMainAccount }
}
.distinctUntilChanged()
.conflate()