Updated on 2026-08-14

This commit is contained in:
Tangem 2026-03-10 16:33:07 +04:00
parent 2f2d6755f9
commit 5f4dfefc2e
20 changed files with 190 additions and 311 deletions

View file

@ -8,11 +8,12 @@ import arrow.core.raise.either
import com.tangem.blockchain.common.AmountType
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.core.analytics.api.AnalyticsEventHandler
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCryptoCurrencyStatus
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.transaction.error.GetFeeError
import com.tangem.domain.transaction.models.TransactionFeeExtended
import com.tangem.domain.transaction.usecase.IsFeeApproximateUseCase
@ -55,7 +56,7 @@ internal class FeeSelectorLogic @AssistedInject constructor(
private val feeSelectorCheckReloadTrigger: FeeSelectorCheckReloadTrigger,
private val feeSelectorAlertFactory: FeeSelectorAlertFactory,
private val analyticsEventHandler: AnalyticsEventHandler,
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val getUserWalletUseCase: GetUserWalletUseCase,
private val getAvailableFeeTokensUseCase: GetAvailableFeeTokensUseCase,
isGaslessFeeSupportedForNetwork: IsGaslessFeeSupportedForNetwork,
@ -294,11 +295,9 @@ internal class FeeSelectorLogic @AssistedInject constructor(
private suspend fun getSelectedTokenStatus(tokenId: CryptoCurrency.ID): Either<GetFeeError, CryptoCurrencyStatus> =
either {
if (params.feeCryptoCurrencyStatus.currency.id != tokenId) {
getSingleCryptoCurrencyStatusUseCase
.invokeMultiWalletSync(
userWalletId = params.userWalletId,
cryptoCurrencyId = tokenId,
).getOrElse {
singleAccountStatusListSupplier.getSyncOrNull(params.userWalletId)
.getCryptoCurrencyStatus(currencyId = tokenId, network = null)
.getOrElse {
raise(GetFeeError.DataError(IllegalStateException("No token found for id: $tokenId")))
}
} else {

View file

@ -35,7 +35,9 @@ import com.tangem.core.ui.utils.InputNumberFormatter
import com.tangem.core.ui.utils.parseBigDecimal
import com.tangem.datasource.local.appsflyer.AppsFlyerStore
import com.tangem.domain.account.status.model.AccountCryptoCurrencyStatus
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.usecase.GetAccountCurrencyStatusUseCase
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCryptoCurrencyStatus
import com.tangem.domain.account.usecase.IsAccountsModeEnabledUseCase
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.appcurrency.model.AppCurrency
@ -69,7 +71,6 @@ import com.tangem.domain.tangempay.GetTangemPayCustomerIdUseCase
import com.tangem.domain.tangempay.TangemPayWithdrawUseCase
import com.tangem.domain.tokens.GetFeePaidCryptoCurrencyStatusSyncUseCase
import com.tangem.domain.tokens.GetMinimumTransactionAmountSyncUseCase
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.UpdateDelayedNetworkStatusUseCase
import com.tangem.domain.transaction.error.GetFeeError
import com.tangem.domain.transaction.models.TransactionFeeExtended
@ -136,7 +137,6 @@ internal class SwapModel @Inject constructor(
private val analyticsErrorEventHandler: AnalyticsErrorHandler,
private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase,
private val updateDelayedCurrencyStatusUseCase: UpdateDelayedNetworkStatusUseCase,
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
private val getFeePaidCryptoCurrencyStatusSyncUseCase: GetFeePaidCryptoCurrencyStatusSyncUseCase,
private val getUserWalletUseCase: GetUserWalletUseCase,
private val getWalletMetaInfoUseCase: GetWalletMetaInfoUseCase,
@ -153,6 +153,7 @@ internal class SwapModel @Inject constructor(
router: AppRouter,
private val isAccountsModeEnabledUseCase: IsAccountsModeEnabledUseCase,
private val getAccountCurrencyStatusUseCase: GetAccountCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val getTangemPayCurrencyStatusUseCase: GetTangemPayCurrencyStatusUseCase,
private val tangemPayWithdrawUseCase: TangemPayWithdrawUseCase,
private val iGaslessFeeSupportedForNetwork: IsGaslessFeeSupportedForNetwork,
@ -386,10 +387,9 @@ internal class SwapModel @Inject constructor(
} else {
val fromStatus = getFromStatus()
val toStatus = initialCurrencyTo?.let { currencyTo ->
getSingleCryptoCurrencyStatusUseCase.invokeMultiWalletSync(
userWalletId = userWalletId,
cryptoCurrencyId = currencyTo.id,
).getOrNull()
singleAccountStatusListSupplier.getSyncOrNull(params.userWalletId)
.getCryptoCurrencyStatus(currencyTo)
.getOrNull()
}
if (fromStatus == null) {
@ -2305,10 +2305,9 @@ internal class SwapModel @Inject constructor(
depositAddress = tangemPayInput.depositAddress,
)
} else {
getSingleCryptoCurrencyStatusUseCase.invokeMultiWalletSync(
userWalletId = userWalletId,
cryptoCurrencyId = initialCurrencyFrom.id,
).getOrNull()
singleAccountStatusListSupplier.getSyncOrNull(params.userWalletId)
.getCryptoCurrencyStatus(currency = initialCurrencyFrom)
.getOrNull()
}
}

View file

@ -36,6 +36,7 @@ dependencies {
implementation(projects.domain.tokens.models)
implementation(projects.domain.balanceHiding)
implementation(projects.domain.balanceHiding.models)
implementation(projects.domain.account.status)
/* AndroidX */
implementation(deps.androidx.activity.compose)

View file

@ -1,22 +1,19 @@
package com.tangem.features.txhistory.model
import androidx.compose.runtime.Stable
import arrow.core.Either
import arrow.core.Option
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.core.navigation.url.UrlOpener
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCryptoCurrencyStatus
import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase
import com.tangem.domain.card.common.util.cardTypesResolver
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.error.CurrencyStatusError
import com.tangem.domain.txhistory.models.TxHistoryStateError
import com.tangem.domain.txhistory.repository.TxHistoryRepositoryV2
import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase
import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.features.txhistory.component.TxHistoryComponent
import com.tangem.features.txhistory.converter.TxHistoryItemToTransactionStateConverter
import com.tangem.features.txhistory.entity.TxHistoryUM
@ -40,8 +37,7 @@ internal class TxHistoryModel @Inject constructor(
override val dispatchers: CoroutineDispatcherProvider,
private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase,
private val txHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase,
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
private val getUserWalletUseCase: GetUserWalletUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val getExplorerTransactionUrlUseCase: GetExplorerTransactionUrlUseCase,
private val urlOpener: UrlOpener,
private val txHistoryUpdateListener: TxHistoryUpdateListener,
@ -184,26 +180,20 @@ internal class TxHistoryModel @Inject constructor(
}
private fun subscribeOnCurrencyStatusUpdates() {
val userWallet: UserWallet = requireNotNull(getUserWalletUseCase(params.userWalletId).getOrNull()) {
"User wallet not found"
}
getSingleCryptoCurrencyStatusUseCase.invokeMultiWallet(
userWalletId = params.userWalletId,
currencyId = params.currency.id,
isSingleWalletWithTokens = userWallet is UserWallet.Cold &&
userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken(),
)
singleAccountStatusListSupplier(params.userWalletId)
.map { it.getCryptoCurrencyStatus(currency = params.currency) }
.distinctUntilChanged()
.onEach(::handlePendingTxsChanges)
.flowOn(dispatchers.main)
.flowOn(dispatchers.default)
.launchIn(modelScope)
}
private fun handlePendingTxsChanges(maybeCurrencyStatus: Either<CurrencyStatusError, CryptoCurrencyStatus>) {
maybeCurrencyStatus.onRight { status ->
private fun handlePendingTxsChanges(maybeCurrencyStatus: Option<CryptoCurrencyStatus>) {
maybeCurrencyStatus.onSome { status ->
val pendingTxs = status.value.pendingTransactions
.map(txHistoryItemConverter::convert)
.toPersistentList()
_uiState.update { state ->
if (state is TxHistoryUM.NotSupported) {
state.copy(pendingTransactions = pendingTxs)

View file

@ -8,6 +8,7 @@ import com.tangem.core.analytics.models.AnalyticsParam
import com.tangem.core.analytics.models.event.MainScreenAnalyticsEvent
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.decompose.ui.UiMessageSender
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.currency.CryptoCurrency
@ -18,7 +19,6 @@ import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.nft.analytics.NFTAnalyticsEvent
import com.tangem.domain.settings.ShouldShowMarketsTooltipUseCase
import com.tangem.domain.tokens.GetCryptoCurrencyActionsUseCase
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.model.details.NavigationAction
import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
@ -94,7 +94,7 @@ internal class WalletContentClickIntentsImplementor @Inject constructor(
private val currencyActionsClickIntents: WalletCurrencyActionsClickIntentsImplementor,
private val onrampStatusFactory: OnrampStatusFactory,
private val getUserWalletUseCase: GetUserWalletUseCase,
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val getCryptoCurrencyActionsUseCase: GetCryptoCurrencyActionsUseCase,
private val getExplorerTransactionUrlUseCase: GetExplorerTransactionUrlUseCase,
private val shouldShowMarketsTooltipUseCase: ShouldShowMarketsTooltipUseCase,
@ -269,7 +269,7 @@ internal class WalletContentClickIntentsImplementor @Inject constructor(
override fun onTransactionClick(txHash: String) {
modelScope.launch(dispatchers.main) {
val currency = getSingleCryptoCurrencyStatusUseCase.unwrap(
val currency = singleAccountStatusListSupplier.unwrap(
userWalletId = stateHolder.getSelectedWalletId(),
)
?.currency

View file

@ -22,6 +22,7 @@ import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.haptic.TangemHapticEffect
import com.tangem.core.ui.haptic.VibratorHapticManager
import com.tangem.core.ui.message.DialogMessage
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.usecase.ManageCryptoCurrenciesUseCase
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.appcurrency.extenstions.unwrap
@ -42,7 +43,10 @@ import com.tangem.domain.onramp.model.OnrampSource
import com.tangem.domain.promo.GetStoryContentUseCase
import com.tangem.domain.promo.models.StoryContentIds
import com.tangem.domain.staking.model.StakingOption
import com.tangem.domain.tokens.*
import com.tangem.domain.tokens.IsCryptoCurrencyCoinCouldHideUseCase
import com.tangem.domain.tokens.NeedShowYieldSupplyDepositedWarningUseCase
import com.tangem.domain.tokens.SaveViewedTokenReceiveWarningUseCase
import com.tangem.domain.tokens.SaveViewedYieldSupplyWarningUseCase
import com.tangem.domain.tokens.model.ScenarioUnavailabilityReason
import com.tangem.domain.tokens.model.analytics.TokenReceiveCopyActionSource
import com.tangem.domain.tokens.model.analytics.TokenReceiveNewAnalyticsEvent
@ -124,7 +128,7 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor(
private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase,
private val walletManagersFacade: WalletManagersFacade,
private val isDemoCardUseCase: IsDemoCardUseCase,
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val getExploreUrlUseCase: GetExploreUrlUseCase,
private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase,
private val getStoryContentUseCase: GetStoryContentUseCase,
@ -485,7 +489,7 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor(
val userWalletId = stateHolder.getSelectedWalletId()
modelScope.launch(dispatchers.main) {
val currencyStatus = getSingleCryptoCurrencyStatusUseCase.unwrap(userWalletId) ?: return@launch
val currencyStatus = singleAccountStatusListSupplier.unwrap(userWalletId) ?: return@launch
when (val addresses = currencyStatus.value.networkAddress) {
is NetworkAddress.Selectable -> {

View file

@ -1,13 +1,11 @@
package com.tangem.feature.wallet.presentation.wallet.domain
import arrow.core.Either
import com.tangem.domain.account.status.producer.SingleAccountStatusListProducer
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.error.CurrencyStatusError
import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase
import kotlinx.coroutines.flow.*
import timber.log.Timber
internal fun GetSelectedWalletSyncUseCase.unwrap(): UserWallet? {
@ -20,29 +18,9 @@ internal fun GetSelectedWalletSyncUseCase.unwrap(): UserWallet? {
)
}
internal suspend fun GetSingleCryptoCurrencyStatusUseCase.unwrap(userWalletId: UserWalletId): CryptoCurrencyStatus? {
return invokeSingleWallet(userWalletId)
.conflate()
.distinctUntilChanged()
.filter(Either<CurrencyStatusError, CryptoCurrencyStatus>::isRight)
.firstOrNull()
?.fold(
ifLeft = {
Timber.e("Impossible to get primary currency status $it")
null
},
ifRight = { it },
)
}
internal suspend fun GetSingleCryptoCurrencyStatusUseCase.collectLatest(
userWalletId: UserWalletId,
onRight: suspend (CryptoCurrencyStatus) -> Unit,
) {
invokeSingleWallet(userWalletId = userWalletId)
.conflate()
.distinctUntilChanged()
.collectLatest { maybeStatus ->
maybeStatus.onRight { onRight(it) }
}
internal suspend fun SingleAccountStatusListSupplier.unwrap(userWalletId: UserWalletId): CryptoCurrencyStatus? {
return getSyncOrNull(params = SingleAccountStatusListProducer.Params(userWalletId))
?.mainAccount
?.flattenCurrencies()
?.firstOrNull()
}

View file

@ -43,6 +43,7 @@ dependencies {
implementation(projects.domain.models)
implementation(projects.domain.appCurrency.models)
implementation(projects.domain.appCurrency)
implementation(projects.domain.account.status)
implementation(projects.domain.wallets.models)
implementation(projects.domain.wallets)
implementation(projects.domain.tokens.models)

View file

@ -16,12 +16,13 @@ import com.tangem.core.ui.extensions.stringReference
import com.tangem.core.ui.extensions.wrappedList
import com.tangem.core.ui.format.bigdecimal.crypto
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCryptoCurrencyStatus
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.domain.yield.supply.usecase.*
import com.tangem.features.yield.supply.api.YieldSupplyActiveComponent
@ -55,7 +56,7 @@ internal class YieldSupplyActiveModel @Inject constructor(
private val yieldSupplyGetMaxFeeUseCase: YieldSupplyGetMaxFeeUseCase,
private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase,
private val getUserWalletUseCase: GetUserWalletUseCase,
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val urlOpener: UrlOpener,
private val appRouter: AppRouter,
private val yieldSupplyGetDustMinAmountUseCase: YieldSupplyGetDustMinAmountUseCase,
@ -168,44 +169,44 @@ internal class YieldSupplyActiveModel @Inject constructor(
ifRight = { wallet ->
userWallet = wallet
getSingleCryptoCurrencyStatusUseCase.invokeMultiWallet(
userWalletId = params.userWalletId,
currencyId = cryptoCurrency.id,
isSingleWalletWithTokens = false,
).onEach { maybeCryptoCurrency ->
maybeCryptoCurrency.fold(
ifRight = { cryptoCurrencyStatus ->
cryptoCurrencyStatusFlow.update { cryptoCurrencyStatus }
singleAccountStatusListSupplier(params.userWalletId)
.map { it.getCryptoCurrencyStatus(currency = cryptoCurrency) }
.distinctUntilChanged()
.onEach { maybeCryptoCurrency ->
maybeCryptoCurrency.fold(
ifSome = { cryptoCurrencyStatus ->
cryptoCurrencyStatusFlow.update { cryptoCurrencyStatus }
val protocolBalance =
cryptoCurrencyStatus.value.yieldSupplyStatus?.effectiveProtocolBalance
?: yieldSupplyGetProtocolBalanceUseCase(
userWalletId = userWalletId,
cryptoCurrency = cryptoCurrency,
).getOrNull()
val protocolBalance =
cryptoCurrencyStatus.value.yieldSupplyStatus?.effectiveProtocolBalance
?: yieldSupplyGetProtocolBalanceUseCase(
userWalletId = userWalletId,
cryptoCurrency = cryptoCurrency,
).getOrNull()
loadApy()
loadMinAmount()
loadFees()
loadApy()
loadMinAmount()
loadFees()
uiState.update {
it.copy(
availableBalance = stringReference(
protocolBalance.format {
crypto(
symbol = AAVEV3_PREFIX + cryptoCurrency.symbol,
decimals = cryptoCurrency.decimals,
)
},
),
)
}
},
ifLeft = {
Timber.w(it.toString())
},
)
}.flowOn(dispatchers.default)
uiState.update {
it.copy(
availableBalance = stringReference(
protocolBalance.format {
crypto(
symbol = AAVEV3_PREFIX + cryptoCurrency.symbol,
decimals = cryptoCurrency.decimals,
)
},
),
)
}
},
ifEmpty = {
Timber.w("No currency status found: ${cryptoCurrency.id}")
},
)
}
.flowOn(dispatchers.default)
.launchIn(modelScope)
},
ifLeft = { error ->

View file

@ -5,9 +5,10 @@ import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.core.decompose.navigation.Router
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCryptoCurrencyStatus
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.model.details.NavigationAction
import com.tangem.domain.yield.supply.usecase.YieldSupplyEnterStatusUseCase
import com.tangem.features.yield.supply.api.YieldSupplyEntryComponent
@ -24,7 +25,7 @@ internal class YieldSupplyEntryModel @Inject constructor(
override val dispatchers: CoroutineDispatcherProvider,
private val router: Router,
private val yieldSupplyEnterStatusUseCase: YieldSupplyEnterStatusUseCase,
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
) : Model() {
private val params = paramsContainer.require<YieldSupplyEntryComponent.Params>()
@ -39,22 +40,22 @@ internal class YieldSupplyEntryModel @Inject constructor(
val userWalletId = params.userWalletId
val cryptoCurrency = params.cryptoCurrency
modelScope.launch(dispatchers.default) {
getSingleCryptoCurrencyStatusUseCase.invokeMultiWalletSync(
userWalletId = userWalletId,
cryptoCurrencyId = cryptoCurrency.id,
).onLeft { error ->
Timber.e("Failed to get CryptoCurrencyStatus: $error")
withContext(dispatchers.mainImmediate) {
router.pop()
}
}.onRight { cryptoCurrencyStatus ->
withContext(dispatchers.mainImmediate) {
val route = getInitialRoute(cryptoCurrencyStatus)
if (route != null) {
router.replaceCurrent(route)
singleAccountStatusListSupplier.getSyncOrNull(userWalletId)
.getCryptoCurrencyStatus(currency = cryptoCurrency)
.onNone {
Timber.e("Failed to get CryptoCurrencyStatus: ${cryptoCurrency.id}")
withContext(dispatchers.mainImmediate) {
router.pop()
}
}
.onSome { cryptoCurrencyStatus ->
withContext(dispatchers.mainImmediate) {
val route = getInitialRoute(cryptoCurrencyStatus)
if (route != null) {
router.replaceCurrent(route)
}
}
}
}
}
}

View file

@ -11,6 +11,8 @@ import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.combinedReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.stringReference
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCryptoCurrencyStatus
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.models.StatusSource
@ -21,7 +23,6 @@ import com.tangem.domain.models.currency.shouldShowNotSuppliedNotification
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import com.tangem.domain.networks.single.SingleNetworkStatusFetcher
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.domain.yield.supply.models.YieldSupplyPendingStatus
import com.tangem.domain.yield.supply.usecase.*
@ -35,9 +36,9 @@ import com.tangem.utils.transformer.update
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import timber.log.Timber
import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject
import kotlin.properties.Delegates
import java.util.concurrent.atomic.AtomicBoolean
@Suppress("LongParameterList", "LargeClass")
@ModelScoped
@ -48,7 +49,7 @@ internal class YieldSupplyModel @Inject constructor(
private val appRouter: AppRouter,
private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase,
private val getUserWalletUseCase: GetUserWalletUseCase,
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val singleNetworkStatusFetcher: SingleNetworkStatusFetcher,
private val yieldSupplyGetTokenStatusUseCase: YieldSupplyGetTokenStatusUseCase,
private val yieldSupplyIsAvailableUseCase: YieldSupplyIsAvailableUseCase,
@ -109,32 +110,33 @@ internal class YieldSupplyModel @Inject constructor(
private fun subscribeOnCurrencyStatusUpdates() {
combine(
getSingleCryptoCurrencyStatusUseCase.invokeMultiWallet(
userWalletId = params.userWalletId,
currencyId = cryptoCurrency.id,
isSingleWalletWithTokens = false,
),
yieldSupplyEnterStatusFlowUseCase(
flow = singleAccountStatusListSupplier(params.userWalletId).map {
it.getCryptoCurrencyStatus(currency = cryptoCurrency)
},
flow2 = yieldSupplyEnterStatusFlowUseCase(
userWalletId = params.userWalletId,
cryptoCurrency = cryptoCurrency,
),
) { maybeCryptoCurrency, _ ->
maybeCryptoCurrency
}.flowOn(dispatchers.io)
}
.flowOn(dispatchers.io)
.distinctUntilChanged()
.onEach { maybeCryptoCurrency ->
maybeCryptoCurrency.fold(
ifRight = { cryptoCurrencyStatus ->
ifSome = { cryptoCurrencyStatus ->
latestCryptoCurrencyStatus = cryptoCurrencyStatus
if (isFirstCryptoCurrencyStatusEmission.compareAndSet(true, false)) {
sendInfoAboutProtocolStatus(cryptoCurrencyStatus)
}
onCryptoCurrencyStatusUpdated(cryptoCurrencyStatus)
},
ifLeft = {
Timber.w(it.toString())
ifEmpty = {
Timber.w("Unable to get crypto currency status: ${cryptoCurrency.id}")
},
)
}.launchIn(modelScope)
}
.launchIn(modelScope)
}
private suspend fun loadTokenStatus() {

View file

@ -13,13 +13,14 @@ import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIco
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.wrappedList
import com.tangem.datasource.local.appsflyer.AppsFlyerStore
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCryptoCurrencyStatus
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.isHotWallet
import com.tangem.domain.tokens.GetFeePaidCryptoCurrencyStatusSyncUseCase
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.transaction.error.GetFeeError
import com.tangem.domain.transaction.usecase.SendTransactionUseCase
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
@ -55,7 +56,7 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
paramsContainer: ParamsContainer,
private val analytics: AnalyticsEventHandler,
private val getUserWalletUseCase: GetUserWalletUseCase,
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val getFeePaidCryptoCurrencyStatusSyncUseCase: GetFeePaidCryptoCurrencyStatusSyncUseCase,
private val sendTransactionUseCase: SendTransactionUseCase,
private val yieldSupplyStartEarningUseCase: YieldSupplyStartEarningUseCase,
@ -346,27 +347,27 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
}
private fun getCurrenciesStatusUpdates() {
getSingleCryptoCurrencyStatusUseCase.invokeMultiWallet(
userWalletId = userWalletId,
currencyId = cryptoCurrency.id,
isSingleWalletWithTokens = false,
).onEach { maybeCryptoCurrency ->
maybeCryptoCurrency.fold(
ifRight = { cryptoCurrencyStatus ->
onDataLoaded(
currencyStatus = cryptoCurrencyStatus,
feeCurrencyStatus = getFeePaidCryptoCurrencyStatusSyncUseCase(
userWalletId = userWalletId,
cryptoCurrencyStatus = cryptoCurrencyStatus,
).getOrNull() ?: cryptoCurrencyStatus,
)
},
ifLeft = {
Timber.w(it.toString())
showAlertError()
},
)
}.launchIn(modelScope)
singleAccountStatusListSupplier(params.userWalletId)
.map { it.getCryptoCurrencyStatus(currency = cryptoCurrency) }
.distinctUntilChanged()
.onEach { maybeCryptoCurrency ->
maybeCryptoCurrency.fold(
ifSome = { cryptoCurrencyStatus ->
onDataLoaded(
currencyStatus = cryptoCurrencyStatus,
feeCurrencyStatus = getFeePaidCryptoCurrencyStatusSyncUseCase(
userWalletId = userWalletId,
cryptoCurrencyStatus = cryptoCurrencyStatus,
).getOrNull() ?: cryptoCurrencyStatus,
)
},
ifEmpty = {
Timber.w("Unable to get crypto currency status: ${cryptoCurrency.id}")
showAlertError()
},
)
}
.launchIn(modelScope)
}
private fun onDataLoaded(currencyStatus: CryptoCurrencyStatus, feeCurrencyStatus: CryptoCurrencyStatus) {