diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ToggleTokenListGroupingUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ToggleTokenListGroupingUseCase.kt index 20f1ae77ef..a179238d94 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ToggleTokenListGroupingUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ToggleTokenListGroupingUseCase.kt @@ -8,6 +8,7 @@ import arrow.core.raise.withError import com.tangem.domain.tokens.error.TokenListSortingError import com.tangem.domain.tokens.error.mapper.mapToTokenListSortingError import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.tokens.model.TotalFiatBalance import com.tangem.domain.tokens.operations.TokenListSortingOperations import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.withContext @@ -29,7 +30,7 @@ class ToggleTokenListGroupingUseCase( } private fun Raise.groupTokens(tokenList: TokenList.Ungrouped): TokenList.GroupedByNetwork { - ensure(tokenList.totalFiatBalance !is TokenList.FiatBalance.Loading) { + ensure(tokenList.totalFiatBalance !is TotalFiatBalance.Loading) { TokenListSortingError.TokenListIsLoading } @@ -47,7 +48,7 @@ class ToggleTokenListGroupingUseCase( private fun Raise.ungroupTokens( tokenList: TokenList.GroupedByNetwork, ): TokenList.Ungrouped { - ensure(tokenList.totalFiatBalance !is TokenList.FiatBalance.Loading) { + ensure(tokenList.totalFiatBalance !is TotalFiatBalance.Loading) { TokenListSortingError.TokenListIsLoading } 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 482940452a..2764f37e15 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 @@ -8,6 +8,7 @@ import arrow.core.raise.withError import com.tangem.domain.tokens.error.TokenListSortingError import com.tangem.domain.tokens.error.mapper.mapToTokenListSortingError import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.tokens.model.TotalFiatBalance import com.tangem.domain.tokens.operations.TokenListSortingOperations import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.withContext @@ -31,7 +32,7 @@ class ToggleTokenListSortingUseCase( private fun Raise.sortGroupedTokenList( tokenList: TokenList.GroupedByNetwork, ): TokenList.GroupedByNetwork { - ensure(tokenList.totalFiatBalance !is TokenList.FiatBalance.Loading) { + ensure(tokenList.totalFiatBalance !is TotalFiatBalance.Loading) { TokenListSortingError.TokenListIsLoading } @@ -48,7 +49,7 @@ class ToggleTokenListSortingUseCase( private fun Raise.sortUngroupedTokenList( tokenList: TokenList.Ungrouped, ): TokenList.Ungrouped { - ensure(tokenList.totalFiatBalance !is TokenList.FiatBalance.Loading) { + ensure(tokenList.totalFiatBalance !is TotalFiatBalance.Loading) { TokenListSortingError.TokenListIsLoading } 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 089bbdefde..88c7af38bd 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 @@ -12,7 +12,7 @@ import java.math.BigDecimal * @property sortedBy The criteria used for sorting the tokens. */ sealed class TokenList { - open val totalFiatBalance: FiatBalance = FiatBalance.Loading + open val totalFiatBalance: TotalFiatBalance = TotalFiatBalance.Loading open val sortedBy: SortType = SortType.NONE /** @@ -24,7 +24,7 @@ sealed class TokenList { */ data class GroupedByNetwork( val groups: List, - override val totalFiatBalance: FiatBalance, + override val totalFiatBalance: TotalFiatBalance, override val sortedBy: SortType, ) : TokenList() @@ -37,14 +37,14 @@ sealed class TokenList { */ data class Ungrouped( val currencies: List, - override val totalFiatBalance: FiatBalance, + override val totalFiatBalance: TotalFiatBalance, override val sortedBy: SortType, ) : TokenList() /** Represents a state where the token list is empty. */ object Empty : TokenList() { - override val totalFiatBalance: FiatBalance = FiatBalance.Loaded( + override val totalFiatBalance: TotalFiatBalance = TotalFiatBalance.Loaded( amount = BigDecimal.ZERO, isAllAmountsSummarized = true, ) @@ -54,32 +54,4 @@ sealed class TokenList { enum class SortType { NONE, BALANCE, } - - /** - * Represents the possible states of the fiat balance, including loading, failure, or a loaded amount. - */ - sealed class FiatBalance { - /** - * Represents the loading state of the fiat balance. - * This state indicates that the fiat balance is currently being retrieved or calculated. - */ - object Loading : FiatBalance() - - /** - * Represents the failure state of the fiat balance. - * This state indicates that an attempt to retrieve or calculate the fiat balance has failed. - */ - object Failed : FiatBalance() - - /** - * Represents the successfully loaded state of the fiat balance. - * - * @property amount The loaded fiat balance amount. - * @property isAllAmountsSummarized Indicates whether the amount includes a summary of all underlying amounts. - */ - data class Loaded( - val amount: BigDecimal, - val isAllAmountsSummarized: Boolean, - ) : FiatBalance() - } } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TotalFiatBalance.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TotalFiatBalance.kt new file mode 100644 index 0000000000..62786117ab --- /dev/null +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TotalFiatBalance.kt @@ -0,0 +1,31 @@ +package com.tangem.domain.tokens.model + +import java.math.BigDecimal + +/** + * Represents the possible states of the fiat balance, including loading, failure, or a loaded amount. + */ +sealed class TotalFiatBalance { + /** + * Represents the loading state of the fiat balance. + * This state indicates that the fiat balance is currently being retrieved or calculated. + */ + object Loading : TotalFiatBalance() + + /** + * Represents the failure state of the fiat balance. + * This state indicates that an attempt to retrieve or calculate the fiat balance has failed. + */ + object Failed : TotalFiatBalance() + + /** + * Represents the successfully loaded state of the fiat balance. + * + * @property amount The loaded fiat balance amount. + * @property isAllAmountsSummarized Indicates whether the amount includes a summary of all underlying amounts. + */ + data class Loaded( + val amount: BigDecimal, + val isAllAmountsSummarized: Boolean, + ) : TotalFiatBalance() +} \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListFiatBalanceOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListFiatBalanceOperations.kt index 78db26e8a0..2ff01885c9 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListFiatBalanceOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListFiatBalanceOperations.kt @@ -2,7 +2,7 @@ package com.tangem.domain.tokens.operations import arrow.core.NonEmptyList import com.tangem.domain.tokens.model.CryptoCurrencyStatus -import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.tokens.model.TotalFiatBalance import java.math.BigDecimal internal class TokenListFiatBalanceOperations( @@ -10,14 +10,14 @@ internal class TokenListFiatBalanceOperations( private val isAnyTokenLoading: Boolean, ) { - fun calculateFiatBalance(): TokenList.FiatBalance { - var fiatBalance: TokenList.FiatBalance = TokenList.FiatBalance.Loading + fun calculateFiatBalance(): TotalFiatBalance { + var fiatBalance: TotalFiatBalance = TotalFiatBalance.Loading if (isAnyTokenLoading) return fiatBalance for (token in currencies) { when (val status = token.value) { is CryptoCurrencyStatus.Loading -> { - fiatBalance = TokenList.FiatBalance.Loading + fiatBalance = TotalFiatBalance.Loading break } is CryptoCurrencyStatus.MissedDerivation, @@ -25,7 +25,7 @@ internal class TokenListFiatBalanceOperations( is CryptoCurrencyStatus.NoAmount, is CryptoCurrencyStatus.NoQuote, -> { - fiatBalance = TokenList.FiatBalance.Failed + fiatBalance = TotalFiatBalance.Failed break } is CryptoCurrencyStatus.NoAccount -> { @@ -43,9 +43,9 @@ internal class TokenListFiatBalanceOperations( return fiatBalance } - private fun recalculateNoAccountBalance(currentBalance: TokenList.FiatBalance): TokenList.FiatBalance { - return (currentBalance as? TokenList.FiatBalance.Loaded)?.copy(isAllAmountsSummarized = false) - ?: TokenList.FiatBalance.Loaded( + private fun recalculateNoAccountBalance(currentBalance: TotalFiatBalance): TotalFiatBalance { + return (currentBalance as? TotalFiatBalance.Loaded)?.copy(isAllAmountsSummarized = false) + ?: TotalFiatBalance.Loaded( amount = BigDecimal.ZERO, isAllAmountsSummarized = false, ) @@ -53,12 +53,12 @@ internal class TokenListFiatBalanceOperations( private fun recalculateBalance( status: CryptoCurrencyStatus.Loaded, - currentBalance: TokenList.FiatBalance, - ): TokenList.FiatBalance { + currentBalance: TotalFiatBalance, + ): TotalFiatBalance { return with(currentBalance) { - (this as? TokenList.FiatBalance.Loaded)?.copy( + (this as? TotalFiatBalance.Loaded)?.copy( amount = this.amount + status.fiatAmount, - ) ?: TokenList.FiatBalance.Loaded( + ) ?: TotalFiatBalance.Loaded( amount = status.fiatAmount, isAllAmountsSummarized = true, ) @@ -67,15 +67,15 @@ internal class TokenListFiatBalanceOperations( private fun recalculateBalance( status: CryptoCurrencyStatus.Custom, - currentBalance: TokenList.FiatBalance, - ): TokenList.FiatBalance { + currentBalance: TotalFiatBalance, + ): TotalFiatBalance { return with(currentBalance) { val isTokenAmountCanBeSummarized = status.fiatAmount != null - (this as? TokenList.FiatBalance.Loaded)?.copy( + (this as? TotalFiatBalance.Loaded)?.copy( amount = this.amount + (status.fiatAmount ?: BigDecimal.ZERO), isAllAmountsSummarized = isTokenAmountCanBeSummarized, - ) ?: TokenList.FiatBalance.Loaded( + ) ?: TotalFiatBalance.Loaded( amount = status.fiatAmount ?: BigDecimal.ZERO, isAllAmountsSummarized = isTokenAmountCanBeSummarized, ) 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 9c75a10432..0af48b7898 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 @@ -6,6 +6,7 @@ import arrow.core.raise.either import arrow.core.raise.withError 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.wallets.models.UserWalletId import kotlinx.coroutines.flow.* @@ -71,7 +72,7 @@ internal class TokenListOperations( private fun Raise.createTokenList( currencies: NonEmptyList, - fiatBalance: TokenList.FiatBalance, + fiatBalance: TotalFiatBalance, isAnyTokenLoading: Boolean, isGrouped: Boolean, isSortedByBalance: Boolean, @@ -87,7 +88,7 @@ internal class TokenListOperations( private fun Raise.createTokenList( sortingOperations: TokenListSortingOperations, - fiatBalance: TokenList.FiatBalance, + fiatBalance: TotalFiatBalance, isGrouped: Boolean, ): TokenList { return if (isGrouped) { @@ -99,7 +100,7 @@ internal class TokenListOperations( private fun Raise.createUngroupedTokenList( sortingOperations: TokenListSortingOperations, - fiatBalance: TokenList.FiatBalance, + fiatBalance: TotalFiatBalance, ): TokenList.Ungrouped = TokenList.Ungrouped( sortedBy = sortingOperations.getSortType(), totalFiatBalance = fiatBalance, @@ -113,7 +114,7 @@ internal class TokenListOperations( private fun Raise.createGroupedTokenList( sortingOperations: TokenListSortingOperations, - fiatBalance: TokenList.FiatBalance, + fiatBalance: TotalFiatBalance, ): TokenList.GroupedByNetwork = TokenList.GroupedByNetwork( sortedBy = sortingOperations.getSortType(), totalFiatBalance = fiatBalance, @@ -127,7 +128,7 @@ internal class TokenListOperations( private fun createUnsortedUngroupedTokenList( tokens: List, - fiatBalance: TokenList.FiatBalance, + fiatBalance: TotalFiatBalance, ): TokenList.Ungrouped { return TokenList.Ungrouped( sortedBy = TokenList.SortType.NONE, 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 2833be87eb..354252452c 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,10 +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.tokens.model.CryptoCurrencyStatus -import com.tangem.domain.tokens.model.Network -import com.tangem.domain.tokens.model.NetworkGroup -import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.tokens.model.* import java.math.BigDecimal internal class TokenListSortingOperations( @@ -22,7 +19,7 @@ internal class TokenListSortingOperations( constructor( tokenList: TokenList, sortByBalance: Boolean = tokenList.sortedBy == TokenList.SortType.BALANCE, - isAnyTokenLoading: Boolean = tokenList.totalFiatBalance is TokenList.FiatBalance.Loading, + isAnyTokenLoading: Boolean = tokenList.totalFiatBalance is TotalFiatBalance.Loading, ) : this( currencies = when (tokenList) { is TokenList.GroupedByNetwork -> tokenList.groups.flatMap { it.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 b831c9595a..e08a5348dd 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 @@ -7,6 +7,7 @@ import com.tangem.domain.tokens.mock.MockNetworksGroups.loadedNetworksGroups import com.tangem.domain.tokens.mock.MockNetworksGroups.sortedNetworksGroups import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.tokens.model.TotalFiatBalance import java.math.BigDecimal @Suppress("MemberVisibilityCanBePrivate") @@ -19,43 +20,43 @@ internal object MockTokenLists { val emptyGroupedTokenList = TokenList.GroupedByNetwork( groups = emptyList(), - totalFiatBalance = TokenList.FiatBalance.Failed, + totalFiatBalance = TotalFiatBalance.Failed, sortedBy = TokenList.SortType.NONE, ) val emptyUngroupedTokenList = TokenList.Ungrouped( currencies = emptyList(), - totalFiatBalance = TokenList.FiatBalance.Failed, + totalFiatBalance = TotalFiatBalance.Failed, sortedBy = TokenList.SortType.NONE, ) val failedGroupedTokenList = TokenList.GroupedByNetwork( groups = failedNetworksGroups, - totalFiatBalance = TokenList.FiatBalance.Failed, + totalFiatBalance = TotalFiatBalance.Failed, sortedBy = TokenList.SortType.NONE, ) val failedUngroupedTokenList = TokenList.Ungrouped( currencies = MockTokensStates.failedTokenStates, - totalFiatBalance = TokenList.FiatBalance.Failed, + totalFiatBalance = TotalFiatBalance.Failed, sortedBy = TokenList.SortType.NONE, ) val noQuotesUngroupedTokenList = failedUngroupedTokenList.copy( - totalFiatBalance = TokenList.FiatBalance.Failed, + totalFiatBalance = TotalFiatBalance.Failed, currencies = MockTokensStates.noQuotesTokensStatuses, ) val loadingUngroupedTokenList = with(failedUngroupedTokenList) { copy( currencies = currencies.map { it.copy(value = CryptoCurrencyStatus.Loading) }.toNonEmptyListOrNull() ?: emptyList(), - totalFiatBalance = TokenList.FiatBalance.Loading, + totalFiatBalance = TotalFiatBalance.Loading, ) } val loadingGroupedTokenList = with(failedGroupedTokenList) { copy( - totalFiatBalance = TokenList.FiatBalance.Loading, + totalFiatBalance = TotalFiatBalance.Loading, groups = groups.map { group -> group.copy( currencies = group.currencies @@ -72,7 +73,7 @@ internal object MockTokenLists { return failedUngroupedTokenList.copy( currencies = tokens, sortedBy = TokenList.SortType.NONE, - totalFiatBalance = TokenList.FiatBalance.Loaded( + totalFiatBalance = TotalFiatBalance.Loaded( amount = tokens.sumOf { it.value.fiatAmount ?: BigDecimal.ZERO }, isAllAmountsSummarized = true, ), @@ -86,7 +87,7 @@ internal object MockTokenLists { return failedGroupedTokenList.copy( groups = groups, sortedBy = TokenList.SortType.NONE, - totalFiatBalance = TokenList.FiatBalance.Loaded( + totalFiatBalance = TotalFiatBalance.Loaded( amount = groups .flatMap { it.currencies as NonEmptyList } .sumOf { it.value.fiatAmount ?: BigDecimal.ZERO }, diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/models/SaveWalletError.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/models/SaveWalletError.kt index 7b320009c7..a41524b8b7 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/models/SaveWalletError.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/models/SaveWalletError.kt @@ -5,7 +5,9 @@ package com.tangem.domain.wallets.models */ sealed interface SaveWalletError { - object DataError : SaveWalletError + val messageId: Int? - data class WalletAlreadySaved(val messageId: Int) : SaveWalletError + data class DataError(override val messageId: Int?) : SaveWalletError + + data class WalletAlreadySaved(override val messageId: Int) : SaveWalletError } \ No newline at end of file diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetWalletsUseCase.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetWalletsUseCase.kt index 4045a3a98a..554791e869 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetWalletsUseCase.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetWalletsUseCase.kt @@ -3,7 +3,6 @@ package com.tangem.domain.wallets.usecase import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.models.UserWallet import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.firstOrNull /** * Use case for getting list of user wallets @@ -18,5 +17,5 @@ class GetWalletsUseCase(private val userWalletsListManager: UserWalletsListManag operator fun invoke(): Flow> = userWalletsListManager.userWallets @Throws(IllegalArgumentException::class) - suspend fun invokeSync(): List? = userWalletsListManager.userWallets.firstOrNull() + fun invokeSync(): List = userWalletsListManager.userWalletsSync } \ No newline at end of file diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SaveWalletUseCase.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SaveWalletUseCase.kt index 0f3becefc0..469ef7b1fc 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SaveWalletUseCase.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SaveWalletUseCase.kt @@ -29,7 +29,7 @@ class SaveWalletUseCase(private val userWalletsListManager: UserWalletsListManag is UserWalletsListError.WalletAlreadySaved -> SaveWalletError.WalletAlreadySaved( it.messageResId, ) - else -> SaveWalletError.DataError + else -> SaveWalletError.DataError(it.messageResId) }.left() } diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt index 32f84a0f7f..9f2109e070 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt @@ -412,7 +412,7 @@ internal class SendViewModel @Inject constructor( runCatching { waitForDelay(delay = RECENT_LOAD_DELAY) { getWalletsUseCase.invokeSync() - ?.toAvailableWallets() + .toAvailableWallets() .orEmpty() } }.onSuccess { result -> diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt index 068801b384..2540a508f8 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt @@ -13,6 +13,7 @@ import com.tangem.domain.tokens.GetTokenListUseCase import com.tangem.domain.tokens.ToggleTokenListGroupingUseCase import com.tangem.domain.tokens.ToggleTokenListSortingUseCase import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.tokens.model.TotalFiatBalance import com.tangem.domain.wallets.models.UserWalletId import com.tangem.feature.wallet.featuretoggle.WalletFeatureToggles import com.tangem.feature.wallet.presentation.organizetokens.analytics.PortfolioOrganizeTokensAnalyticsEvent @@ -191,7 +192,7 @@ internal class OrganizeTokensViewModel @Inject constructor( } else { val maybeTokenList = getTokenListUseCase.launch(userWalletId) .first { maybeTokenList -> - maybeTokenList.getOrNull()?.totalFiatBalance !is TokenList.FiatBalance.Loading + maybeTokenList.getOrNull()?.totalFiatBalance !is TotalFiatBalance.Loading } maybeTokenList.getOrElse { error -> diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/TokenListAnalyticsSender.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/TokenListAnalyticsSender.kt index f0ca57a2b3..5d9840556b 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/TokenListAnalyticsSender.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/TokenListAnalyticsSender.kt @@ -11,6 +11,7 @@ import com.tangem.domain.analytics.model.WalletBalanceState import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.NetworkGroup import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.tokens.model.TotalFiatBalance import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent.Basic import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent.MainScreen @@ -35,7 +36,7 @@ internal class TokenListAnalyticsSender @Inject constructor( suspend fun send(displayedUiState: WalletState?, userWallet: UserWallet, tokenList: TokenList) { if (screenLifecycleProvider.isBackgroundState.value) return if (displayedUiState == null || displayedUiState.pullToRefreshConfig.isRefreshing) return - if (tokenList.totalFiatBalance is TokenList.FiatBalance.Loading) return + if (tokenList.totalFiatBalance is TotalFiatBalance.Loading) return val currenciesStatuses = getCurrenciesStatuses(tokenList) @@ -52,7 +53,7 @@ internal class TokenListAnalyticsSender @Inject constructor( } private fun sendBalanceLoadedEventIfNeeded( - fiatBalance: TokenList.FiatBalance, + fiatBalance: TotalFiatBalance, currenciesStatuses: List, ) { createCardBalanceState(fiatBalance, currenciesStatuses)?.let { balanceState -> @@ -61,13 +62,13 @@ internal class TokenListAnalyticsSender @Inject constructor( } private fun createCardBalanceState( - fiatBalance: TokenList.FiatBalance, + fiatBalance: TotalFiatBalance, currenciesStatuses: List, ): AnalyticsParam.CardBalanceState? { return when (fiatBalance) { - is TokenList.FiatBalance.Failed -> getCardBalanceState(currenciesStatuses) - is TokenList.FiatBalance.Loaded -> getCardBalanceState(fiatBalance) - is TokenList.FiatBalance.Loading -> null + is TotalFiatBalance.Failed -> getCardBalanceState(currenciesStatuses) + is TotalFiatBalance.Loaded -> getCardBalanceState(fiatBalance) + is TotalFiatBalance.Loading -> null } } @@ -125,7 +126,7 @@ internal class TokenListAnalyticsSender @Inject constructor( } } - private fun getCardBalanceState(fiatBalance: TokenList.FiatBalance.Loaded): AnalyticsParam.CardBalanceState { + private fun getCardBalanceState(fiatBalance: TotalFiatBalance.Loaded): AnalyticsParam.CardBalanceState { return if (fiatBalance.amount > BigDecimal.ZERO) { AnalyticsParam.CardBalanceState.Full } else { @@ -135,7 +136,7 @@ internal class TokenListAnalyticsSender @Inject constructor( private suspend fun sendToppedUpEventIfNeeded( userWallet: UserWallet, - fiatBalance: TokenList.FiatBalance, + fiatBalance: TotalFiatBalance, currenciesStatuses: List, ) { val balanceState = getWalletBalanceState(fiatBalance) ?: return @@ -157,17 +158,17 @@ internal class TokenListAnalyticsSender @Inject constructor( } } - private fun getWalletBalanceState(fiatBalance: TokenList.FiatBalance): WalletBalanceState? { + private fun getWalletBalanceState(fiatBalance: TotalFiatBalance): WalletBalanceState? { return when (fiatBalance) { - is TokenList.FiatBalance.Failed -> WalletBalanceState.Error - is TokenList.FiatBalance.Loaded -> { + is TotalFiatBalance.Failed -> WalletBalanceState.Error + is TotalFiatBalance.Loaded -> { if (fiatBalance.amount > BigDecimal.ZERO) { WalletBalanceState.ToppedUp } else { WalletBalanceState.Empty } } - is TokenList.FiatBalance.Loading -> null + is TotalFiatBalance.Loading -> null } } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCardStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCardStateConverter.kt index 1e1d944584..6a914a5c2a 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCardStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCardStateConverter.kt @@ -2,7 +2,7 @@ package com.tangem.feature.wallet.presentation.wallet.state.transformers.convert import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.appcurrency.model.AppCurrency -import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.tokens.model.TotalFiatBalance import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.domain.WalletAdditionalInfoFactory import com.tangem.feature.wallet.presentation.wallet.domain.getCardsCount @@ -10,16 +10,16 @@ import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState import com.tangem.utils.converter.Converter internal class MultiWalletCardStateConverter( - private val fiatBalance: TokenList.FiatBalance, + private val fiatBalance: TotalFiatBalance, private val selectedWallet: UserWallet, private val appCurrency: AppCurrency, ) : Converter { override fun convert(value: WalletCardState): WalletCardState { return when (fiatBalance) { - is TokenList.FiatBalance.Loading -> value.toLoadingState() - is TokenList.FiatBalance.Failed -> value.toErrorState() - is TokenList.FiatBalance.Loaded -> value.toWalletCardState(fiatBalance) + is TotalFiatBalance.Loading -> value.toLoadingState() + is TotalFiatBalance.Failed -> value.toErrorState() + is TotalFiatBalance.Loaded -> value.toWalletCardState(fiatBalance) } } @@ -45,7 +45,7 @@ internal class MultiWalletCardStateConverter( ) } - private fun WalletCardState.toWalletCardState(fiatBalance: TokenList.FiatBalance.Loaded): WalletCardState { + private fun WalletCardState.toWalletCardState(fiatBalance: TotalFiatBalance.Loaded): WalletCardState { return WalletCardState.Content( id = id, title = title, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenListStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenListStateConverter.kt index 02c8d42705..ccb6834bde 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenListStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenListStateConverter.kt @@ -6,6 +6,7 @@ import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.NetworkGroup import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.tokens.model.TotalFiatBalance import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTokensListState import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTokensListState.TokensListItemState @@ -79,7 +80,7 @@ internal class TokenListStateConverter( private fun getOrganizeTokensButtonState(currenciesSize: Int): WalletOrganizeTokensButtonConfig? { return if (currenciesSize > 1 && !isSingleCurrencyWalletWithToken()) { WalletOrganizeTokensButtonConfig( - isEnabled = tokenList.totalFiatBalance !is TokenList.FiatBalance.Loading, + isEnabled = tokenList.totalFiatBalance !is TotalFiatBalance.Loading, onClick = clickIntents::onOrganizeTokensClick, ) } else { 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 62576cf73a..595793c393 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 @@ -10,6 +10,7 @@ import com.tangem.domain.tokens.RunPolkadotAccountHealthCheckUseCase import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.tokens.model.TotalFiatBalance import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.featuretoggle.WalletFeatureToggles import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender @@ -65,7 +66,7 @@ internal class MultiWalletTokenListSubscriber( } private fun checkNeedSorting(tokenList: TokenList): Boolean { - return tokenList.totalFiatBalance !is TokenList.FiatBalance.Loading && + return tokenList.totalFiatBalance !is TotalFiatBalance.Loading && tokenList.sortedBy == TokenList.SortType.BALANCE }