Updated on 2026-08-14
This commit is contained in:
parent
d19703e048
commit
5d206bd37f
17 changed files with 107 additions and 98 deletions
|
|
@ -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<TokenListSortingError>.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<TokenListSortingError>.ungroupTokens(
|
||||
tokenList: TokenList.GroupedByNetwork,
|
||||
): TokenList.Ungrouped {
|
||||
ensure(tokenList.totalFiatBalance !is TokenList.FiatBalance.Loading) {
|
||||
ensure(tokenList.totalFiatBalance !is TotalFiatBalance.Loading) {
|
||||
TokenListSortingError.TokenListIsLoading
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<TokenListSortingError>.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<TokenListSortingError>.sortUngroupedTokenList(
|
||||
tokenList: TokenList.Ungrouped,
|
||||
): TokenList.Ungrouped {
|
||||
ensure(tokenList.totalFiatBalance !is TokenList.FiatBalance.Loading) {
|
||||
ensure(tokenList.totalFiatBalance !is TotalFiatBalance.Loading) {
|
||||
TokenListSortingError.TokenListIsLoading
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<NetworkGroup>,
|
||||
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<CryptoCurrencyStatus>,
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
}
|
||||
|
|
@ -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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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<Error>.createTokenList(
|
||||
currencies: NonEmptyList<CryptoCurrencyStatus>,
|
||||
fiatBalance: TokenList.FiatBalance,
|
||||
fiatBalance: TotalFiatBalance,
|
||||
isAnyTokenLoading: Boolean,
|
||||
isGrouped: Boolean,
|
||||
isSortedByBalance: Boolean,
|
||||
|
|
@ -87,7 +88,7 @@ internal class TokenListOperations(
|
|||
|
||||
private fun Raise<Error>.createTokenList(
|
||||
sortingOperations: TokenListSortingOperations,
|
||||
fiatBalance: TokenList.FiatBalance,
|
||||
fiatBalance: TotalFiatBalance,
|
||||
isGrouped: Boolean,
|
||||
): TokenList {
|
||||
return if (isGrouped) {
|
||||
|
|
@ -99,7 +100,7 @@ internal class TokenListOperations(
|
|||
|
||||
private fun Raise<Error>.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<Error>.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<CryptoCurrencyStatus>,
|
||||
fiatBalance: TokenList.FiatBalance,
|
||||
fiatBalance: TotalFiatBalance,
|
||||
): TokenList.Ungrouped {
|
||||
return TokenList.Ungrouped(
|
||||
sortedBy = TokenList.SortType.NONE,
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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<CryptoCurrencyStatus> }
|
||||
.sumOf { it.value.fiatAmount ?: BigDecimal.ZERO },
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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<List<UserWallet>> = userWalletsListManager.userWallets
|
||||
|
||||
@Throws(IllegalArgumentException::class)
|
||||
suspend fun invokeSync(): List<UserWallet>? = userWalletsListManager.userWallets.firstOrNull()
|
||||
fun invokeSync(): List<UserWallet> = userWalletsListManager.userWalletsSync
|
||||
}
|
||||
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -412,7 +412,7 @@ internal class SendViewModel @Inject constructor(
|
|||
runCatching {
|
||||
waitForDelay(delay = RECENT_LOAD_DELAY) {
|
||||
getWalletsUseCase.invokeSync()
|
||||
?.toAvailableWallets()
|
||||
.toAvailableWallets()
|
||||
.orEmpty()
|
||||
}
|
||||
}.onSuccess { result ->
|
||||
|
|
|
|||
|
|
@ -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 ->
|
||||
|
|
|
|||
|
|
@ -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<CryptoCurrencyStatus>,
|
||||
) {
|
||||
createCardBalanceState(fiatBalance, currenciesStatuses)?.let { balanceState ->
|
||||
|
|
@ -61,13 +62,13 @@ internal class TokenListAnalyticsSender @Inject constructor(
|
|||
}
|
||||
|
||||
private fun createCardBalanceState(
|
||||
fiatBalance: TokenList.FiatBalance,
|
||||
fiatBalance: TotalFiatBalance,
|
||||
currenciesStatuses: List<CryptoCurrencyStatus>,
|
||||
): 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<CryptoCurrencyStatus>,
|
||||
) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<WalletCardState, WalletCardState> {
|
||||
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue