diff --git a/domain/models/src/main/kotlin/com/tangem/domain/models/TokensGroupType.kt b/domain/models/src/main/kotlin/com/tangem/domain/models/TokensGroupType.kt new file mode 100644 index 0000000000..23982e6f41 --- /dev/null +++ b/domain/models/src/main/kotlin/com/tangem/domain/models/TokensGroupType.kt @@ -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, + ; +} \ No newline at end of file diff --git a/domain/models/src/main/kotlin/com/tangem/domain/models/TokensSortType.kt b/domain/models/src/main/kotlin/com/tangem/domain/models/TokensSortType.kt new file mode 100644 index 0000000000..0e85408187 --- /dev/null +++ b/domain/models/src/main/kotlin/com/tangem/domain/models/TokensSortType.kt @@ -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, + ; +} \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ToggleTokenListSortingUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ToggleTokenListSortingUseCase.kt index 2764f37e15..b45c106eef 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ToggleTokenListSortingUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ToggleTokenListSortingUseCase.kt @@ -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, ) } } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenList.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenList.kt index 3814c64c01..494924c0ce 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenList.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenList.kt @@ -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, 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, 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 { return when (this) { diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListOperations.kt index ab21e7d932..9d742c8ac5 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListOperations.kt @@ -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, ) diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListSortingOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListSortingOperations.kt index 0eb4730daf..73f809d1c4 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListSortingOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListSortingOperations.kt @@ -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.groupTokens(): NonEmptyList { val groupedTokens = currencies diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt index a9a32bc442..10fd0c9e44 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt @@ -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 } @@ -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, ) } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/organizetokens/model/OrganizeTokensModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/organizetokens/model/OrganizeTokensModel.kt index 0cc0cdffde..7aeebcd81e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/organizetokens/model/OrganizeTokensModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/organizetokens/model/OrganizeTokensModel.kt @@ -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) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/common/TokenListOperations.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/common/TokenListOperations.kt index 38b17ef15f..4ff807e1f8 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/common/TokenListOperations.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/common/TokenListOperations.kt @@ -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 } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/converter/TokenListToStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/converter/TokenListToStateConverter.kt index 6d1cf1b5b8..12a713c0ff 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/converter/TokenListToStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/converter/TokenListToStateConverter.kt @@ -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( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt index a06e2509e8..82b335a45e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt @@ -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 } }