diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletContentLoaderFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletContentLoaderFactory.kt new file mode 100644 index 0000000000..a6d0db40dc --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletContentLoaderFactory.kt @@ -0,0 +1,40 @@ +package com.tangem.feature.wallet.presentation.wallet.loaders + +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.common.util.cardTypesResolver +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.feature.wallet.presentation.wallet.loaders.implementors.MultiWalletContentLoaderFactory +import com.tangem.feature.wallet.presentation.wallet.loaders.implementors.SingleWalletContentLoaderFactory +import com.tangem.feature.wallet.presentation.wallet.loaders.implementors.SingleWalletWithTokenContentLoaderFactory +import com.tangem.feature.wallet.presentation.wallet.loaders.implementors.WalletContentLoader +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import dagger.hilt.android.scopes.ViewModelScoped +import javax.inject.Inject + +@ViewModelScoped +internal class WalletContentLoaderFactory @Inject constructor( + private val multiWalletContentLoaderFactory: MultiWalletContentLoaderFactory, + private val singleWalletWithTokenContentLoaderFactory: SingleWalletWithTokenContentLoaderFactory, + private val singleWalletContentLoaderFactory: SingleWalletContentLoaderFactory, +) { + + fun create( + userWallet: UserWallet, + appCurrency: AppCurrency, + clickIntents: WalletClickIntentsV2, + isRefresh: Boolean = false, + ): WalletContentLoader? { + return when { + userWallet.isMultiCurrency -> { + multiWalletContentLoaderFactory.create(userWallet, appCurrency, clickIntents) + } + userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken() -> { + singleWalletWithTokenContentLoaderFactory.create(userWallet, appCurrency, clickIntents) + } + !userWallet.isMultiCurrency -> { + singleWalletContentLoaderFactory.create(userWallet, appCurrency, clickIntents, isRefresh) + } + else -> null + } + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletLoaderStorage.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletLoaderStorage.kt new file mode 100644 index 0000000000..11414466c8 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletLoaderStorage.kt @@ -0,0 +1,26 @@ +package com.tangem.feature.wallet.presentation.wallet.loaders + +import com.tangem.domain.wallets.models.UserWalletId +import kotlinx.coroutines.Job +import java.util.concurrent.ConcurrentHashMap +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +internal class WalletLoaderStorage @Inject constructor() { + + private val loaders = ConcurrentHashMap>() + + fun contains(id: UserWalletId) = loaders.containsKey(id) + + fun set(id: UserWalletId, jobs: List) { + loaders[id] = jobs + } + + fun remove(id: UserWalletId) { + loaders[id]?.let { + it.forEach(Job::cancel) + loaders.remove(id) + } + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletScreenContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletScreenContentLoader.kt new file mode 100644 index 0000000000..24b6e550ed --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletScreenContentLoader.kt @@ -0,0 +1,91 @@ +package com.tangem.feature.wallet.presentation.wallet.loaders + +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import dagger.hilt.android.scopes.ViewModelScoped +import kotlinx.coroutines.CoroutineScope +import timber.log.Timber +import javax.inject.Inject + +/** + * Base wallet screen content loader. Use it to load content by [UserWallet]. + * + * @property factory factory that creates loader + * @property storage storage that save loader's jobs + * @property dispatchers coroutine dispatchers provider + * +[REDACTED_AUTHOR] + */ +@ViewModelScoped +internal class WalletScreenContentLoader @Inject constructor( + private val factory: WalletContentLoaderFactory, + private val storage: WalletLoaderStorage, + private val dispatchers: CoroutineDispatcherProvider, +) { + + /** + * Load content by [UserWallet] + * + * @param userWallet user wallet + * @param appCurrency app currency + * @param clickIntents click intents + * @param isRefresh flag that determinate if content must load again + * @param coroutineScope coroutine scope + */ + fun load( + userWallet: UserWallet, + appCurrency: AppCurrency, + clickIntents: WalletClickIntentsV2, + isRefresh: Boolean = false, + coroutineScope: CoroutineScope, + ) { + if (userWallet.isLocked) return + + val id = userWallet.walletId + if (!storage.contains(id)) { + loadInternal(userWallet, appCurrency, clickIntents, coroutineScope, isRefresh) + } else { + if (isRefresh) { + storage.remove(id) + loadInternal(userWallet, appCurrency, clickIntents, coroutineScope, true) + } else { + Timber.d("$id content loading has already started") + } + } + } + + /** Cancel loading by [id] */ + fun cancel(id: UserWalletId) { + Timber.d("$id content loading is canceled") + storage.remove(id) + } + + private fun loadInternal( + userWallet: UserWallet, + appCurrency: AppCurrency, + clickIntents: WalletClickIntentsV2, + coroutineScope: CoroutineScope, + isRefresh: Boolean, + ) { + val loader = factory.create( + userWallet = userWallet, + appCurrency = appCurrency, + clickIntents = clickIntents, + isRefresh = isRefresh, + ) + + if (loader == null) { + Timber.e("Impossible to create loader for $userWallet") + return + } + + Timber.d("${userWallet.walletId} content loading is ${if (isRefresh) "re" else ""}started") + + loader.subscribers + .map { it.subscribe(coroutineScope, dispatchers) } + .let { storage.set(userWallet.walletId, it) } + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoader.kt new file mode 100644 index 0000000000..6424208a3f --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoader.kt @@ -0,0 +1,46 @@ +package com.tangem.feature.wallet.presentation.wallet.loaders.implementors + +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.tokens.GetTokenListUseCase +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender +import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory +import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker +import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateHolderV2 +import com.tangem.feature.wallet.presentation.wallet.subscribers.MultiWalletWarningsSubscriber +import com.tangem.feature.wallet.presentation.wallet.subscribers.TokenListSubscriber +import com.tangem.feature.wallet.presentation.wallet.subscribers.WalletSubscriber +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 + +@Suppress("LongParameterList") +internal class MultiWalletContentLoader( + private val userWallet: UserWallet, + private val appCurrency: AppCurrency, + private val clickIntents: WalletClickIntentsV2, + private val stateHolder: WalletStateHolderV2, + private val tokenListAnalyticsSender: TokenListAnalyticsSender, + private val walletWithFundsChecker: WalletWithFundsChecker, + private val getTokenListUseCase: GetTokenListUseCase, + private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory, +) : WalletContentLoader(id = userWallet.walletId) { + + override fun create(): List> { + return listOf( + TokenListSubscriber( + userWallet = userWallet, + appCurrency = appCurrency, + stateHolder = stateHolder, + clickIntents = clickIntents, + tokenListAnalyticsSender = tokenListAnalyticsSender, + walletWithFundsChecker = walletWithFundsChecker, + getTokenListUseCase = getTokenListUseCase, + ), + MultiWalletWarningsSubscriber( + userWalletId = userWallet.walletId, + stateHolder = stateHolder, + clickIntents = clickIntents, + getMultiWalletWarningsFactory = getMultiWalletWarningsFactory, + ), + ) + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoaderFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoaderFactory.kt new file mode 100644 index 0000000000..1751d80a8b --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoaderFactory.kt @@ -0,0 +1,39 @@ +package com.tangem.feature.wallet.presentation.wallet.loaders.implementors + +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.tokens.GetTokenListUseCase +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender +import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory +import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker +import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateHolderV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import dagger.hilt.android.scopes.ViewModelScoped +import javax.inject.Inject + +@ViewModelScoped +internal class MultiWalletContentLoaderFactory @Inject constructor( + private val stateHolder: WalletStateHolderV2, + private val getTokenListUseCase: GetTokenListUseCase, + private val tokenListAnalyticsSender: TokenListAnalyticsSender, + private val walletWithFundsChecker: WalletWithFundsChecker, + private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory, +) { + + fun create( + userWallet: UserWallet, + appCurrency: AppCurrency, + clickIntents: WalletClickIntentsV2, + ): WalletContentLoader { + return MultiWalletContentLoader( + userWallet = userWallet, + appCurrency = appCurrency, + clickIntents = clickIntents, + stateHolder = stateHolder, + tokenListAnalyticsSender = tokenListAnalyticsSender, + walletWithFundsChecker = walletWithFundsChecker, + getTokenListUseCase = getTokenListUseCase, + getMultiWalletWarningsFactory = getMultiWalletWarningsFactory, + ) + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoader.kt new file mode 100644 index 0000000000..792c45ee35 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoader.kt @@ -0,0 +1,66 @@ +package com.tangem.feature.wallet.presentation.wallet.loaders.implementors + +import com.tangem.core.analytics.api.AnalyticsEventHandler +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.settings.SetWalletWithFundsFoundUseCase +import com.tangem.domain.tokens.GetCryptoCurrencyActionsUseCase +import com.tangem.domain.tokens.GetPrimaryCurrencyStatusUpdatesUseCase +import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase +import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsUseCase +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.feature.wallet.presentation.wallet.domain.GetSingleWalletWarningsFactory +import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateHolderV2 +import com.tangem.feature.wallet.presentation.wallet.subscribers.* +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 + +@Suppress("LongParameterList") +internal class SingleWalletContentLoader( + private val userWallet: UserWallet, + private val appCurrency: AppCurrency, + private val clickIntents: WalletClickIntentsV2, + private val isRefresh: Boolean, + private val stateHolder: WalletStateHolderV2, + private val getPrimaryCurrencyStatusUpdatesUseCase: GetPrimaryCurrencyStatusUpdatesUseCase, + private val getCryptoCurrencyActionsUseCase: GetCryptoCurrencyActionsUseCase, + private val getSingleWalletWarningsFactory: GetSingleWalletWarningsFactory, + private val setWalletWithFundsFoundUseCase: SetWalletWithFundsFoundUseCase, + private val txHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase, + private val txHistoryItemsUseCase: GetTxHistoryItemsUseCase, + private val analyticsEventHandler: AnalyticsEventHandler, +) : WalletContentLoader(id = userWallet.walletId) { + + override fun create(): List> { + return listOf( + PrimaryCurrencySubscriber( + userWallet = userWallet, + appCurrency = appCurrency, + stateHolder = stateHolder, + getPrimaryCurrencyStatusUpdatesUseCase = getPrimaryCurrencyStatusUpdatesUseCase, + setWalletWithFundsFoundUseCase = setWalletWithFundsFoundUseCase, + analyticsEventHandler = analyticsEventHandler, + ), + SingleWalletButtonsSubscriber( + userWallet = userWallet, + stateHolder = stateHolder, + clickIntents = clickIntents, + getPrimaryCurrencyStatusUpdatesUseCase = getPrimaryCurrencyStatusUpdatesUseCase, + getCryptoCurrencyActionsUseCase = getCryptoCurrencyActionsUseCase, + ), + SingleWalletNotificationsSubscriber( + userWalletId = userWallet.walletId, + stateHolder = stateHolder, + clickIntents = clickIntents, + getSingleWalletWarningsFactory = getSingleWalletWarningsFactory, + ), + TxHistorySubscriber( + userWallet = userWallet, + isRefresh = isRefresh, + stateHolder = stateHolder, + clickIntents = clickIntents, + getPrimaryCurrencyStatusUpdatesUseCase = getPrimaryCurrencyStatusUpdatesUseCase, + txHistoryItemsCountUseCase = txHistoryItemsCountUseCase, + txHistoryItemsUseCase = txHistoryItemsUseCase, + ), + ) + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoaderFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoaderFactory.kt new file mode 100644 index 0000000000..05eb03ee25 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoaderFactory.kt @@ -0,0 +1,51 @@ +package com.tangem.feature.wallet.presentation.wallet.loaders.implementors + +import com.tangem.core.analytics.api.AnalyticsEventHandler +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.settings.SetWalletWithFundsFoundUseCase +import com.tangem.domain.tokens.GetCryptoCurrencyActionsUseCase +import com.tangem.domain.tokens.GetPrimaryCurrencyStatusUpdatesUseCase +import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase +import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsUseCase +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.feature.wallet.presentation.wallet.domain.GetSingleWalletWarningsFactory +import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateHolderV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import dagger.hilt.android.scopes.ViewModelScoped +import javax.inject.Inject + +@ViewModelScoped +@Suppress("LongParameterList") +internal class SingleWalletContentLoaderFactory @Inject constructor( + private val stateHolder: WalletStateHolderV2, + private val getPrimaryCurrencyStatusUpdatesUseCase: GetPrimaryCurrencyStatusUpdatesUseCase, + private val getCryptoCurrencyActionsUseCase: GetCryptoCurrencyActionsUseCase, + private val getSingleWalletWarningsFactory: GetSingleWalletWarningsFactory, + private val setWalletWithFundsFoundUseCase: SetWalletWithFundsFoundUseCase, + private val txHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase, + private val txHistoryItemsUseCase: GetTxHistoryItemsUseCase, + private val analyticsEventHandler: AnalyticsEventHandler, +) { + + fun create( + userWallet: UserWallet, + appCurrency: AppCurrency, + clickIntents: WalletClickIntentsV2, + isRefresh: Boolean, + ): WalletContentLoader { + return SingleWalletContentLoader( + userWallet = userWallet, + appCurrency = appCurrency, + clickIntents = clickIntents, + isRefresh = isRefresh, + stateHolder = stateHolder, + getPrimaryCurrencyStatusUpdatesUseCase = getPrimaryCurrencyStatusUpdatesUseCase, + getCryptoCurrencyActionsUseCase = getCryptoCurrencyActionsUseCase, + getSingleWalletWarningsFactory = getSingleWalletWarningsFactory, + setWalletWithFundsFoundUseCase = setWalletWithFundsFoundUseCase, + txHistoryItemsCountUseCase = txHistoryItemsCountUseCase, + txHistoryItemsUseCase = txHistoryItemsUseCase, + analyticsEventHandler = analyticsEventHandler, + ) + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoader.kt new file mode 100644 index 0000000000..fd3242278a --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoader.kt @@ -0,0 +1,46 @@ +package com.tangem.feature.wallet.presentation.wallet.loaders.implementors + +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.tokens.GetCardTokensListUseCase +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender +import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory +import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker +import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateHolderV2 +import com.tangem.feature.wallet.presentation.wallet.subscribers.MultiWalletWarningsSubscriber +import com.tangem.feature.wallet.presentation.wallet.subscribers.SingleWalletWithTokenListSubscriber +import com.tangem.feature.wallet.presentation.wallet.subscribers.WalletSubscriber +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 + +@Suppress("LongParameterList") +internal class SingleWalletWithTokenContentLoader( + private val userWallet: UserWallet, + private val appCurrency: AppCurrency, + private val clickIntents: WalletClickIntentsV2, + private val stateHolder: WalletStateHolderV2, + private val tokenListAnalyticsSender: TokenListAnalyticsSender, + private val walletWithFundsChecker: WalletWithFundsChecker, + private val getCardTokensListUseCase: GetCardTokensListUseCase, + private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory, +) : WalletContentLoader(id = userWallet.walletId) { + + override fun create(): List> { + return listOf( + SingleWalletWithTokenListSubscriber( + userWallet = userWallet, + appCurrency = appCurrency, + stateHolder = stateHolder, + clickIntents = clickIntents, + tokenListAnalyticsSender = tokenListAnalyticsSender, + walletWithFundsChecker = walletWithFundsChecker, + getCardTokensListUseCase = getCardTokensListUseCase, + ), + MultiWalletWarningsSubscriber( + userWalletId = userWallet.walletId, + stateHolder = stateHolder, + clickIntents = clickIntents, + getMultiWalletWarningsFactory = getMultiWalletWarningsFactory, + ), + ) + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoaderFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoaderFactory.kt new file mode 100644 index 0000000000..efef9eeb8d --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoaderFactory.kt @@ -0,0 +1,37 @@ +package com.tangem.feature.wallet.presentation.wallet.loaders.implementors + +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.tokens.GetCardTokensListUseCase +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender +import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory +import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker +import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateHolderV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import javax.inject.Inject + +internal class SingleWalletWithTokenContentLoaderFactory @Inject constructor( + private val stateHolder: WalletStateHolderV2, + private val tokenListAnalyticsSender: TokenListAnalyticsSender, + private val walletWithFundsChecker: WalletWithFundsChecker, + private val getCardTokensListUseCase: GetCardTokensListUseCase, + private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory, +) { + + fun create( + userWallet: UserWallet, + appCurrency: AppCurrency, + clickIntents: WalletClickIntentsV2, + ): SingleWalletWithTokenContentLoader { + return SingleWalletWithTokenContentLoader( + userWallet = userWallet, + appCurrency = appCurrency, + clickIntents = clickIntents, + stateHolder = stateHolder, + tokenListAnalyticsSender = tokenListAnalyticsSender, + walletWithFundsChecker = walletWithFundsChecker, + getCardTokensListUseCase = getCardTokensListUseCase, + getMultiWalletWarningsFactory = getMultiWalletWarningsFactory, + ) + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/WalletContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/WalletContentLoader.kt new file mode 100644 index 0000000000..83f9c28342 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/WalletContentLoader.kt @@ -0,0 +1,19 @@ +package com.tangem.feature.wallet.presentation.wallet.loaders.implementors + +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.feature.wallet.presentation.wallet.subscribers.WalletSubscriber + +/** + * Wallet content loader + * + * @property id loader id + * +[REDACTED_AUTHOR] + */ +internal abstract class WalletContentLoader(val id: UserWalletId) { + + /** Loader's subscribers */ + val subscribers: List> get() = create() + + protected abstract fun create(): List> +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt index e7cc3d17a9..1bcff88b81 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt @@ -4,6 +4,7 @@ import com.tangem.core.navigation.AppScreen import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.DeleteWalletUseCase import com.tangem.domain.wallets.usecase.UpdateWalletUseCase +import com.tangem.feature.wallet.presentation.wallet.loaders.WalletScreenContentLoader import com.tangem.feature.wallet.presentation.wallet.state.WalletAlertState import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState @@ -27,7 +28,7 @@ internal interface WalletCardClickIntents { internal class WalletCardClickIntentsImplementor @Inject constructor( private val stateHolder: WalletStateHolderV2, private val walletEventSender: WalletEventSender, - // TODO: private val walletScreenContentLoader: WalletScreenContentLoader, + private val walletScreenContentLoader: WalletScreenContentLoader, private val updateWalletUseCase: UpdateWalletUseCase, private val deleteWalletUseCase: DeleteWalletUseCase, private val dispatchers: CoroutineDispatcherProvider, @@ -51,7 +52,7 @@ internal class WalletCardClickIntentsImplementor @Inject constructor( override fun onDeleteAfterConfirmationClick(userWalletId: UserWalletId) { viewModelScope.launch(dispatchers.main) { - // TODO: walletScreenContentLoader.cancel(userWalletId) + walletScreenContentLoader.cancel(userWalletId) deleteWalletUseCase(userWalletId) .onRight { popBackIfAllWalletsIsLocked() } .onLeft { Timber.e(it.toString()) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntentsV2.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntentsV2.kt index 643c5dec03..55e0a76bc5 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntentsV2.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntentsV2.kt @@ -1,6 +1,7 @@ package com.tangem.feature.wallet.presentation.wallet.viewmodels.intents import com.tangem.core.analytics.api.AnalyticsEventHandler +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.settings.NeverToShowWalletsScrollPreview import com.tangem.domain.tokens.FetchCardTokenListUseCase @@ -11,29 +12,29 @@ import com.tangem.domain.wallets.usecase.SelectWalletUseCase import com.tangem.feature.wallet.presentation.router.InnerWalletRouter import com.tangem.feature.wallet.presentation.wallet.analytics.PortfolioEvent import com.tangem.feature.wallet.presentation.wallet.domain.unwrap +import com.tangem.feature.wallet.presentation.wallet.loaders.WalletScreenContentLoader import com.tangem.feature.wallet.presentation.wallet.state2.WalletState import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateHolderV2 import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetRefreshStateTransformer import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTokenListErrorTransformer import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import javax.inject.Inject -/** -[REDACTED_AUTHOR] - */ @Suppress("LongParameterList") +@ViewModelScoped internal class WalletClickIntentsV2 @Inject constructor( private val walletCardClickIntentsImplementor: WalletCardClickIntentsImplementor, private val warningsClickIntentsImplementer: WalletWarningsClickIntentsImplementer, private val currencyActionsClickIntentsImplementor: WalletCurrencyActionsClickIntentsImplementor, private val contentClickIntentsImplementor: WalletContentClickIntentsImplementor, private val stateHolder: WalletStateHolderV2, - // TODO: private val walletScreenContentLoader: WalletScreenContentLoader, + private val walletScreenContentLoader: WalletScreenContentLoader, private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, private val selectWalletUseCase: SelectWalletUseCase, - // TODO: private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val fetchTokenListUseCase: FetchTokenListUseCase, private val fetchCardTokenListUseCase: FetchCardTokenListUseCase, private val fetchCurrencyStatusUseCase: FetchCurrencyStatusUseCase, @@ -66,13 +67,12 @@ internal class WalletClickIntentsV2 @Inject constructor( stateHolder.update { it.copy(selectedWalletIndex = index) } maybeUserWallet.onRight { - // TODO: - // walletScreenContentLoader.load( - // userWallet = it, - // appCurrency = getSelectedAppCurrencyUseCase.unwrap(), - // clickIntents = this@WalletClickIntentsV2, - // coroutineScope = viewModelScope, - // ) + walletScreenContentLoader.load( + userWallet = it, + appCurrency = getSelectedAppCurrencyUseCase.unwrap(), + clickIntents = this@WalletClickIntentsV2, + coroutineScope = viewModelScope, + ) } } } @@ -133,14 +133,13 @@ internal class WalletClickIntentsV2 @Inject constructor( viewModelScope.launch(dispatchers.main) { fetchCurrencyStatusUseCase(userWallet.walletId, refresh = true) - // TODO: - // walletScreenContentLoader.load( - // userWallet = userWallet, - // appCurrency = getSelectedAppCurrencyUseCase.unwrap(), - // clickIntents = this@WalletClickIntentsV2, - // coroutineScope = viewModelScope, - // isRefresh = true, - // ) + walletScreenContentLoader.load( + userWallet = userWallet, + appCurrency = getSelectedAppCurrencyUseCase.unwrap(), + clickIntents = this@WalletClickIntentsV2, + coroutineScope = viewModelScope, + isRefresh = true, + ) stateHolder.update( SetRefreshStateTransformer(userWalletId = userWallet.walletId, isRefreshing = false), diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletContentClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletContentClickIntents.kt index 82c943e41b..a3582c6e63 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletContentClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletContentClickIntents.kt @@ -19,6 +19,7 @@ import com.tangem.feature.wallet.presentation.wallet.state2.transformers.CloseBo import com.tangem.feature.wallet.presentation.wallet.state2.transformers.OpenBottomSheetTransformer import com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter.MultiWalletCurrencyActionsConverter import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.take import kotlinx.coroutines.launch @@ -42,6 +43,7 @@ internal interface WalletContentClickIntents { } @Suppress("LongParameterList") +@ViewModelScoped internal class WalletContentClickIntentsImplementor @Inject constructor( private val stateHolder: WalletStateHolderV2, private val currencyActionsClickIntentsImplementor: WalletCurrencyActionsClickIntentsImplementor, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt index 0b6070971a..9690fa7684 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt @@ -37,6 +37,7 @@ import com.tangem.feature.wallet.presentation.wallet.state2.transformers.CloseBo import com.tangem.feature.wallet.presentation.wallet.state2.transformers.OpenBottomSheetTransformer import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletEventSender import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.take @@ -65,6 +66,7 @@ interface WalletCurrencyActionsClickIntents { } @Suppress("LongParameterList", "LargeClass") +@ViewModelScoped internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( private val stateHolder: WalletStateHolderV2, private val walletEventSender: WalletEventSender, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt index b4b9b2d06f..cfa8be01ab 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt @@ -38,6 +38,7 @@ import com.tangem.feature.wallet.presentation.wallet.state2.transformers.OpenBot import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletEventSender import com.tangem.operations.derivation.ExtendedPublicKeysMap import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.coroutines.launch import javax.inject.Inject @@ -63,6 +64,7 @@ internal interface WalletWarningsClickIntents { } @Suppress("LongParameterList") +@ViewModelScoped internal class WalletWarningsClickIntentsImplementer @Inject constructor( private val stateHolder: WalletStateHolderV2, private val walletEventSender: WalletEventSender,