Updated on 2026-08-14
This commit is contained in:
parent
c813e330c2
commit
b196684377
11 changed files with 70 additions and 29 deletions
|
|
@ -0,0 +1,19 @@
|
|||
package com.tangem.domain.models
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Represents the type of a group of tokens
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
@Serializable
|
||||
enum class TokensGroupType {
|
||||
|
||||
/** No grouping applied */
|
||||
NONE,
|
||||
|
||||
/** Grouping by network */
|
||||
NETWORK,
|
||||
;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.tangem.domain.models
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Represents the sorting type for tokens
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
@Serializable
|
||||
enum class TokensSortType {
|
||||
|
||||
/** No sorting applied */
|
||||
NONE,
|
||||
|
||||
/** Sorted by their balance */
|
||||
BALANCE,
|
||||
;
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import arrow.core.raise.Raise
|
|||
import arrow.core.raise.either
|
||||
import arrow.core.raise.ensure
|
||||
import arrow.core.raise.withError
|
||||
import com.tangem.domain.models.TokensSortType
|
||||
import com.tangem.domain.tokens.error.TokenListSortingError
|
||||
import com.tangem.domain.tokens.error.mapper.mapToTokenListSortingError
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
|
|
@ -66,7 +67,7 @@ class ToggleTokenListSortingUseCase(
|
|||
private fun getSortingOperations(tokenList: TokenList): TokenListSortingOperations {
|
||||
return TokenListSortingOperations(
|
||||
tokenList = tokenList,
|
||||
sortByBalance = tokenList.sortedBy != TokenList.SortType.BALANCE,
|
||||
sortByBalance = tokenList.sortedBy != TokensSortType.BALANCE,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.domain.tokens.model
|
||||
|
||||
import com.tangem.domain.models.StatusSource
|
||||
import com.tangem.domain.models.TokensSortType
|
||||
import java.math.BigDecimal
|
||||
|
||||
/**
|
||||
|
|
@ -14,7 +15,7 @@ import java.math.BigDecimal
|
|||
*/
|
||||
sealed class TokenList {
|
||||
open val totalFiatBalance: TotalFiatBalance = TotalFiatBalance.Loading
|
||||
open val sortedBy: SortType = SortType.NONE
|
||||
open val sortedBy: TokensSortType = TokensSortType.NONE
|
||||
|
||||
/**
|
||||
* Represents tokens that are grouped by their network.
|
||||
|
|
@ -26,7 +27,7 @@ sealed class TokenList {
|
|||
data class GroupedByNetwork(
|
||||
val groups: List<NetworkGroup>,
|
||||
override val totalFiatBalance: TotalFiatBalance,
|
||||
override val sortedBy: SortType,
|
||||
override val sortedBy: TokensSortType,
|
||||
) : TokenList()
|
||||
|
||||
/**
|
||||
|
|
@ -39,7 +40,7 @@ sealed class TokenList {
|
|||
data class Ungrouped(
|
||||
val currencies: List<CryptoCurrencyStatus>,
|
||||
override val totalFiatBalance: TotalFiatBalance,
|
||||
override val sortedBy: SortType,
|
||||
override val sortedBy: TokensSortType,
|
||||
) : TokenList()
|
||||
|
||||
/** Represents a state where the token list is empty. */
|
||||
|
|
@ -52,11 +53,6 @@ sealed class TokenList {
|
|||
)
|
||||
}
|
||||
|
||||
/** Defines the possible sorting criteria for the tokens. */
|
||||
enum class SortType {
|
||||
NONE, BALANCE,
|
||||
}
|
||||
|
||||
/** Get flatten list of cryptocurrency status [CryptoCurrencyStatus] */
|
||||
fun flattenCurrencies(): List<CryptoCurrencyStatus> {
|
||||
return when (this) {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ import arrow.core.*
|
|||
import arrow.core.raise.Raise
|
||||
import arrow.core.raise.either
|
||||
import arrow.core.raise.withError
|
||||
import com.tangem.domain.models.TokensSortType
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.domain.tokens.model.TotalFiatBalance
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
|
|
@ -105,7 +106,7 @@ internal class TokenListOperations(
|
|||
fiatBalance: TotalFiatBalance,
|
||||
): TokenList.Ungrouped {
|
||||
return TokenList.Ungrouped(
|
||||
sortedBy = TokenList.SortType.NONE,
|
||||
sortedBy = TokensSortType.NONE,
|
||||
totalFiatBalance = fiatBalance,
|
||||
currencies = tokens,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import arrow.core.raise.either
|
|||
import arrow.core.raise.ensure
|
||||
import arrow.core.raise.ensureNotNull
|
||||
import arrow.core.toNonEmptyListOrNull
|
||||
import com.tangem.domain.models.TokensSortType
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.staking.model.stakekit.YieldBalance
|
||||
import com.tangem.domain.staking.utils.getTotalWithRewardsStakingBalance
|
||||
|
|
@ -25,7 +26,7 @@ internal class TokenListSortingOperations(
|
|||
|
||||
constructor(
|
||||
tokenList: TokenList,
|
||||
sortByBalance: Boolean = tokenList.sortedBy == TokenList.SortType.BALANCE,
|
||||
sortByBalance: Boolean = tokenList.sortedBy == TokensSortType.BALANCE,
|
||||
isAnyTokenLoading: Boolean = tokenList.totalFiatBalance is TotalFiatBalance.Loading,
|
||||
) : this(
|
||||
currencies = tokenList.flattenCurrencies(),
|
||||
|
|
@ -51,7 +52,7 @@ internal class TokenListSortingOperations(
|
|||
if (sortByBalance) sortTokensByBalance(nonEmptyCurrencies) else nonEmptyCurrencies
|
||||
}
|
||||
|
||||
fun getSortType(): TokenList.SortType = if (sortByBalance) TokenList.SortType.BALANCE else TokenList.SortType.NONE
|
||||
fun getSortType(): TokensSortType = if (sortByBalance) TokensSortType.BALANCE else TokensSortType.NONE
|
||||
|
||||
private fun Raise<Error>.groupTokens(): NonEmptyList<NetworkGroup> {
|
||||
val groupedTokens = currencies
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.tangem.domain.tokens.mock
|
|||
import arrow.core.NonEmptyList
|
||||
import arrow.core.toNonEmptyListOrNull
|
||||
import com.tangem.domain.models.StatusSource
|
||||
import com.tangem.domain.models.TokensSortType
|
||||
import com.tangem.domain.tokens.mock.MockNetworksGroups.failedNetworksGroups
|
||||
import com.tangem.domain.tokens.mock.MockNetworksGroups.loadedNetworksGroups
|
||||
import com.tangem.domain.tokens.mock.MockNetworksGroups.sortedNetworksGroups
|
||||
|
|
@ -22,25 +23,25 @@ internal object MockTokenLists {
|
|||
val emptyGroupedTokenList = TokenList.GroupedByNetwork(
|
||||
groups = emptyList(),
|
||||
totalFiatBalance = TotalFiatBalance.Failed,
|
||||
sortedBy = TokenList.SortType.NONE,
|
||||
sortedBy = TokensSortType.NONE,
|
||||
)
|
||||
|
||||
val emptyUngroupedTokenList = TokenList.Ungrouped(
|
||||
currencies = emptyList(),
|
||||
totalFiatBalance = TotalFiatBalance.Failed,
|
||||
sortedBy = TokenList.SortType.NONE,
|
||||
sortedBy = TokensSortType.NONE,
|
||||
)
|
||||
|
||||
val failedGroupedTokenList = TokenList.GroupedByNetwork(
|
||||
groups = failedNetworksGroups,
|
||||
totalFiatBalance = TotalFiatBalance.Failed,
|
||||
sortedBy = TokenList.SortType.NONE,
|
||||
sortedBy = TokensSortType.NONE,
|
||||
)
|
||||
|
||||
val failedUngroupedTokenList = TokenList.Ungrouped(
|
||||
currencies = MockTokensStates.failedTokenStates,
|
||||
totalFiatBalance = TotalFiatBalance.Failed,
|
||||
sortedBy = TokenList.SortType.NONE,
|
||||
sortedBy = TokensSortType.NONE,
|
||||
)
|
||||
|
||||
val noQuotesUngroupedTokenList = failedUngroupedTokenList.copy(
|
||||
|
|
@ -76,7 +77,7 @@ internal object MockTokenLists {
|
|||
|
||||
return failedUngroupedTokenList.copy(
|
||||
currencies = tokens,
|
||||
sortedBy = TokenList.SortType.NONE,
|
||||
sortedBy = TokensSortType.NONE,
|
||||
totalFiatBalance = TotalFiatBalance.Loaded(
|
||||
amount = tokens.sumOf { it.value.fiatAmount ?: BigDecimal.ZERO },
|
||||
isAllAmountsSummarized = true,
|
||||
|
|
@ -91,7 +92,7 @@ internal object MockTokenLists {
|
|||
|
||||
return failedGroupedTokenList.copy(
|
||||
groups = groups,
|
||||
sortedBy = TokenList.SortType.NONE,
|
||||
sortedBy = TokensSortType.NONE,
|
||||
totalFiatBalance = TotalFiatBalance.Loaded(
|
||||
amount = groups
|
||||
.flatMap { it.currencies as NonEmptyList<CryptoCurrencyStatus> }
|
||||
|
|
@ -109,7 +110,7 @@ internal object MockTokenLists {
|
|||
|
||||
return unsortedUngroupedTokenList.copy(
|
||||
currencies = tokens,
|
||||
sortedBy = TokenList.SortType.BALANCE,
|
||||
sortedBy = TokensSortType.BALANCE,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +120,7 @@ internal object MockTokenLists {
|
|||
|
||||
return unsortedGroupedTokenList.copy(
|
||||
groups = groups,
|
||||
sortedBy = TokenList.SortType.BALANCE,
|
||||
sortedBy = TokensSortType.BALANCE,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
|
|||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase
|
||||
import com.tangem.domain.core.lce.Lce
|
||||
import com.tangem.domain.models.TokensSortType
|
||||
import com.tangem.domain.tokens.ApplyTokenListSortingUseCase
|
||||
import com.tangem.domain.tokens.GetTokenListUseCase
|
||||
import com.tangem.domain.tokens.ToggleTokenListGroupingUseCase
|
||||
|
|
@ -89,7 +90,7 @@ internal class OrganizeTokensModel @Inject constructor(
|
|||
|
||||
override fun onSortClick() {
|
||||
val list = cachedTokenList ?: return
|
||||
if (list.sortedBy == TokenList.SortType.BALANCE) return
|
||||
if (list.sortedBy == TokensSortType.BALANCE) return
|
||||
|
||||
analyticsEventsHandler.send(PortfolioOrganizeTokensAnalyticsEvent.ByBalance)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens.utils.common
|
||||
|
||||
import com.tangem.domain.models.TokensSortType
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.domain.tokens.model.TokenList.SortType
|
||||
|
||||
internal fun TokenList.disableSortingByBalance(): TokenList {
|
||||
return when (this) {
|
||||
is TokenList.GroupedByNetwork -> this.copy(sortedBy = SortType.NONE)
|
||||
is TokenList.Ungrouped -> this.copy(sortedBy = SortType.NONE)
|
||||
is TokenList.GroupedByNetwork -> this.copy(sortedBy = TokensSortType.NONE)
|
||||
is TokenList.Ungrouped -> this.copy(sortedBy = TokensSortType.NONE)
|
||||
is TokenList.Empty -> this
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens.utils.converter
|
||||
|
||||
import com.tangem.domain.models.TokensSortType
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState
|
||||
|
|
@ -20,7 +21,7 @@ internal class TokenListToStateConverter(
|
|||
itemsState = itemsState,
|
||||
header = state.header.copy(
|
||||
isEnabled = itemsState !is OrganizeTokensListState.Empty,
|
||||
isSortedByBalance = value.sortedBy == TokenList.SortType.BALANCE,
|
||||
isSortedByBalance = value.sortedBy == TokensSortType.BALANCE,
|
||||
isGrouped = value is TokenList.GroupedByNetwork,
|
||||
),
|
||||
actions = state.actions.copy(
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ package com.tangem.feature.wallet.presentation.wallet.subscribers
|
|||
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
|
||||
import com.tangem.domain.core.lce.Lce
|
||||
import com.tangem.domain.core.lce.LceFlow
|
||||
import com.tangem.domain.models.TokensSortType
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.tokens.ApplyTokenListSortingUseCase
|
||||
import com.tangem.domain.tokens.RunPolkadotAccountHealthCheckUseCase
|
||||
import com.tangem.domain.tokens.error.TokenListError
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.domain.tokens.model.TotalFiatBalance
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
|
||||
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender
|
||||
import com.tangem.feature.wallet.presentation.wallet.domain.MultiWalletTokenListStore
|
||||
|
|
@ -55,7 +56,7 @@ internal class MultiWalletTokenListSubscriber(
|
|||
userWalletId = userWallet.walletId,
|
||||
sortedTokensIds = getCurrenciesIds(tokenList),
|
||||
isGroupedByNetwork = tokenList is TokenList.GroupedByNetwork,
|
||||
isSortedByBalance = tokenList.sortedBy == TokenList.SortType.BALANCE,
|
||||
isSortedByBalance = tokenList.sortedBy == TokensSortType.BALANCE,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +66,7 @@ internal class MultiWalletTokenListSubscriber(
|
|||
|
||||
return tokenList.takeIf {
|
||||
tokenList.totalFiatBalance is TotalFiatBalance.Loaded &&
|
||||
tokenList.sortedBy == TokenList.SortType.BALANCE
|
||||
tokenList.sortedBy == TokensSortType.BALANCE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue