Updated on 2026-08-14

This commit is contained in:
Tangem 2024-03-08 09:18:07 +08:00
parent 2f2dec3b67
commit 42e55156eb
9 changed files with 32 additions and 51 deletions

View file

@ -14,22 +14,23 @@ 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.models.UserWallet
import com.tangem.domain.wallets.usecase.IsNeedToBackupUseCase
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification
import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.*
import timber.log.Timber
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.flow
import javax.inject.Inject
import kotlin.collections.count
@Suppress("LongParameterList")
@ViewModelScoped
internal class GetMultiWalletWarningsFactory @Inject constructor(
private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase,
private val getTokenListUseCase: GetTokenListUseCase,
private val isDemoCardUseCase: IsDemoCardUseCase,
private val isReadyToShowRateAppUseCase: IsReadyToShowRateAppUseCase,
@ -40,15 +41,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor(
private var readyForRateAppNotification = false
fun create(clickIntents: WalletClickIntents): Flow<ImmutableList<WalletNotification>> {
val userWallet = getSelectedWalletSyncUseCase().fold(
ifLeft = {
Timber.e("Failed to get selected wallet $it")
return flowOf(value = persistentListOf())
},
ifRight = { it },
)
fun create(userWallet: UserWallet, clickIntents: WalletClickIntents): Flow<ImmutableList<WalletNotification>> {
val cardTypesResolver = userWallet.scanResponse.cardTypesResolver
val promoFlow = flow { emit(promoRepository.getChangellyPromoBanner()) }

View file

@ -9,21 +9,17 @@ import com.tangem.domain.tokens.GetPrimaryCurrencyStatusUpdatesUseCase
import com.tangem.domain.tokens.error.CurrencyStatusError
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase
import com.tangem.domain.wallets.usecase.IsNeedToBackupUseCase
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification
import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.*
import timber.log.Timber
import javax.inject.Inject
@ViewModelScoped
internal class GetSingleWalletWarningsFactory @Inject constructor(
private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase,
private val getPrimaryCurrencyStatusUpdatesUseCase: GetPrimaryCurrencyStatusUpdatesUseCase,
private val isDemoCardUseCase: IsDemoCardUseCase,
private val isReadyToShowRateAppUseCase: IsReadyToShowRateAppUseCase,
@ -33,15 +29,7 @@ internal class GetSingleWalletWarningsFactory @Inject constructor(
private var readyForRateAppNotification = false
fun create(clickIntents: WalletClickIntents): Flow<ImmutableList<WalletNotification>> {
val userWallet = getSelectedWalletSyncUseCase().fold(
ifLeft = {
Timber.e("Failed to get selected wallet $it")
return flowOf(value = persistentListOf())
},
ifRight = { it },
)
fun create(userWallet: UserWallet, clickIntents: WalletClickIntents): Flow<ImmutableList<WalletNotification>> {
val cardTypesResolver = userWallet.scanResponse.cardTypesResolver
return combine(

View file

@ -44,7 +44,7 @@ internal class MultiWalletContentLoader(
applyTokenListSortingUseCase = applyTokenListSortingUseCase,
),
MultiWalletWarningsSubscriber(
userWalletId = userWallet.walletId,
userWallet = userWallet,
stateHolder = stateHolder,
clickIntents = clickIntents,
getMultiWalletWarningsFactory = getMultiWalletWarningsFactory,

View file

@ -49,7 +49,7 @@ internal class SingleWalletContentLoader(
getCryptoCurrencyActionsUseCase = getCryptoCurrencyActionsUseCase,
),
SingleWalletNotificationsSubscriber(
userWalletId = userWallet.walletId,
userWallet = userWallet,
stateHolder = stateHolder,
clickIntents = clickIntents,
getSingleWalletWarningsFactory = getSingleWalletWarningsFactory,

View file

@ -38,7 +38,7 @@ internal class SingleWalletWithTokenContentLoader(
getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase,
),
MultiWalletWarningsSubscriber(
userWalletId = userWallet.walletId,
userWallet = userWallet,
stateHolder = stateHolder,
clickIntents = clickIntents,
getMultiWalletWarningsFactory = getMultiWalletWarningsFactory,

View file

@ -27,12 +27,12 @@ sealed class WalletNotification(val config: NotificationConfig) {
),
) {
object DevCard : Critical(
data object DevCard : Critical(
title = resourceReference(id = R.string.warning_developer_card_title),
subtitle = resourceReference(id = R.string.warning_developer_card_message),
)
object FailedCardValidation : Critical(
data object FailedCardValidation : Critical(
title = resourceReference(id = R.string.warning_failed_to_verify_card_title),
subtitle = resourceReference(id = R.string.warning_failed_to_verify_card_message),
)
@ -64,12 +64,12 @@ sealed class WalletNotification(val config: NotificationConfig) {
),
)
object NetworksUnreachable : Warning(
data object NetworksUnreachable : Warning(
title = resourceReference(id = R.string.warning_network_unreachable_title),
subtitle = resourceReference(id = R.string.warning_network_unreachable_message),
)
object SomeNetworksUnreachable : Warning(
data object SomeNetworksUnreachable : Warning(
title = resourceReference(id = R.string.warning_some_networks_unreachable_title),
subtitle = resourceReference(id = R.string.warning_some_networks_unreachable_message),
)
@ -80,7 +80,7 @@ sealed class WalletNotification(val config: NotificationConfig) {
onCloseClick = onCloseClick,
)
object TestNetCard : Warning(
data object TestNetCard : Warning(
title = resourceReference(id = R.string.warning_testnet_card_title),
subtitle = resourceReference(id = R.string.warning_testnet_card_message),
)

View file

@ -1,6 +1,6 @@
package com.tangem.feature.wallet.presentation.wallet.subscribers
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender
import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory
import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController
@ -15,7 +15,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.onEach
internal class MultiWalletWarningsSubscriber(
private val userWalletId: UserWalletId,
private val userWallet: UserWallet,
private val stateHolder: WalletStateController,
private val clickIntents: WalletClickIntents,
private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory,
@ -23,13 +23,13 @@ internal class MultiWalletWarningsSubscriber(
) : WalletSubscriber() {
override fun create(coroutineScope: CoroutineScope): Flow<ImmutableList<WalletNotification>> {
return getMultiWalletWarningsFactory.create(clickIntents)
return getMultiWalletWarningsFactory.create(userWallet, clickIntents)
.conflate()
.distinctUntilChanged()
.onEach { warnings ->
val displayedState = stateHolder.getWalletState(userWalletId)
val displayedState = stateHolder.getWalletState(userWallet.walletId)
stateHolder.update(SetWarningsTransformer(userWalletId, warnings))
stateHolder.update(SetWarningsTransformer(userWallet.walletId, warnings))
walletWarningsAnalyticsSender.send(displayedState, warnings)
}
}

View file

@ -1,6 +1,6 @@
package com.tangem.feature.wallet.presentation.wallet.subscribers
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender
import com.tangem.feature.wallet.presentation.wallet.domain.GetSingleWalletWarningsFactory
import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController
@ -18,7 +18,7 @@ import kotlinx.coroutines.flow.onEach
[REDACTED_AUTHOR]
*/
internal class SingleWalletNotificationsSubscriber(
private val userWalletId: UserWalletId,
private val userWallet: UserWallet,
private val stateHolder: WalletStateController,
private val getSingleWalletWarningsFactory: GetSingleWalletWarningsFactory,
private val walletWarningsAnalyticsSender: WalletWarningsAnalyticsSender,
@ -26,13 +26,13 @@ internal class SingleWalletNotificationsSubscriber(
) : WalletSubscriber() {
override fun create(coroutineScope: CoroutineScope): Flow<ImmutableList<WalletNotification>> {
return getSingleWalletWarningsFactory.create(clickIntents)
return getSingleWalletWarningsFactory.create(userWallet, clickIntents)
.conflate()
.distinctUntilChanged()
.onEach { warnings ->
val displayedState = stateHolder.getWalletState(userWalletId)
val displayedState = stateHolder.getWalletState(userWallet.walletId)
stateHolder.update(SetWarningsTransformer(userWalletId, warnings))
stateHolder.update(SetWarningsTransformer(userWallet.walletId, warnings))
walletWarningsAnalyticsSender.send(displayedState, warnings)
}
}

View file

@ -249,6 +249,12 @@ internal class WalletViewModel @Inject constructor(
}
private suspend fun addWallet(action: WalletsUpdateActionResolver.Action.AddWallet) {
walletScreenContentLoader.load(
userWallet = action.selectedWallet,
clickIntents = clickIntents,
coroutineScope = viewModelScope,
)
stateHolder.update(
AddWalletTransformer(
userWallet = action.selectedWallet,
@ -256,12 +262,6 @@ internal class WalletViewModel @Inject constructor(
),
)
walletScreenContentLoader.load(
userWallet = action.selectedWallet,
clickIntents = clickIntents,
coroutineScope = viewModelScope,
)
withContext(dispatchers.io) { delay(timeMillis = 700) }
scrollToWallet(index = action.selectedWalletIndex)