diff --git a/domain/account/src/main/java/com/tangem/domain/account/models/AccountStatusList.kt b/domain/account/src/main/java/com/tangem/domain/account/models/AccountStatusList.kt index 2ab3ad738b..9581d1a6fb 100644 --- a/domain/account/src/main/java/com/tangem/domain/account/models/AccountStatusList.kt +++ b/domain/account/src/main/java/com/tangem/domain/account/models/AccountStatusList.kt @@ -2,6 +2,7 @@ package com.tangem.domain.account.models import com.tangem.domain.models.TotalFiatBalance import com.tangem.domain.models.account.AccountStatus +import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.wallet.UserWallet import kotlinx.serialization.Serializable @@ -29,4 +30,8 @@ data class AccountStatusList( is AccountStatus.CryptoPortfolio -> accountStatus.account.isMainAccount } } + + fun flattenCurrencies(): List = accountStatuses + .map { accountStatus -> accountStatus.flattenCurrencies() } + .flatten() } \ No newline at end of file diff --git a/domain/models/src/main/kotlin/com/tangem/domain/models/account/AccountStatus.kt b/domain/models/src/main/kotlin/com/tangem/domain/models/account/AccountStatus.kt index 1712913f2e..0d99a1abb2 100644 --- a/domain/models/src/main/kotlin/com/tangem/domain/models/account/AccountStatus.kt +++ b/domain/models/src/main/kotlin/com/tangem/domain/models/account/AccountStatus.kt @@ -1,6 +1,7 @@ package com.tangem.domain.models.account import com.tangem.domain.core.lce.Lce +import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.quote.PriceChange import com.tangem.domain.models.tokenlist.TokenList import kotlinx.serialization.Serializable @@ -29,4 +30,8 @@ sealed interface AccountStatus { val tokenList: TokenList, val priceChangeLce: Lce, ) : AccountStatus + + fun flattenCurrencies(): List = when (this) { + is CryptoPortfolio -> tokenList.flattenCurrencies() + } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt index b54f0a1bb1..2d5684a5c0 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt @@ -9,6 +9,8 @@ import com.tangem.core.decompose.di.ModelScoped import com.tangem.core.ui.components.notifications.NotificationConfig.ButtonsState import com.tangem.core.ui.components.notifications.NotificationConfig.IconTint import com.tangem.core.ui.extensions.resourceReference +import com.tangem.domain.account.models.AccountStatusList +import com.tangem.domain.account.status.producer.SingleAccountStatusListProducer import com.tangem.domain.card.CardTypesResolver import com.tangem.domain.card.common.util.cardTypesResolver import com.tangem.domain.core.lce.Lce @@ -33,6 +35,7 @@ import com.tangem.domain.wallets.usecase.SeedPhraseNotificationUseCase import com.tangem.feature.wallet.child.wallet.model.WalletActivationBannerType import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents import com.tangem.feature.wallet.impl.R +import com.tangem.feature.wallet.presentation.account.AccountDependencies import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification import com.tangem.features.yield.supply.api.YieldSupplyFeatureToggles import com.tangem.lib.crypto.BlockchainUtils.isBitcoin @@ -60,14 +63,21 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( private val getOnrampCountryUseCase: GetOnrampCountryUseCase, private val notificationsRepository: NotificationsRepository, private val yieldSupplyFeatureToggles: YieldSupplyFeatureToggles, + private val accountDependencies: AccountDependencies, ) { @Suppress("UNCHECKED_CAST", "MagicNumber") fun create(userWallet: UserWallet, clickIntents: WalletClickIntents): Flow> { val cardTypesResolver = (userWallet as? UserWallet.Cold)?.scanResponse?.cardTypesResolver + val tokenListFlow = if (accountDependencies.accountsFeatureToggles.isFeatureEnabled) { + val params = SingleAccountStatusListProducer.Params(userWallet.walletId) + accountDependencies.singleAccountStatusListSupplier(params) + } else { + tokenListStore.getOrThrow(userWallet.walletId) + } return combine( - tokenListStore.getOrThrow(userWallet.walletId), + tokenListFlow, isReadyToShowRateAppUseCase(), isNeedToBackupUseCase(userWallet.walletId), seedPhraseNotificationUseCase(userWalletId = userWallet.walletId), @@ -75,7 +85,18 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( shouldShowPromoWalletUseCase(userWalletId = userWallet.walletId, promoId = PromoId.Sepa), notificationsRepository.getShouldShowNotification(NotificationId.EnablePushesReminderNotification.key), ) { array -> - val maybeTokenList = array[0] as Lce + val totalFiatBalance: Lce + val flattenCurrencies: Lce> + if (accountDependencies.accountsFeatureToggles.isFeatureEnabled) { + val accountStatusList = array[0] as AccountStatusList + totalFiatBalance = Lce.Content(accountStatusList.totalFiatBalance) + flattenCurrencies = Lce.Content(accountStatusList.flattenCurrencies()) + } else { + val maybeTokenList = array[0] as Lce + totalFiatBalance = maybeTokenList.map { it.totalFiatBalance } + flattenCurrencies = maybeTokenList.map { it.flattenCurrencies() } + } + val isReadyToShowRating = array[1] as Boolean val isNeedToBackup = array[2] as Boolean val seedPhraseIssueStatus = array[3] as SeedPhraseNotificationsStatus @@ -84,19 +105,19 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( val shouldShowEnablePushesReminderNotification = array[6] as Boolean buildList { - addUsedOutdatedDataNotification(maybeTokenList) + addUsedOutdatedDataNotification(totalFiatBalance) addCriticalNotifications(userWallet, seedPhraseIssueStatus, clickIntents) - addFinishWalletActivationNotification(userWallet, maybeTokenList, clickIntents) + addFinishWalletActivationNotification(userWallet, totalFiatBalance, clickIntents) addReferralPromoNotification(cardTypesResolver, clickIntents, shouldShowReferralPromo) addSepaPromoNotification(userWallet, clickIntents, shouldShowSepaBanner) - addInformationalNotifications(userWallet, cardTypesResolver, maybeTokenList, clickIntents) + addInformationalNotifications(userWallet, cardTypesResolver, flattenCurrencies, clickIntents) - addWarningNotifications(cardTypesResolver, maybeTokenList, isNeedToBackup, clickIntents) + addWarningNotifications(cardTypesResolver, flattenCurrencies, isNeedToBackup, clickIntents) addPushReminderNotification( clickIntents = clickIntents, @@ -104,7 +125,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( !notificationsRepository.isUserAllowToSubscribeOnPushNotifications(), ) - addYieldSupplyNotifications(maybeTokenList) + addYieldSupplyNotifications(flattenCurrencies) val hasCriticalOrWarning = any { notification -> notification is WalletNotification.Critical || notification is WalletNotification.Warning @@ -118,16 +139,16 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( } private fun MutableList.addUsedOutdatedDataNotification( - maybeTokenList: Lce, + totalFiatBalance: Lce, ) { addIf( element = WalletNotification.UsedOutdatedData, - condition = maybeTokenList.fold( + condition = totalFiatBalance.fold( ifLoading = { - (it?.totalFiatBalance as? TotalFiatBalance.Loaded)?.source == StatusSource.ONLY_CACHE + (it as? TotalFiatBalance.Loaded)?.source == StatusSource.ONLY_CACHE }, ifContent = { - (it.totalFiatBalance as? TotalFiatBalance.Loaded)?.source == StatusSource.ONLY_CACHE + (it as? TotalFiatBalance.Loaded)?.source == StatusSource.ONLY_CACHE }, ifError = { false }, ), @@ -205,7 +226,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( private fun MutableList.addInformationalNotifications( userWallet: UserWallet, cardTypesResolver: CardTypesResolver?, - maybeTokenList: Lce, + flattenCurrencies: Lce>, clickIntents: WalletClickIntents, ) { addIf( @@ -213,15 +234,15 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( condition = cardTypesResolver != null && isDemoCardUseCase(cardId = cardTypesResolver.getCardId()), ) - addMissingAddressesNotification(userWallet, maybeTokenList, clickIntents) + addMissingAddressesNotification(userWallet, flattenCurrencies, clickIntents) } private fun MutableList.addMissingAddressesNotification( userWallet: UserWallet, - maybeTokenList: Lce, + flattenCurrencies: Lce>, clickIntents: WalletClickIntents, ) { - val currencies = maybeTokenList.getMissingAddressCurrencies() + val currencies = flattenCurrencies.getMissingAddressCurrencies() .ifEmpty { return } addIf( @@ -236,11 +257,10 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( ) } - private fun Lce.getMissingAddressCurrencies(): List { - val tokenList = getOrNull(isPartialContentAccepted = true) ?: return emptyList() + private fun Lce>.getMissingAddressCurrencies(): List { + val flattenCurrencies = getOrNull(isPartialContentAccepted = true) ?: return emptyList() - return tokenList - .flattenCurrencies() + return flattenCurrencies .filter { it.value is CryptoCurrencyStatus.MissedDerivation } .map(CryptoCurrencyStatus::currency) } @@ -292,17 +312,17 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( } private fun MutableList.addYieldSupplyNotifications( - tokenList: Lce, + flattenCurrencies: Lce>, ) { addIf( element = WalletNotification.Warning.YeildSupplyApprove, - condition = tokenList.hasTokensWithActivatedSupplyWithoutApprove(), + condition = flattenCurrencies.hasTokensWithActivatedSupplyWithoutApprove(), ) } private fun MutableList.addWarningNotifications( cardTypesResolver: CardTypesResolver?, - tokenList: Lce, + flattenCurrencies: Lce>, isNeedToBackup: Boolean, clickIntents: WalletClickIntents, ) { @@ -320,7 +340,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( addIf( element = WalletNotification.Warning.SomeNetworksUnreachable, - condition = tokenList.hasUnreachableNetworks(), + condition = flattenCurrencies.hasUnreachableNetworks(), ) } @@ -337,16 +357,16 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( ) } - private fun Lce.hasUnreachableNetworks(): Boolean { - val tokenList = getOrNull(isPartialContentAccepted = false) ?: return false + private fun Lce>.hasUnreachableNetworks(): Boolean { + val flattenCurrencies = getOrNull(isPartialContentAccepted = false) ?: return false - return tokenList.flattenCurrencies().any { it.value is CryptoCurrencyStatus.Unreachable } + return flattenCurrencies.any { it.value is CryptoCurrencyStatus.Unreachable } } - private fun Lce.hasTokensWithActivatedSupplyWithoutApprove(): Boolean { - val tokenList = getOrNull(isPartialContentAccepted = false) ?: return false + private fun Lce>.hasTokensWithActivatedSupplyWithoutApprove(): Boolean { + val flattenCurrencies = getOrNull(isPartialContentAccepted = false) ?: return false val yieldSupplyEnabled = yieldSupplyFeatureToggles.isYieldSupplyFeatureEnabled - return yieldSupplyEnabled && tokenList.flattenCurrencies().any { + return yieldSupplyEnabled && flattenCurrencies.any { it.value.yieldSupplyStatus?.isAllowedToSpend == false } } @@ -365,8 +385,8 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( ) } - private fun TokenList?.getFinishWalletActivationType(): WalletActivationBannerType { - return if ((this?.totalFiatBalance as? TotalFiatBalance.Loaded)?.amount?.isPositive() == true) { + private fun TotalFiatBalance?.getFinishWalletActivationType(): WalletActivationBannerType { + return if ((this as? TotalFiatBalance.Loaded)?.amount?.isPositive() == true) { WalletActivationBannerType.Warning } else { WalletActivationBannerType.Attention @@ -375,14 +395,14 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( private fun MutableList.addFinishWalletActivationNotification( userWallet: UserWallet, - maybeTokenList: Lce, + totalFiatBalance: Lce, clickIntents: WalletClickIntents, ) { if (userWallet !is UserWallet.Hot) return val shouldShowFinishActivation = !userWallet.backedUp - val type = maybeTokenList.fold( + val type = totalFiatBalance.fold( ifLoading = { it.getFinishWalletActivationType() }, ifContent = { it.getFinishWalletActivationType() }, ifError = { WalletActivationBannerType.Attention },