From 9a9c365735ff2151176fb66f376c09f5b436c577 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 14 Dec 2023 11:27:51 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../loaders/WalletContentLoaderFactory.kt | 12 +++---- .../loaders/WalletScreenContentLoader.kt | 9 ++--- .../implementors/MultiWalletContentLoader.kt | 8 ++--- .../MultiWalletContentLoaderFactory.kt | 14 ++++---- .../implementors/SingleWalletContentLoader.kt | 6 ++-- .../SingleWalletContentLoaderFactory.kt | 12 +++---- .../SingleWalletWithTokenContentLoader.kt | 8 ++--- ...ngleWalletWithTokenContentLoaderFactory.kt | 15 ++++---- .../implementors/VisaWalletContentLoader.kt | 6 ++-- .../VisaWalletContentLoaderFactory.kt | 30 +++++++--------- .../subscribers/PrimaryCurrencySubscriber.kt | 33 +++++++++++------- .../SingleWalletWithTokenListSubscriber.kt | 34 ++++++++++++------- .../wallet/subscribers/TokenListSubscriber.kt | 34 ++++++++++++------- .../wallet/viewmodels/WalletViewModelV2.kt | 26 +------------- .../intents/WalletClickIntentsV2.kt | 6 +--- 15 files changed, 113 insertions(+), 140 deletions(-) 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 index ca2acfa827..224cd27c24 100644 --- 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 @@ -1,6 +1,5 @@ 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.* @@ -18,22 +17,19 @@ internal class WalletContentLoaderFactory @Inject constructor( fun create( userWallet: UserWallet, - appCurrency: AppCurrency, clickIntents: WalletClickIntentsV2, isRefresh: Boolean = false, ): WalletContentLoader? { return when { - userWallet.isMultiCurrency -> { - multiWalletContentLoaderFactory.create(userWallet, appCurrency, clickIntents) - } + userWallet.isMultiCurrency -> multiWalletContentLoaderFactory.create(userWallet, clickIntents) userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken() -> { - singleWalletWithTokenContentLoaderFactory.create(userWallet, appCurrency, clickIntents) + singleWalletWithTokenContentLoaderFactory.create(userWallet, clickIntents) } userWallet.scanResponse.cardTypesResolver.isVisaWallet() -> { - visaWalletContentLoaderFactory.create(userWallet, appCurrency, clickIntents, isRefresh) + visaWalletContentLoaderFactory.create(userWallet, clickIntents, isRefresh) } !userWallet.isMultiCurrency -> { - singleWalletContentLoaderFactory.create(userWallet, appCurrency, clickIntents, isRefresh) + singleWalletContentLoaderFactory.create(userWallet, clickIntents, isRefresh) } else -> null } 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 index 96d4175d6b..27ad8b60f5 100644 --- 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 @@ -1,6 +1,5 @@ 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 @@ -30,14 +29,12 @@ internal class WalletScreenContentLoader @Inject constructor( * 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, @@ -46,11 +43,11 @@ internal class WalletScreenContentLoader @Inject constructor( val id = userWallet.walletId if (!storage.contains(id)) { - loadInternal(userWallet, appCurrency, clickIntents, coroutineScope, isRefresh) + loadInternal(userWallet, clickIntents, coroutineScope, isRefresh) } else { if (isRefresh) { storage.remove(id) - loadInternal(userWallet, appCurrency, clickIntents, coroutineScope, true) + loadInternal(userWallet, clickIntents, coroutineScope, true) } else { Timber.d("$id content loading has already started") } @@ -70,14 +67,12 @@ internal class WalletScreenContentLoader @Inject constructor( 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, ) 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 index 7f988fc301..28cc709d13 100644 --- 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 @@ -1,6 +1,6 @@ package com.tangem.feature.wallet.presentation.wallet.loaders.implementors -import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.redux.ReduxStateHolder import com.tangem.domain.tokens.GetTokenListUseCase import com.tangem.domain.wallets.models.UserWallet @@ -17,12 +17,12 @@ import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletCl @Suppress("LongParameterList") internal class MultiWalletContentLoader( private val userWallet: UserWallet, - private val appCurrency: AppCurrency, - private val clickIntents: WalletClickIntentsV2, private val stateHolder: WalletStateController, + private val clickIntents: WalletClickIntentsV2, private val tokenListAnalyticsSender: TokenListAnalyticsSender, private val walletWithFundsChecker: WalletWithFundsChecker, private val getTokenListUseCase: GetTokenListUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory, private val reduxStateHolder: ReduxStateHolder, ) : WalletContentLoader(id = userWallet.walletId) { @@ -31,12 +31,12 @@ internal class MultiWalletContentLoader( return listOf( TokenListSubscriber( userWallet = userWallet, - appCurrency = appCurrency, stateHolder = stateHolder, clickIntents = clickIntents, tokenListAnalyticsSender = tokenListAnalyticsSender, walletWithFundsChecker = walletWithFundsChecker, getTokenListUseCase = getTokenListUseCase, + getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase, ), MultiWalletWarningsSubscriber( userWalletId = userWallet.walletId, 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 index 199162d4ed..570fb98420 100644 --- 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 @@ -1,6 +1,6 @@ package com.tangem.feature.wallet.presentation.wallet.loaders.implementors -import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.redux.ReduxStateHolder import com.tangem.domain.tokens.GetTokenListUseCase import com.tangem.domain.wallets.models.UserWallet @@ -12,29 +12,27 @@ import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletCl import dagger.hilt.android.scopes.ViewModelScoped import javax.inject.Inject +@Suppress("LongParameterList") @ViewModelScoped internal class MultiWalletContentLoaderFactory @Inject constructor( private val stateHolder: WalletStateController, - private val getTokenListUseCase: GetTokenListUseCase, private val tokenListAnalyticsSender: TokenListAnalyticsSender, private val walletWithFundsChecker: WalletWithFundsChecker, private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory, + private val getTokenListUseCase: GetTokenListUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val reduxStateHolder: ReduxStateHolder, ) { - fun create( - userWallet: UserWallet, - appCurrency: AppCurrency, - clickIntents: WalletClickIntentsV2, - ): WalletContentLoader { + fun create(userWallet: UserWallet, clickIntents: WalletClickIntentsV2): WalletContentLoader { return MultiWalletContentLoader( userWallet = userWallet, - appCurrency = appCurrency, clickIntents = clickIntents, stateHolder = stateHolder, tokenListAnalyticsSender = tokenListAnalyticsSender, walletWithFundsChecker = walletWithFundsChecker, getTokenListUseCase = getTokenListUseCase, + getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase, getMultiWalletWarningsFactory = getMultiWalletWarningsFactory, reduxStateHolder = reduxStateHolder, ) 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 index c35105c56b..5d1471cdc1 100644 --- 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 @@ -1,7 +1,7 @@ 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.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.settings.SetWalletWithFundsFoundUseCase import com.tangem.domain.tokens.GetCryptoCurrencyActionsUseCase import com.tangem.domain.tokens.GetPrimaryCurrencyStatusUpdatesUseCase @@ -16,7 +16,6 @@ import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletCl @Suppress("LongParameterList") internal class SingleWalletContentLoader( private val userWallet: UserWallet, - private val appCurrency: AppCurrency, private val clickIntents: WalletClickIntentsV2, private val isRefresh: Boolean, private val stateHolder: WalletStateController, @@ -26,6 +25,7 @@ internal class SingleWalletContentLoader( private val setWalletWithFundsFoundUseCase: SetWalletWithFundsFoundUseCase, private val txHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase, private val txHistoryItemsUseCase: GetTxHistoryItemsUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val analyticsEventHandler: AnalyticsEventHandler, ) : WalletContentLoader(id = userWallet.walletId) { @@ -33,10 +33,10 @@ internal class SingleWalletContentLoader( return listOf( PrimaryCurrencySubscriber( userWallet = userWallet, - appCurrency = appCurrency, stateHolder = stateHolder, getPrimaryCurrencyStatusUpdatesUseCase = getPrimaryCurrencyStatusUpdatesUseCase, setWalletWithFundsFoundUseCase = setWalletWithFundsFoundUseCase, + getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase, analyticsEventHandler = analyticsEventHandler, ), SingleWalletButtonsSubscriber( 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 index d9565ba647..a22dcd9604 100644 --- 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 @@ -1,7 +1,7 @@ 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.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.settings.SetWalletWithFundsFoundUseCase import com.tangem.domain.tokens.GetCryptoCurrencyActionsUseCase import com.tangem.domain.tokens.GetPrimaryCurrencyStatusUpdatesUseCase @@ -24,18 +24,13 @@ internal class SingleWalletContentLoaderFactory @Inject constructor( private val setWalletWithFundsFoundUseCase: SetWalletWithFundsFoundUseCase, private val txHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase, private val txHistoryItemsUseCase: GetTxHistoryItemsUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val analyticsEventHandler: AnalyticsEventHandler, ) { - fun create( - userWallet: UserWallet, - appCurrency: AppCurrency, - clickIntents: WalletClickIntentsV2, - isRefresh: Boolean, - ): WalletContentLoader { + fun create(userWallet: UserWallet, clickIntents: WalletClickIntentsV2, isRefresh: Boolean): WalletContentLoader { return SingleWalletContentLoader( userWallet = userWallet, - appCurrency = appCurrency, clickIntents = clickIntents, isRefresh = isRefresh, stateHolder = stateHolder, @@ -45,6 +40,7 @@ internal class SingleWalletContentLoaderFactory @Inject constructor( setWalletWithFundsFoundUseCase = setWalletWithFundsFoundUseCase, txHistoryItemsCountUseCase = txHistoryItemsCountUseCase, txHistoryItemsUseCase = txHistoryItemsUseCase, + getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase, analyticsEventHandler = analyticsEventHandler, ) } 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 index 9f44f3b2c0..4fbec78665 100644 --- 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 @@ -1,6 +1,6 @@ package com.tangem.feature.wallet.presentation.wallet.loaders.implementors -import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.tokens.GetCardTokensListUseCase import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender @@ -15,25 +15,25 @@ import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletCl @Suppress("LongParameterList") internal class SingleWalletWithTokenContentLoader( private val userWallet: UserWallet, - private val appCurrency: AppCurrency, private val clickIntents: WalletClickIntentsV2, private val stateHolder: WalletStateController, private val tokenListAnalyticsSender: TokenListAnalyticsSender, private val walletWithFundsChecker: WalletWithFundsChecker, - private val getCardTokensListUseCase: GetCardTokensListUseCase, private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory, + private val getCardTokensListUseCase: GetCardTokensListUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, ) : 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, + getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase, ), MultiWalletWarningsSubscriber( userWalletId = userWallet.walletId, 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 index 39db71a2d8..232bd81fb1 100644 --- 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 @@ -1,6 +1,6 @@ package com.tangem.feature.wallet.presentation.wallet.loaders.implementors -import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.tokens.GetCardTokensListUseCase import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender @@ -14,24 +14,21 @@ internal class SingleWalletWithTokenContentLoaderFactory @Inject constructor( private val stateHolder: WalletStateController, private val tokenListAnalyticsSender: TokenListAnalyticsSender, private val walletWithFundsChecker: WalletWithFundsChecker, - private val getCardTokensListUseCase: GetCardTokensListUseCase, private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory, + private val getCardTokensListUseCase: GetCardTokensListUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, ) { - fun create( - userWallet: UserWallet, - appCurrency: AppCurrency, - clickIntents: WalletClickIntentsV2, - ): SingleWalletWithTokenContentLoader { + fun create(userWallet: UserWallet, clickIntents: WalletClickIntentsV2): SingleWalletWithTokenContentLoader { return SingleWalletWithTokenContentLoader( userWallet = userWallet, - appCurrency = appCurrency, clickIntents = clickIntents, stateHolder = stateHolder, tokenListAnalyticsSender = tokenListAnalyticsSender, walletWithFundsChecker = walletWithFundsChecker, - getCardTokensListUseCase = getCardTokensListUseCase, getMultiWalletWarningsFactory = getMultiWalletWarningsFactory, + getCardTokensListUseCase = getCardTokensListUseCase, + getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase, ) } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoader.kt index de0d49830b..8a221a2d24 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoader.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoader.kt @@ -1,7 +1,7 @@ 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.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.settings.SetWalletWithFundsFoundUseCase import com.tangem.domain.tokens.GetPrimaryCurrencyStatusUpdatesUseCase import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase @@ -17,7 +17,6 @@ import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletCl @Suppress("LongParameterList") internal class VisaWalletContentLoader( private val userWallet: UserWallet, - private val appCurrency: AppCurrency, private val clickIntents: WalletClickIntentsV2, private val isRefresh: Boolean, private val stateHolder: WalletStateController, @@ -25,6 +24,7 @@ internal class VisaWalletContentLoader( private val setWalletWithFundsFoundUseCase: SetWalletWithFundsFoundUseCase, private val txHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase, private val txHistoryItemsUseCase: GetTxHistoryItemsUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val analyticsEventHandler: AnalyticsEventHandler, ) : WalletContentLoader(id = userWallet.walletId) { @@ -32,11 +32,11 @@ internal class VisaWalletContentLoader( return listOf( PrimaryCurrencySubscriber( userWallet = userWallet, - appCurrency = appCurrency, stateHolder = stateHolder, getPrimaryCurrencyStatusUpdatesUseCase = getPrimaryCurrencyStatusUpdatesUseCase, setWalletWithFundsFoundUseCase = setWalletWithFundsFoundUseCase, analyticsEventHandler = analyticsEventHandler, + getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase, ), VisaWalletBalancesAndLimitsSubscriber(userWallet, stateHolder, clickIntents), TxHistorySubscriber( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoaderFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoaderFactory.kt index e7f547ddfe..61db482fa2 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoaderFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoaderFactory.kt @@ -1,7 +1,7 @@ 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.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.settings.SetWalletWithFundsFoundUseCase import com.tangem.domain.tokens.GetPrimaryCurrencyStatusUpdatesUseCase import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase @@ -20,26 +20,22 @@ internal class VisaWalletContentLoaderFactory @Inject constructor( private val setWalletWithFundsFoundUseCase: SetWalletWithFundsFoundUseCase, private val txHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase, private val txHistoryItemsUseCase: GetTxHistoryItemsUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val analyticsEventHandler: AnalyticsEventHandler, ) { - fun create( - userWallet: UserWallet, - appCurrency: AppCurrency, - clickIntents: WalletClickIntentsV2, - isRefresh: Boolean, - ): WalletContentLoader { + fun create(userWallet: UserWallet, clickIntents: WalletClickIntentsV2, isRefresh: Boolean): WalletContentLoader { return VisaWalletContentLoader( - userWallet, - appCurrency, - clickIntents, - isRefresh, - stateHolder, - getPrimaryCurrencyStatusUpdatesUseCase, - setWalletWithFundsFoundUseCase, - txHistoryItemsCountUseCase, - txHistoryItemsUseCase, - analyticsEventHandler, + userWallet = userWallet, + clickIntents = clickIntents, + isRefresh = isRefresh, + stateHolder = stateHolder, + getPrimaryCurrencyStatusUpdatesUseCase = getPrimaryCurrencyStatusUpdatesUseCase, + setWalletWithFundsFoundUseCase = setWalletWithFundsFoundUseCase, + txHistoryItemsCountUseCase = txHistoryItemsCountUseCase, + txHistoryItemsUseCase = txHistoryItemsUseCase, + getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase, + analyticsEventHandler = analyticsEventHandler, ) } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/PrimaryCurrencySubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/PrimaryCurrencySubscriber.kt index 10ca93bc2b..5a44bc2911 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/PrimaryCurrencySubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/PrimaryCurrencySubscriber.kt @@ -5,6 +5,7 @@ import arrow.core.getOrElse import com.tangem.common.extensions.isZero import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.analytics.models.AnalyticsParam +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.settings.SetWalletWithFundsFoundUseCase import com.tangem.domain.tokens.GetPrimaryCurrencyStatusUpdatesUseCase @@ -15,39 +16,45 @@ import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnaly import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetPrimaryCurrencyTransformer import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.conflate -import kotlinx.coroutines.flow.distinctUntilChanged -import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.* import timber.log.Timber import java.math.BigDecimal internal class PrimaryCurrencySubscriber( private val userWallet: UserWallet, - private val appCurrency: AppCurrency, private val stateHolder: WalletStateController, private val getPrimaryCurrencyStatusUpdatesUseCase: GetPrimaryCurrencyStatusUpdatesUseCase, private val setWalletWithFundsFoundUseCase: SetWalletWithFundsFoundUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val analyticsEventHandler: AnalyticsEventHandler, ) : WalletSubscriber() { - override fun create(coroutineScope: CoroutineScope): Flow> { - return getPrimaryCurrencyStatusUpdatesUseCase(userWallet.walletId) - .conflate() - .distinctUntilChanged() - .onEach { maybeCurrencyStatus -> - val status = maybeCurrencyStatus.getOrElse { + override fun create( + coroutineScope: CoroutineScope, + ): Flow, AppCurrency>> { + return combine( + flow = getPrimaryCurrencyStatusUpdatesUseCase(userWallet.walletId) + .conflate() + .distinctUntilChanged(), + flow2 = getSelectedAppCurrencyUseCase() + .conflate() + .distinctUntilChanged() + .map { maybeAppCurrency -> maybeAppCurrency.getOrElse { AppCurrency.Default } }, + transform = { maybeCurrencyStatus, appCurrency -> maybeCurrencyStatus to appCurrency }, + ) + .onEach { maybeCurrencyStatusAndAppCurrency -> + val status = maybeCurrencyStatusAndAppCurrency.first.getOrElse { Timber.e("Unable to get primary currency status: $it") return@onEach } - updateContent(status) + updateContent(status, maybeCurrencyStatusAndAppCurrency.second) sendAnalyticsEvent(status) checkWalletWithFunds(status) } } - private fun updateContent(status: CryptoCurrencyStatus) { + private fun updateContent(status: CryptoCurrencyStatus, appCurrency: AppCurrency) { stateHolder.update( SetPrimaryCurrencyTransformer( status = status, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletWithTokenListSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletWithTokenListSubscriber.kt index 705c4fbaf9..8496a45e8c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletWithTokenListSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletWithTokenListSubscriber.kt @@ -1,6 +1,8 @@ package com.tangem.feature.wallet.presentation.wallet.subscribers import arrow.core.Either +import arrow.core.getOrElse +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.tokens.GetCardTokensListUseCase import com.tangem.domain.tokens.error.TokenListError @@ -13,32 +15,38 @@ import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetToke import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTokenListTransformer import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.conflate -import kotlinx.coroutines.flow.distinctUntilChanged -import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.* @Suppress("LongParameterList") internal class SingleWalletWithTokenListSubscriber( private val userWallet: UserWallet, - private val appCurrency: AppCurrency, private val stateHolder: WalletStateController, private val clickIntents: WalletClickIntentsV2, private val tokenListAnalyticsSender: TokenListAnalyticsSender, private val walletWithFundsChecker: WalletWithFundsChecker, private val getCardTokensListUseCase: GetCardTokensListUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, ) : WalletSubscriber() { - override fun create(coroutineScope: CoroutineScope): Flow> { - return getCardTokensListUseCase(userWalletId = userWallet.walletId) - .conflate() - .distinctUntilChanged() - .onEach(::updateContent) - .onEach { tokenListAnalyticsSender.send(userWallet, maybeTokenList = it) } - .onEach(walletWithFundsChecker::check) + override fun create(coroutineScope: CoroutineScope): Flow, AppCurrency>> { + return combine( + flow = getCardTokensListUseCase(userWalletId = userWallet.walletId) + .conflate() + .distinctUntilChanged(), + flow2 = getSelectedAppCurrencyUseCase() + .conflate() + .distinctUntilChanged() + .map { maybeAppCurrency -> maybeAppCurrency.getOrElse { AppCurrency.Default } }, + transform = { tokenList, appCurrency -> tokenList to appCurrency }, + ) + .onEach { (maybeTokenList, appCurrency) -> + updateContent(maybeTokenList, appCurrency) + tokenListAnalyticsSender.send(userWallet, maybeTokenList) + walletWithFundsChecker.check(maybeTokenList) + } } - private fun updateContent(maybeTokenList: Either) { + private fun updateContent(maybeTokenList: Either, appCurrency: AppCurrency) { stateHolder.update( maybeTokenList.fold( ifLeft = { SetTokenListErrorTransformer(userWalletId = userWallet.walletId, error = it) }, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TokenListSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TokenListSubscriber.kt index 26ba23fe26..38ec1fa7df 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TokenListSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TokenListSubscriber.kt @@ -1,6 +1,8 @@ package com.tangem.feature.wallet.presentation.wallet.subscribers import arrow.core.Either +import arrow.core.getOrElse +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.tokens.GetTokenListUseCase import com.tangem.domain.tokens.error.TokenListError @@ -13,34 +15,40 @@ import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetToke import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTokenListTransformer import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.conflate -import kotlinx.coroutines.flow.distinctUntilChanged -import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.* typealias MaybeTokenListFlow = Flow> @Suppress("LongParameterList") internal class TokenListSubscriber( private val userWallet: UserWallet, - private val appCurrency: AppCurrency, private val stateHolder: WalletStateController, private val clickIntents: WalletClickIntentsV2, private val tokenListAnalyticsSender: TokenListAnalyticsSender, private val walletWithFundsChecker: WalletWithFundsChecker, private val getTokenListUseCase: GetTokenListUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, ) : WalletSubscriber() { - override fun create(coroutineScope: CoroutineScope): Flow> { - return getTokenListUseCase(userWalletId = userWallet.walletId) - .conflate() - .distinctUntilChanged() - .onEach(::updateContent) - .onEach { tokenListAnalyticsSender.send(userWallet, maybeTokenList = it) } - .onEach(walletWithFundsChecker::check) + override fun create(coroutineScope: CoroutineScope): Flow, AppCurrency>> { + return combine( + flow = getTokenListUseCase(userWalletId = userWallet.walletId) + .conflate() + .distinctUntilChanged(), + flow2 = getSelectedAppCurrencyUseCase() + .conflate() + .distinctUntilChanged() + .map { maybeAppCurrency -> maybeAppCurrency.getOrElse { AppCurrency.Default } }, + transform = { tokenList, appCurrency -> tokenList to appCurrency }, + ) + .onEach { (maybeTokenList, appCurrency) -> + updateContent(maybeTokenList, appCurrency) + tokenListAnalyticsSender.send(userWallet, maybeTokenList) + walletWithFundsChecker.check(maybeTokenList) + } } - private fun updateContent(maybeTokenList: Either) { + private fun updateContent(maybeTokenList: Either, appCurrency: AppCurrency) { stateHolder.update( maybeTokenList.fold( ifLeft = { SetTokenListErrorTransformer(userWalletId = userWallet.walletId, error = it) }, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModelV2.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModelV2.kt index 998d145ac0..c9e4978821 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModelV2.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModelV2.kt @@ -2,10 +2,7 @@ package com.tangem.feature.wallet.presentation.wallet.viewmodels import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import arrow.core.getOrElse import com.tangem.core.analytics.api.AnalyticsEventHandler -import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase -import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase import com.tangem.domain.redux.ReduxStateHolder import com.tangem.domain.settings.CanUseBiometryUseCase @@ -51,7 +48,6 @@ internal class WalletViewModelV2 @Inject constructor( private val shouldShowSaveWalletScreenUseCase: ShouldShowSaveWalletScreenUseCase, private val canUseBiometryUseCase: CanUseBiometryUseCase, private val shouldSaveUserWalletsUseCase: ShouldSaveUserWalletsUseCase, - private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val isWalletsScrollPreviewEnabled: IsWalletsScrollPreviewEnabled, private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, analyticsEventsHandler: AnalyticsEventHandler, @@ -61,8 +57,6 @@ internal class WalletViewModelV2 @Inject constructor( val uiState: StateFlow = stateHolder.uiState - private val selectedAppCurrencyFlow = createSelectedAppCurrencyFlow() - private var router: InnerWalletRouter by Delegates.notNull() private var walletsUpdateJobHolder: JobHolder = JobHolder() @@ -165,10 +159,9 @@ internal class WalletViewModelV2 @Inject constructor( is WalletsUpdateActionResolverV2.Action.ReinitializeWallets -> { walletScreenContentLoader.load( userWallet = action.selectedWallet, - appCurrency = selectedAppCurrencyFlow.value, clickIntents = clickIntents, - coroutineScope = viewModelScope, isRefresh = true, + coroutineScope = viewModelScope, ) } is WalletsUpdateActionResolverV2.Action.ReinitializeWallet -> reinitializeWallet(action) @@ -188,7 +181,6 @@ internal class WalletViewModelV2 @Inject constructor( private fun initializeWallets(action: WalletsUpdateActionResolverV2.Action.InitializeWallets) { walletScreenContentLoader.load( userWallet = action.selectedWallet, - appCurrency = selectedAppCurrencyFlow.value, clickIntents = clickIntents, coroutineScope = viewModelScope, ) @@ -227,7 +219,6 @@ internal class WalletViewModelV2 @Inject constructor( walletScreenContentLoader.load( userWallet = action.selectedWallet, - appCurrency = selectedAppCurrencyFlow.value, clickIntents = clickIntents, coroutineScope = viewModelScope, ) @@ -249,7 +240,6 @@ internal class WalletViewModelV2 @Inject constructor( walletScreenContentLoader.load( userWallet = action.selectedWallet, - appCurrency = selectedAppCurrencyFlow.value, clickIntents = clickIntents, coroutineScope = viewModelScope, ) @@ -264,7 +254,6 @@ internal class WalletViewModelV2 @Inject constructor( viewModelScope.launch(dispatchers.main) { walletScreenContentLoader.load( userWallet = action.selectedWallet, - appCurrency = selectedAppCurrencyFlow.value, clickIntents = clickIntents, coroutineScope = viewModelScope, ) @@ -295,7 +284,6 @@ internal class WalletViewModelV2 @Inject constructor( walletScreenContentLoader.load( userWallet = action.selectedWallet, - appCurrency = selectedAppCurrencyFlow.value, clickIntents = clickIntents, coroutineScope = viewModelScope, ) @@ -311,16 +299,4 @@ internal class WalletViewModelV2 @Inject constructor( ), ) } - - private fun createSelectedAppCurrencyFlow(): StateFlow { - return getSelectedAppCurrencyUseCase() - .map { maybeAppCurrency -> - maybeAppCurrency.getOrElse { AppCurrency.Default } - } - .stateIn( - scope = viewModelScope, - started = SharingStarted.Eagerly, - initialValue = AppCurrency.Default, - ) - } } \ No newline at end of file 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 f6f2ce1e0f..19c3f6130f 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,7 +1,6 @@ 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 @@ -35,7 +34,6 @@ internal class WalletClickIntentsV2 @Inject constructor( private val walletScreenContentLoader: WalletScreenContentLoader, private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, private val selectWalletUseCase: SelectWalletUseCase, - private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val fetchTokenListUseCase: FetchTokenListUseCase, private val fetchCardTokenListUseCase: FetchCardTokenListUseCase, private val fetchCurrencyStatusUseCase: FetchCurrencyStatusUseCase, @@ -72,7 +70,6 @@ internal class WalletClickIntentsV2 @Inject constructor( maybeUserWallet.onRight { walletScreenContentLoader.load( userWallet = it, - appCurrency = getSelectedAppCurrencyUseCase.unwrap(), clickIntents = this@WalletClickIntentsV2, coroutineScope = viewModelScope, ) @@ -141,10 +138,9 @@ internal class WalletClickIntentsV2 @Inject constructor( walletScreenContentLoader.load( userWallet = userWallet, - appCurrency = getSelectedAppCurrencyUseCase.unwrap(), clickIntents = this@WalletClickIntentsV2, - coroutineScope = viewModelScope, isRefresh = true, + coroutineScope = viewModelScope, ) stateHolder.update(