Updated on 2026-08-14
This commit is contained in:
parent
64a5db094e
commit
7476cc4e98
7 changed files with 24 additions and 55 deletions
|
|
@ -54,4 +54,13 @@ sealed class TokenList {
|
|||
enum class SortType {
|
||||
NONE, BALANCE,
|
||||
}
|
||||
|
||||
/** Get flatten list of cryptocurrency status [CryptoCurrencyStatus] */
|
||||
fun flattenCurrencies(): List<CryptoCurrencyStatus> {
|
||||
return when (this) {
|
||||
is GroupedByNetwork -> groups.flatMap(NetworkGroup::currencies)
|
||||
is Ungrouped -> currencies
|
||||
is Empty -> emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,11 +23,7 @@ internal class TokenListSortingOperations(
|
|||
sortByBalance: Boolean = tokenList.sortedBy == TokenList.SortType.BALANCE,
|
||||
isAnyTokenLoading: Boolean = tokenList.totalFiatBalance is TotalFiatBalance.Loading,
|
||||
) : this(
|
||||
currencies = when (tokenList) {
|
||||
is TokenList.GroupedByNetwork -> tokenList.groups.flatMap { it.currencies }
|
||||
is TokenList.Ungrouped -> tokenList.currencies
|
||||
is TokenList.Empty -> emptyList()
|
||||
},
|
||||
currencies = tokenList.flattenCurrencies(),
|
||||
isAnyTokenLoading = isAnyTokenLoading,
|
||||
sortByBalance = sortByBalance,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import com.tangem.core.analytics.models.AnalyticsParam
|
|||
import com.tangem.domain.analytics.CheckIsWalletToppedUpUseCase
|
||||
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
|
||||
|
|
@ -38,7 +37,7 @@ internal class TokenListAnalyticsSender @Inject constructor(
|
|||
if (displayedUiState == null || displayedUiState.pullToRefreshConfig.isRefreshing) return
|
||||
if (tokenList.totalFiatBalance is TotalFiatBalance.Loading) return
|
||||
|
||||
val currenciesStatuses = getCurrenciesStatuses(tokenList)
|
||||
val currenciesStatuses = tokenList.flattenCurrencies()
|
||||
|
||||
sendBalanceLoadedEventIfNeeded(tokenList.totalFiatBalance, currenciesStatuses)
|
||||
sendToppedUpEventIfNeeded(userWallet, tokenList.totalFiatBalance, currenciesStatuses)
|
||||
|
|
@ -46,12 +45,6 @@ internal class TokenListAnalyticsSender @Inject constructor(
|
|||
sendTokenBalancesIfNeeded(currenciesStatuses)
|
||||
}
|
||||
|
||||
private fun getCurrenciesStatuses(tokenList: TokenList): List<CryptoCurrencyStatus> = when (tokenList) {
|
||||
is TokenList.Empty -> emptyList()
|
||||
is TokenList.GroupedByNetwork -> tokenList.groups.flatMap(NetworkGroup::currencies)
|
||||
is TokenList.Ungrouped -> tokenList.currencies
|
||||
}
|
||||
|
||||
private fun sendBalanceLoadedEventIfNeeded(
|
||||
fiatBalance: TotalFiatBalance,
|
||||
currenciesStatuses: List<CryptoCurrencyStatus>,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import com.tangem.domain.settings.ShouldShowRingPromoUseCase
|
|||
import com.tangem.domain.tokens.error.TokenListError
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
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.repository.PromoRepository
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
|
|
@ -144,13 +143,8 @@ internal class GetMultiWalletWarningsFactory @Inject constructor(
|
|||
private fun Lce<TokenListError, TokenList>.getMissingAddressCurrencies(): List<CryptoCurrency> {
|
||||
val tokenList = getOrNull(isPartialContentAccepted = false) ?: return emptyList()
|
||||
|
||||
val currencies = when (tokenList) {
|
||||
is TokenList.GroupedByNetwork -> tokenList.groups.flatMap(NetworkGroup::currencies)
|
||||
is TokenList.Ungrouped -> tokenList.currencies
|
||||
is TokenList.Empty -> emptyList()
|
||||
}
|
||||
|
||||
return currencies
|
||||
return tokenList
|
||||
.flattenCurrencies()
|
||||
.filter { it.value is CryptoCurrencyStatus.MissedDerivation }
|
||||
.map(CryptoCurrencyStatus::currency)
|
||||
}
|
||||
|
|
@ -182,13 +176,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor(
|
|||
private fun Lce<TokenListError, TokenList>.hasUnreachableNetworks(): Boolean {
|
||||
val tokenList = getOrNull(isPartialContentAccepted = false) ?: return false
|
||||
|
||||
val currencies = when (tokenList) {
|
||||
is TokenList.GroupedByNetwork -> tokenList.groups.flatMap(NetworkGroup::currencies)
|
||||
is TokenList.Ungrouped -> tokenList.currencies
|
||||
is TokenList.Empty -> emptyList()
|
||||
}
|
||||
|
||||
return currencies.any { it.value is CryptoCurrencyStatus.Unreachable }
|
||||
return tokenList.flattenCurrencies().any { it.value is CryptoCurrencyStatus.Unreachable }
|
||||
}
|
||||
|
||||
private fun MutableList<WalletNotification>.addRateTheAppNotification(
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.tangem.feature.wallet.presentation.wallet.domain
|
|||
import com.tangem.common.extensions.isZero
|
||||
import com.tangem.domain.settings.SetWalletWithFundsFoundUseCase
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.domain.tokens.model.NetworkGroup
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -12,15 +11,7 @@ internal class WalletWithFundsChecker @Inject constructor(
|
|||
) {
|
||||
|
||||
suspend fun check(tokenList: TokenList) {
|
||||
val hasNonZeroWallets = when (tokenList) {
|
||||
is TokenList.GroupedByNetwork -> {
|
||||
tokenList.groups
|
||||
.flatMap(NetworkGroup::currencies)
|
||||
.hasNonZeroWallets()
|
||||
}
|
||||
is TokenList.Ungrouped -> tokenList.currencies.hasNonZeroWallets()
|
||||
is TokenList.Empty -> false
|
||||
}
|
||||
val hasNonZeroWallets = tokenList.flattenCurrencies().hasNonZeroWallets()
|
||||
|
||||
if (hasNonZeroWallets) setWalletWithFundsFoundUseCase()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import com.tangem.domain.core.lce.LceFlow
|
|||
import com.tangem.domain.core.utils.getOrElse
|
||||
import com.tangem.domain.tokens.RunPolkadotAccountHealthCheckUseCase
|
||||
import com.tangem.domain.tokens.error.TokenListError
|
||||
import com.tangem.domain.tokens.model.NetworkGroup
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender
|
||||
|
|
@ -99,15 +98,14 @@ internal abstract class BasicTokenListSubscriber(
|
|||
private suspend fun startCheck(maybeTokenList: Lce<TokenListError, TokenList>) {
|
||||
// Run Polkadot account health check
|
||||
maybeTokenList.getOrNull()?.let { tokenList ->
|
||||
val cryptoCurrencies = when (tokenList) {
|
||||
is TokenList.GroupedByNetwork -> tokenList.groups.flatMap(NetworkGroup::currencies)
|
||||
is TokenList.Ungrouped -> tokenList.currencies
|
||||
is TokenList.Empty -> emptyList()
|
||||
}
|
||||
|
||||
cryptoCurrencies.forEach {
|
||||
runPolkadotAccountHealthCheckUseCase(userWallet.walletId, it.currency.network)
|
||||
}
|
||||
tokenList
|
||||
.flattenCurrencies()
|
||||
.forEach {
|
||||
runPolkadotAccountHealthCheckUseCase(
|
||||
userWalletId = userWallet.walletId,
|
||||
network = it.currency.network,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,12 +70,6 @@ internal class MultiWalletTokenListSubscriber(
|
|||
}
|
||||
|
||||
private fun getCurrenciesIds(tokenList: TokenList): List<CryptoCurrency.ID> {
|
||||
return when (tokenList) {
|
||||
is TokenList.GroupedByNetwork -> tokenList.groups.flatMap { group ->
|
||||
group.currencies.map { it.currency.id }
|
||||
}
|
||||
is TokenList.Ungrouped -> tokenList.currencies.map { it.currency.id }
|
||||
is TokenList.Empty -> emptyList()
|
||||
}
|
||||
return tokenList.flattenCurrencies().map { it.currency.id }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue