Updated on 2026-08-14

This commit is contained in:
Tangem 2025-07-03 09:59:33 +04:00
parent 0142f675ad
commit 99d7eec8cd
4 changed files with 69 additions and 28 deletions

View file

@ -19,9 +19,11 @@ import com.tangem.domain.models.scan.ScanResponse
import com.tangem.domain.onramp.GetLegacyTopUpUrlUseCase
import com.tangem.domain.tokens.FetchCurrencyStatusUseCase
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.TokensFeatureToggles
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.model.ScenarioUnavailabilityReason
import com.tangem.domain.tokens.model.analytics.TokenReceiveAnalyticsEvent
import com.tangem.domain.tokens.wallet.WalletBalanceFetcher
import com.tangem.domain.wallets.builder.ColdUserWalletBuilder
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.usecase.SaveWalletUseCase
@ -32,6 +34,7 @@ import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.extensions.isPositive
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
@Suppress("LongParameterList")
@ -49,6 +52,8 @@ internal class OnboardingNoteTopUpModel @Inject constructor(
private val rampStateManager: RampStateManager,
private val cardRepository: CardRepository,
private val saveWalletUseCase: SaveWalletUseCase,
private val walletBalanceFetcher: WalletBalanceFetcher,
private val tokensFeatureToggles: TokensFeatureToggles,
) : Model() {
private val params = paramsContainer.require<OnboardingNoteTopUpComponent.Params>()
@ -83,10 +88,12 @@ internal class OnboardingNoteTopUpModel @Inject constructor(
showBalanceLoadingProgress(true)
createUserWalletIfNull()
val userWalletId = requireNotNull(userWallet?.walletId)
fetchCurrencyStatusUseCase(
userWalletId = userWalletId,
refresh = true,
)
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
walletBalanceFetcher(params = WalletBalanceFetcher.Params(userWalletId = userWalletId))
.onLeft(Timber::e)
} else {
fetchCurrencyStatusUseCase(userWalletId = userWalletId, refresh = true)
}
showBalanceLoadingProgress(false)
}
}

View file

@ -36,8 +36,10 @@ import com.tangem.domain.onboarding.SaveTwinsOnboardingShownUseCase
import com.tangem.domain.onramp.GetLegacyTopUpUrlUseCase
import com.tangem.domain.tokens.FetchCurrencyStatusUseCase
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.TokensFeatureToggles
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.model.analytics.TokenReceiveAnalyticsEvent
import com.tangem.domain.tokens.wallet.WalletBalanceFetcher
import com.tangem.domain.wallets.builder.ColdUserWalletBuilder
import com.tangem.domain.wallets.builder.UserWalletIdBuilder
import com.tangem.domain.wallets.legacy.UserWalletsListManager
@ -85,6 +87,8 @@ internal class OnboardingTwinModel @Inject constructor(
private val sendFeedbackEmailUseCase: SendFeedbackEmailUseCase,
private val clipboardManager: ClipboardManager,
private val shareManager: ShareManager,
private val tokensFeatureToggles: TokensFeatureToggles,
private val walletBalanceFetcher: WalletBalanceFetcher,
) : Model() {
private val params = paramsContainer.require<OnboardingTwinComponent.Params>()
@ -329,13 +333,15 @@ internal class OnboardingTwinModel @Inject constructor(
cardRepository.finishCardActivation(params.scanResponse.card.cardId)
fetchCurrencyStatusUseCase.invoke(
userWalletId = userWallet.walletId,
refresh = true,
).onLeft {
Timber.e("Unable to fetch currency status: $it")
setLoading(false)
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
walletBalanceFetcher(params = WalletBalanceFetcher.Params(userWalletId = userWallet.walletId))
} else {
fetchCurrencyStatusUseCase.invoke(userWalletId = userWallet.walletId, refresh = true)
}
.onLeft {
Timber.e("Unable to fetch currency status: $it")
setLoading(false)
}
val cryptoCurrencyStatus = getSingleCryptoCurrencyStatusUseCase.invokeSingleWallet(userWallet.walletId)
.firstOrNull()?.getOrNull()
@ -431,10 +437,12 @@ internal class OnboardingTwinModel @Inject constructor(
it.copy(isLoading = true)
}
modelScope.launch {
fetchCurrencyStatusUseCase(
userWalletId = userWallet.walletId,
refresh = true,
)
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
walletBalanceFetcher(params = WalletBalanceFetcher.Params(userWalletId = userWallet.walletId))
.onLeft(Timber::e)
} else {
fetchCurrencyStatusUseCase(userWalletId = userWallet.walletId, refresh = true)
}
}
}

View file

@ -20,6 +20,8 @@ import com.tangem.domain.nft.ObserveAndClearNFTCacheIfNeedUseCase
import com.tangem.domain.settings.*
import com.tangem.domain.tokens.FetchCurrencyStatusUseCase
import com.tangem.domain.tokens.RefreshMultiCurrencyWalletQuotesUseCase
import com.tangem.domain.tokens.TokensFeatureToggles
import com.tangem.domain.tokens.wallet.WalletBalanceFetcher
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.models.isMultiCurrency
@ -83,6 +85,8 @@ internal class WalletModel @Inject constructor(
private val analyticsEventsHandler: AnalyticsEventHandler,
private val deepLinksRegistry: DeepLinksRegistry,
private val fetchCurrencyStatusUseCase: FetchCurrencyStatusUseCase,
private val walletBalanceFetcher: WalletBalanceFetcher,
private val tokensFeatureToggles: TokensFeatureToggles,
private val appRouter: AppRouter,
private val routingFeatureToggle: RoutingFeatureToggle,
private val observeAndClearNFTCacheIfNeedUseCase: ObserveAndClearNFTCacheIfNeedUseCase,
@ -518,10 +522,15 @@ internal class WalletModel @Inject constructor(
}
private fun fetchIfSingleWallet(userWallet: UserWallet) {
if (userWallet is UserWallet.Cold && userWallet.scanResponse.cardTypesResolver.isSingleWallet()) {
modelScope.launch {
fetchCurrencyStatusUseCase(userWalletId = userWallet.walletId)
.onLeft { Timber.e(it.toString()) }
modelScope.launch {
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
walletBalanceFetcher(params = WalletBalanceFetcher.Params(userWalletId = userWallet.walletId))
.onLeft(Timber::e)
} else {
if (userWallet is UserWallet.Cold && userWallet.scanResponse.cardTypesResolver.isSingleWallet()) {
fetchCurrencyStatusUseCase(userWalletId = userWallet.walletId)
.onLeft { Timber.e(it.toString()) }
}
}
}
}

View file

@ -11,6 +11,9 @@ import com.tangem.domain.tokens.FetchCardTokenListUseCase
import com.tangem.domain.tokens.FetchCurrencyStatusUseCase
import com.tangem.domain.tokens.FetchTokenListUseCase
import com.tangem.domain.tokens.FetchTokenListUseCase.RefreshMode
import com.tangem.domain.tokens.TokensFeatureToggles
import com.tangem.domain.tokens.error.TokenListError
import com.tangem.domain.tokens.wallet.WalletBalanceFetcher
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase
import com.tangem.domain.wallets.usecase.SelectWalletUseCase
@ -23,11 +26,11 @@ import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState
import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetRefreshStateTransformer
import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTokenListErrorTransformer
import com.tangem.features.onramp.OnrampFeatureToggles
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
@Suppress("LongParameterList")
@ -44,12 +47,13 @@ internal class WalletClickIntents @Inject constructor(
private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase,
private val selectWalletUseCase: SelectWalletUseCase,
private val fetchTokenListUseCase: FetchTokenListUseCase,
private val walletBalanceFetcher: WalletBalanceFetcher,
private val tokensFeatureToggles: TokensFeatureToggles,
private val fetchCardTokenListUseCase: FetchCardTokenListUseCase,
private val fetchCurrencyStatusUseCase: FetchCurrencyStatusUseCase,
private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase,
private val neverToShowWalletsScrollPreview: NeverToShowWalletsScrollPreview,
private val rampStateManager: RampStateManager,
private val dispatchers: CoroutineDispatcherProvider,
private val onrampFeatureToggles: OnrampFeatureToggles,
private val fetchHotCryptoUseCase: FetchHotCryptoUseCase,
private val onrampStatusFactory: OnrampStatusFactory,
@ -127,13 +131,21 @@ internal class WalletClickIntents @Inject constructor(
)
modelScope.launch {
val maybeFetchResult = if (
userWallet is UserWallet.Cold &&
userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()
) {
fetchCardTokenListUseCase(userWalletId = userWallet.walletId, refresh = true)
val maybeFetchResult = if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
walletBalanceFetcher.invoke(params = WalletBalanceFetcher.Params(userWalletId = userWallet.walletId))
.mapLeft {
Timber.e(it)
TokenListError.DataError(it)
}
} else {
fetchTokenListUseCase(userWalletId = userWallet.walletId, mode = RefreshMode.FULL)
val isSingleWalletWithToken = userWallet is UserWallet.Cold &&
userWallet.cardTypesResolver.isSingleWalletWithToken()
if (isSingleWalletWithToken) {
fetchCardTokenListUseCase(userWalletId = userWallet.walletId, refresh = true)
} else {
fetchTokenListUseCase(userWalletId = userWallet.walletId, mode = RefreshMode.FULL)
}
}
buildList {
@ -172,8 +184,13 @@ internal class WalletClickIntents @Inject constructor(
SetRefreshStateTransformer(userWalletId = userWallet.walletId, isRefreshing = showRefreshState),
)
modelScope.launch(dispatchers.main) {
fetchCurrencyStatusUseCase(userWallet.walletId, refresh = true)
modelScope.launch {
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
walletBalanceFetcher(params = WalletBalanceFetcher.Params(userWalletId = userWallet.walletId))
.onLeft(Timber::e)
} else {
fetchCurrencyStatusUseCase(userWallet.walletId, refresh = true)
}
onrampStatusFactory.updateOnrmapTransactionStatuses(userWallet)
walletScreenContentLoader.load(
userWallet = userWallet,