Updated on 2026-08-14
This commit is contained in:
parent
723f56e5ff
commit
9a9c365735
15 changed files with 113 additions and 140 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<WalletSubscriber> {
|
||||
return listOf(
|
||||
SingleWalletWithTokenListSubscriber(
|
||||
userWallet = userWallet,
|
||||
appCurrency = appCurrency,
|
||||
stateHolder = stateHolder,
|
||||
clickIntents = clickIntents,
|
||||
tokenListAnalyticsSender = tokenListAnalyticsSender,
|
||||
walletWithFundsChecker = walletWithFundsChecker,
|
||||
getCardTokensListUseCase = getCardTokensListUseCase,
|
||||
getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase,
|
||||
),
|
||||
MultiWalletWarningsSubscriber(
|
||||
userWalletId = userWallet.walletId,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Either<CurrencyStatusError, CryptoCurrencyStatus>> {
|
||||
return getPrimaryCurrencyStatusUpdatesUseCase(userWallet.walletId)
|
||||
.conflate()
|
||||
.distinctUntilChanged()
|
||||
.onEach { maybeCurrencyStatus ->
|
||||
val status = maybeCurrencyStatus.getOrElse {
|
||||
override fun create(
|
||||
coroutineScope: CoroutineScope,
|
||||
): Flow<Pair<Either<CurrencyStatusError, CryptoCurrencyStatus>, 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,
|
||||
|
|
|
|||
|
|
@ -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<Either<TokenListError, TokenList>> {
|
||||
return getCardTokensListUseCase(userWalletId = userWallet.walletId)
|
||||
.conflate()
|
||||
.distinctUntilChanged()
|
||||
.onEach(::updateContent)
|
||||
.onEach { tokenListAnalyticsSender.send(userWallet, maybeTokenList = it) }
|
||||
.onEach(walletWithFundsChecker::check)
|
||||
override fun create(coroutineScope: CoroutineScope): Flow<Pair<Either<TokenListError, TokenList>, 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<TokenListError, TokenList>) {
|
||||
private fun updateContent(maybeTokenList: Either<TokenListError, TokenList>, appCurrency: AppCurrency) {
|
||||
stateHolder.update(
|
||||
maybeTokenList.fold(
|
||||
ifLeft = { SetTokenListErrorTransformer(userWalletId = userWallet.walletId, error = it) },
|
||||
|
|
|
|||
|
|
@ -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<Either<TokenListError, TokenList>>
|
||||
|
||||
@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<Either<TokenListError, TokenList>> {
|
||||
return getTokenListUseCase(userWalletId = userWallet.walletId)
|
||||
.conflate()
|
||||
.distinctUntilChanged()
|
||||
.onEach(::updateContent)
|
||||
.onEach { tokenListAnalyticsSender.send(userWallet, maybeTokenList = it) }
|
||||
.onEach(walletWithFundsChecker::check)
|
||||
override fun create(coroutineScope: CoroutineScope): Flow<Pair<Either<TokenListError, TokenList>, 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<TokenListError, TokenList>) {
|
||||
private fun updateContent(maybeTokenList: Either<TokenListError, TokenList>, appCurrency: AppCurrency) {
|
||||
stateHolder.update(
|
||||
maybeTokenList.fold(
|
||||
ifLeft = { SetTokenListErrorTransformer(userWalletId = userWallet.walletId, error = it) },
|
||||
|
|
|
|||
|
|
@ -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<WalletScreenState> = 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<AppCurrency> {
|
||||
return getSelectedAppCurrencyUseCase()
|
||||
.map { maybeAppCurrency ->
|
||||
maybeAppCurrency.getOrElse { AppCurrency.Default }
|
||||
}
|
||||
.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.Eagerly,
|
||||
initialValue = AppCurrency.Default,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue