Updated on 2026-08-14

This commit is contained in:
Tangem 2024-02-08 11:17:26 +03:00
parent 8106b36fd6
commit 1e0876eea6
45 changed files with 301 additions and 292 deletions

View file

@ -4,13 +4,16 @@ import arrow.core.Either
import com.tangem.domain.common.CardTypesResolver
import com.tangem.domain.common.util.cardTypesResolver
import com.tangem.domain.demo.IsDemoCardUseCase
import com.tangem.domain.promo.PromoBanner
import com.tangem.domain.settings.IsReadyToShowRateAppUseCase
import com.tangem.domain.settings.ShouldShowSwapPromoWalletUseCase
import com.tangem.domain.tokens.GetTokenListUseCase
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.usecase.GetSelectedWalletSyncUseCase
import com.tangem.domain.wallets.usecase.IsNeedToBackupUseCase
import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification
@ -26,12 +29,15 @@ import kotlinx.coroutines.flow.flowOf
import timber.log.Timber
import javax.inject.Inject
@Suppress("LongParameterList")
@ViewModelScoped
internal class GetMultiWalletWarningsFactory @Inject constructor(
private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase,
private val getTokenListUseCase: GetTokenListUseCase,
private val isDemoCardUseCase: IsDemoCardUseCase,
private val isReadyToShowRateAppUseCase: IsReadyToShowRateAppUseCase,
private val shouldShowSwapPromoWalletUseCase: ShouldShowSwapPromoWalletUseCase,
private val promoRepository: PromoRepository,
private val isNeedToBackupUseCase: IsNeedToBackupUseCase,
) {
@ -52,9 +58,15 @@ internal class GetMultiWalletWarningsFactory @Inject constructor(
flow = getTokenListUseCase(userWallet.walletId).conflate(),
flow2 = isReadyToShowRateAppUseCase().conflate(),
flow3 = isNeedToBackupUseCase(userWallet.walletId).conflate(),
) { maybeTokenList, isReadyToShowRating, isNeedToBackup ->
flow4 = shouldShowSwapPromoWalletUseCase().conflate(),
) { maybeTokenList, isReadyToShowRating, isNeedToBackup, shouldShowPromo ->
val promoBanner = promoRepository.getChangellyPromoBanner()
readyForRateAppNotification = true
buildList {
addSwapPromoNotification(shouldShowPromo, promoBanner, clickIntents)
addCriticalNotifications(cardTypesResolver)
addInformationalNotifications(cardTypesResolver, maybeTokenList, clickIntents)
@ -66,6 +78,23 @@ internal class GetMultiWalletWarningsFactory @Inject constructor(
}
}
private fun MutableList<WalletNotification>.addSwapPromoNotification(
shouldShowPromo: Boolean,
promoBanner: PromoBanner?,
clickIntents: WalletClickIntentsV2,
) {
promoBanner ?: return
val promoNotification = WalletNotification.SwapPromo(
startDateTime = promoBanner.bannerState.timeline.start,
endDateTime = promoBanner.bannerState.timeline.end,
onCloseClick = clickIntents::onCloseSwapPromoClick,
)
addIf(
element = promoNotification,
condition = shouldShowPromo && promoBanner.isActive,
)
}
private fun MutableList<WalletNotification>.addCriticalNotifications(cardTypesResolver: CardTypesResolver) {
addIf(
element = WalletNotification.Critical.DevCard,

View file

@ -7,6 +7,7 @@ import com.tangem.core.ui.extensions.pluralReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.wrappedList
import com.tangem.feature.wallet.impl.R
import org.joda.time.DateTime
/**
* Wallet notification component state
@ -168,13 +169,21 @@ sealed class WalletNotification(val config: NotificationConfig) {
)
data class SwapPromo(
val startDateTime: DateTime,
val endDateTime: DateTime,
val onCloseClick: () -> Unit,
) : WalletNotification(
config = NotificationConfig(
title = resourceReference(id = R.string.main_swap_promotion_title),
subtitle = resourceReference(id = R.string.main_swap_promotion_message),
title = resourceReference(
id = R.string.main_swap_changelly_promotion_title,
formatArgs = wrappedList("0%"),
),
subtitle = resourceReference(
id = R.string.main_swap_changelly_promotion_message,
formatArgs = wrappedList("0%", startDateTime.dayOfMonth, endDateTime.dayOfMonth),
),
iconResId = R.drawable.img_swap_promo,
backgroundResId = R.drawable.img_swap_promo_banner_background,
backgroundResId = R.drawable.img_swap_promo_green_banner_background,
onCloseClick = onCloseClick,
),
)

View file

@ -72,6 +72,4 @@ internal interface WalletClickIntents {
fun onExploreClick()
fun onTransactionClick(txHash: String)
fun onCloseSwapPromoNotificationClick()
}

View file

@ -5,7 +5,6 @@ import com.tangem.domain.common.CardTypesResolver
import com.tangem.domain.common.util.cardTypesResolver
import com.tangem.domain.demo.IsDemoCardUseCase
import com.tangem.domain.settings.IsReadyToShowRateAppUseCase
import com.tangem.domain.settings.ShouldShowSwapPromoWalletUseCase
import com.tangem.domain.tokens.GetMissedAddressesCryptoCurrenciesUseCase
import com.tangem.domain.tokens.error.GetCurrenciesError
import com.tangem.domain.tokens.model.CryptoCurrency
@ -41,7 +40,6 @@ internal class WalletNotificationsListFactory(
private val isNeedToBackupUseCase: IsNeedToBackupUseCase,
private val getMissedAddressCryptoCurrenciesUseCase: GetMissedAddressesCryptoCurrenciesUseCase,
private val hasSingleWalletSignedHashesUseCase: HasSingleWalletSignedHashesUseCase,
private val shouldShowSwapPromoWalletUseCase: ShouldShowSwapPromoWalletUseCase,
private val clickIntents: WalletClickIntents,
) {
@ -57,12 +55,9 @@ internal class WalletNotificationsListFactory(
flow2 = isReadyToShowRateAppUseCase().conflate(),
flow3 = isNeedToBackupUseCase(selectedWallet.walletId).conflate(),
flow4 = getMissedAddressCryptoCurrenciesUseCase(selectedWallet.walletId).conflate(),
flow5 = shouldShowSwapPromoWalletUseCase().conflate(),
) { hasSignedHashes, isReadyToShowRating, isNeedToBackup, maybeMissedAddressCurrencies, isShowSwapPromo ->
) { hasSignedHashes, isReadyToShowRating, isNeedToBackup, maybeMissedAddressCurrencies ->
readyForRateAppNotification = true
buildList {
addSwapPromoNotification(isShowSwapPromo, cardTypesResolver)
addCriticalNotifications(cardTypesResolver)
addInformationalNotifications(cardTypesResolver, maybeMissedAddressCurrencies)
@ -86,18 +81,6 @@ internal class WalletNotificationsListFactory(
}
}
private fun MutableList<WalletNotification>.addSwapPromoNotification(
showSwapPromo: Boolean,
cardTypesResolver: CardTypesResolver,
) {
addIf(
element = WalletNotification.SwapPromo(
clickIntents::onCloseSwapPromoNotificationClick,
),
condition = showSwapPromo && cardTypesResolver.isMultiwalletAllowed(),
)
}
private fun MutableList<WalletNotification>.addCriticalNotifications(cardTypesResolver: CardTypesResolver) {
addIf(
element = WalletNotification.Critical.DevCard,

View file

@ -129,7 +129,6 @@ internal class WalletViewModel @Inject constructor(
private val getExplorerTransactionUrlUseCase: GetExplorerTransactionUrlUseCase,
private val isDemoCardUseCase: IsDemoCardUseCase,
private val scanCardToUnlockWalletUseCase: ScanCardToUnlockWalletClickHandler,
private val shouldShowSwapPromoWalletUseCase: ShouldShowSwapPromoWalletUseCase,
isReadyToShowRateAppUseCase: IsReadyToShowRateAppUseCase,
isNeedToBackupUseCase: IsNeedToBackupUseCase,
getMissedAddressesCryptoCurrenciesUseCase: GetMissedAddressesCryptoCurrenciesUseCase,
@ -148,7 +147,6 @@ internal class WalletViewModel @Inject constructor(
isNeedToBackupUseCase = isNeedToBackupUseCase,
getMissedAddressCryptoCurrenciesUseCase = getMissedAddressesCryptoCurrenciesUseCase,
hasSingleWalletSignedHashesUseCase = hasSingleWalletSignedHashesUseCase,
shouldShowSwapPromoWalletUseCase = shouldShowSwapPromoWalletUseCase,
clickIntents = this,
)
@ -795,12 +793,6 @@ internal class WalletViewModel @Inject constructor(
refreshSingleCurrencyContent(selectedWalletIndex)
}
override fun onCloseSwapPromoNotificationClick() {
viewModelScope.launch(dispatchers.main) {
shouldShowSwapPromoWalletUseCase.neverToShow()
}
}
// FIXME: refreshSingleCurrencyContent mustn't update the TxHistory and Buttons. It only must fetch primary
// currency. Now it not works because GetPrimaryCurrency's subscriber uses .distinctUntilChanged()
private fun refreshSingleCurrencyContent(walletIndex: Int) {

View file

@ -18,6 +18,7 @@ import com.tangem.domain.redux.LegacyAction
import com.tangem.domain.redux.ReduxStateHolder
import com.tangem.domain.settings.NeverToSuggestRateAppUseCase
import com.tangem.domain.settings.RemindToRateAppLaterUseCase
import com.tangem.domain.settings.ShouldShowSwapPromoWalletUseCase
import com.tangem.domain.tokens.FetchTokenListUseCase
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.wallets.models.UnlockWalletsError
@ -62,6 +63,8 @@ internal interface WalletWarningsClickIntents {
fun onDislikeAppClick()
fun onCloseRateAppWarningClick()
fun onCloseSwapPromoClick()
}
@Suppress("LongParameterList")
@ -82,6 +85,7 @@ internal class WalletWarningsClickIntentsImplementer @Inject constructor(
private val reduxStateHolder: ReduxStateHolder,
private val testerFeatureToggles: TesterFeatureToggles,
private val dispatchers: CoroutineDispatcherProvider,
private val shouldShowSwapPromoWalletUseCase: ShouldShowSwapPromoWalletUseCase,
) : BaseWalletClickIntents(), WalletWarningsClickIntents {
override fun onAddBackupCardClick() {
@ -302,4 +306,10 @@ internal class WalletWarningsClickIntentsImplementer @Inject constructor(
remindToRateAppLaterUseCase()
}
}
override fun onCloseSwapPromoClick() {
viewModelScope.launch(dispatchers.main) {
shouldShowSwapPromoWalletUseCase.neverToShow()
}
}
}