Updated on 2026-08-14

This commit is contained in:
Tangem 2025-04-30 12:51:57 +03:00
commit 2541461d44
954 changed files with 22834 additions and 21200 deletions

View file

@ -16,6 +16,7 @@ import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsModel
import com.tangem.feature.tokendetails.presentation.tokendetails.ui.TokenDetailsScreen
import com.tangem.features.markets.token.block.TokenMarketBlockComponent
import com.tangem.features.onramp.OnrampFeatureToggles
import com.tangem.features.tokendetails.TokenDetailsComponent
import com.tangem.features.txhistory.TxHistoryFeatureToggles
import com.tangem.features.txhistory.component.TxHistoryComponent
@ -23,12 +24,14 @@ import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
@Suppress("LongParameterList")
internal class DefaultTokenDetailsComponent @AssistedInject constructor(
@Assisted appComponentContext: AppComponentContext,
@Assisted params: TokenDetailsComponent.Params,
tokenMarketBlockComponentFactory: TokenMarketBlockComponent.Factory,
txHistoryComponentFactory: TxHistoryComponent.Factory,
txHistoryFeatureToggles: TxHistoryFeatureToggles,
onrampFeatureToggles: OnrampFeatureToggles,
deepLinksRegistry: DeepLinksRegistry,
) : TokenDetailsComponent, AppComponentContext by appComponentContext {
@ -48,11 +51,19 @@ internal class DefaultTokenDetailsComponent @AssistedInject constructor(
onResume = model::onResume,
)
val deeplinks = buildList {
if (!onrampFeatureToggles.isFeatureEnabled) {
add(
BuyCurrencyDeepLink(
onReceive = model::onBuyCurrencyDeepLink,
),
)
}
}
registerDeepLinks(
registry = deepLinksRegistry,
BuyCurrencyDeepLink(
onReceive = model::onBuyCurrencyDeepLink,
),
deeplinks,
)
}

View file

@ -46,15 +46,4 @@ internal class DefaultTokenDetailsRouter @Inject constructor(
),
)
}
override fun openOnrampSuccess(externalTxId: String) {
// finish current onramp flow and show onramp success screen
val replaceOnrampScreens = router.stack
.filterNot { it is AppRoute.Onramp }
.toMutableList()
replaceOnrampScreens.add(AppRoute.OnrampSuccess(externalTxId))
router.replaceAll(*replaceOnrampScreens.toTypedArray())
}
}

View file

@ -17,6 +17,4 @@ internal interface InnerTokenDetailsRouter {
fun openTokenDetails(userWalletId: UserWalletId, currency: CryptoCurrency)
fun openStaking(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency, yieldId: String)
fun openOnrampSuccess(externalTxId: String)
}

View file

@ -6,6 +6,8 @@ import arrow.core.getOrElse
import com.tangem.blockchain.common.address.AddressType
import com.tangem.common.routing.AppRoute
import com.tangem.common.routing.AppRouter
import com.tangem.common.ui.bottomsheet.receive.AddressModel
import com.tangem.common.ui.bottomsheet.receive.mapToAddressModels
import com.tangem.common.ui.expressStatus.ExpressStatusBottomSheetConfig
import com.tangem.common.ui.expressStatus.state.ExpressTransactionStateUM
import com.tangem.core.analytics.api.AnalyticsEventHandler
@ -17,8 +19,6 @@ import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.core.decompose.ui.UiMessageSender
import com.tangem.core.navigation.share.ShareManager
import com.tangem.core.ui.clipboard.ClipboardManager
import com.tangem.common.ui.bottomsheet.receive.AddressModel
import com.tangem.common.ui.bottomsheet.receive.mapToAddressModels
import com.tangem.core.ui.components.transactions.state.TxHistoryState
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resourceReference
@ -167,7 +167,7 @@ internal class TokenDetailsModel @Inject constructor(
appCurrencyProvider = Provider { selectedAppCurrencyFlow.value },
currentStateProvider = Provider { uiState.value },
cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus },
userWalletId = userWalletId,
userWallet = userWallet,
cryptoCurrency = cryptoCurrency,
)
}
@ -196,13 +196,9 @@ internal class TokenDetailsModel @Inject constructor(
handleBalanceHiding()
}
fun onBuyCurrencyDeepLink(externalTxId: String) {
if (onrampFeatureToggles.isFeatureEnabled) {
router.openOnrampSuccess(externalTxId)
} else {
val currency = cryptoCurrencyStatus?.currency ?: return
analyticsEventsHandler.send(TokenScreenAnalyticsEvent.Bought(currency.symbol))
}
fun onBuyCurrencyDeepLink() {
val currency = cryptoCurrencyStatus?.currency ?: return
analyticsEventsHandler.send(TokenScreenAnalyticsEvent.Bought(currency.symbol))
}
fun onPause() {

View file

@ -1,9 +1,6 @@
package com.tangem.feature.tokendetails.presentation.tokendetails.state.factory
import com.tangem.common.ui.expressStatus.state.ExpressLinkUM
import com.tangem.common.ui.expressStatus.state.ExpressStatusItemState
import com.tangem.common.ui.expressStatus.state.ExpressStatusItemUM
import com.tangem.common.ui.expressStatus.state.ExpressStatusUM
import com.tangem.common.ui.expressStatus.state.*
import com.tangem.common.ui.notifications.ExpressNotificationsUM
import com.tangem.common.ui.notifications.NotificationUM
import com.tangem.core.analytics.api.AnalyticsEventHandler
@ -23,9 +20,6 @@ import com.tangem.domain.onramp.model.cache.OnrampTransaction
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.model.analytics.TokenOnrampAnalyticsEvent
import com.tangem.common.ui.expressStatus.state.ExpressTransactionStateIconUM
import com.tangem.common.ui.expressStatus.state.ExpressTransactionStateInfoUM
import com.tangem.common.ui.expressStatus.state.ExpressTransactionStateUM
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsClickIntents
import com.tangem.features.tokendetails.impl.R
import com.tangem.utils.Provider
@ -129,8 +123,12 @@ internal class TokenDetailsOnrampTransactionStateConverter(
private fun getIconState(status: OnrampStatus.Status): ExpressTransactionStateIconUM {
return when (status) {
OnrampStatus.Status.Verifying -> ExpressTransactionStateIconUM.Warning
OnrampStatus.Status.Failed -> ExpressTransactionStateIconUM.Error
OnrampStatus.Status.RefundInProgress,
OnrampStatus.Status.Verifying,
-> ExpressTransactionStateIconUM.Warning
OnrampStatus.Status.Refunded,
OnrampStatus.Status.Failed,
-> ExpressTransactionStateIconUM.Error
else -> ExpressTransactionStateIconUM.None
}
}
@ -213,6 +211,10 @@ internal class TokenDetailsOnrampTransactionStateConverter(
wrappedList(cryptoCurrency.name),
)
}
this == OnrampStatus.Status.RefundInProgress ||
this == OnrampStatus.Status.Refunded -> {
resourceReference(R.string.express_exchange_status_failed)
}
else -> {
resourceReference(R.string.express_status_bought, wrappedList(cryptoCurrency.name))
}
@ -234,6 +236,12 @@ internal class TokenDetailsOnrampTransactionStateConverter(
wrappedList(cryptoCurrency.name),
)
}
this == OnrampStatus.Status.RefundInProgress -> {
resourceReference(R.string.express_exchange_status_refunding)
}
this == OnrampStatus.Status.Refunded -> {
resourceReference(R.string.express_exchange_status_refunded)
}
else -> {
resourceReference(
R.string.express_exchange_status_sent,
@ -241,7 +249,11 @@ internal class TokenDetailsOnrampTransactionStateConverter(
)
}
},
state = getStatusState(OnrampStatus.Status.Sending),
state = when {
this == OnrampStatus.Status.RefundInProgress -> ExpressStatusItemState.Active
this == OnrampStatus.Status.Refunded -> ExpressStatusItemState.Error
else -> getStatusState(OnrampStatus.Status.Sending)
},
)
private fun getStatusLink(status: OnrampStatus.Status, externalTxUrl: String?): ExpressLinkUM {

View file

@ -5,20 +5,21 @@ import com.tangem.core.analytics.api.AnalyticsEventHandler
import com.tangem.datasource.local.swaptx.ExpressAnalyticsStatus
import com.tangem.datasource.local.swaptx.SwapTransactionStatusStore
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.quotes.QuotesRepositoryV2
import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase
import com.tangem.domain.tokens.TokensFeatureToggles
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.Quote
import com.tangem.domain.tokens.model.analytics.TokenExchangeAnalyticsEvent
import com.tangem.domain.tokens.repository.QuotesRepository
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.feature.swap.domain.SwapTransactionRepository
import com.tangem.feature.swap.domain.api.SwapRepository
import com.tangem.feature.swap.domain.models.domain.*
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsClickIntents
import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState
import com.tangem.feature.tokendetails.presentation.tokendetails.state.express.ExchangeUM
import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.TokenDetailsSwapTransactionsStateConverter
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsClickIntents
import com.tangem.utils.Provider
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
@ -27,7 +28,6 @@ import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.map
@Suppress("LongParameterList")
@ -35,14 +35,15 @@ internal class ExchangeStatusFactory @AssistedInject constructor(
private val swapTransactionRepository: SwapTransactionRepository,
private val swapRepository: SwapRepository,
private val quotesRepository: QuotesRepository,
private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase,
private val quotesRepositoryV2: QuotesRepositoryV2,
private val tokensFeatureToggles: TokensFeatureToggles,
private val addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase,
private val swapTransactionStatusStore: SwapTransactionStatusStore,
private val analyticsEventsHandler: AnalyticsEventHandler,
@Assisted private val clickIntents: TokenDetailsClickIntents,
@Assisted private val appCurrencyProvider: Provider<AppCurrency>,
@Assisted private val currentStateProvider: Provider<TokenDetailsState>,
@Assisted private val userWalletId: UserWalletId,
@Assisted private val userWallet: UserWallet,
@Assisted private val cryptoCurrency: CryptoCurrency,
) {
@ -56,14 +57,9 @@ internal class ExchangeStatusFactory @AssistedInject constructor(
}
suspend operator fun invoke(): Flow<PersistentList<ExchangeUM>> {
val selectedWallet = getSelectedWalletSyncUseCase().fold(
ifLeft = { return emptyFlow() },
ifRight = { it },
)
return swapTransactionRepository.getTransactions(
userWalletId = userWalletId,
userWallet = userWallet,
cryptoCurrencyId = cryptoCurrency.id,
scanResponse = selectedWallet.scanResponse,
).conflate()
.map { savedTransactions ->
val quotes = savedTransactions
@ -87,7 +83,7 @@ internal class ExchangeStatusFactory @AssistedInject constructor(
val shouldDispose = selectedTx.activeStatus?.isAutoDisposable == true || isForceDispose
if (shouldDispose) {
swapTransactionRepository.removeTransaction(
userWalletId = userWalletId,
userWalletId = userWallet.walletId,
fromCryptoCurrency = selectedTx.fromCryptoCurrency,
toCryptoCurrency = selectedTx.toCryptoCurrency,
txId = selectedTx.info.txId,
@ -113,7 +109,7 @@ internal class ExchangeStatusFactory @AssistedInject constructor(
}
private suspend fun getExchangeStatus(txId: String, provider: SwapProvider): ExchangeStatusModel? {
return swapRepository.getExchangeStatus(txId)
return swapRepository.getExchangeStatus(userWallet = userWallet, txId = txId)
.fold(
ifLeft = { null },
ifRight = { statusModel ->
@ -153,7 +149,7 @@ internal class ExchangeStatusFactory @AssistedInject constructor(
val refundContractAddress = status.refundContractAddress
if (refundNetwork != null && refundContractAddress != null) {
return addCryptoCurrenciesUseCase(
userWalletId = userWalletId,
userWalletId = userWallet.walletId,
contractAddress = refundContractAddress,
networkId = refundNetwork,
).getOrNull()
@ -198,7 +194,12 @@ internal class ExchangeStatusFactory @AssistedInject constructor(
private suspend fun Set<CryptoCurrency.ID>.getQuotesOrEmpty(refresh: Boolean): Set<Quote> {
return try {
val rawIds = mapNotNull { it.rawCurrencyId }.toSet()
quotesRepository.getQuotesSync(rawIds, refresh)
if (tokensFeatureToggles.isQuotesLoadingRefactoringEnabled) {
quotesRepositoryV2.getMultiQuoteSyncOrNull(currenciesIds = rawIds).orEmpty()
} else {
quotesRepository.getQuotesSync(rawIds, refresh)
}
} catch (t: Throwable) {
emptySet()
}
@ -210,7 +211,7 @@ internal class ExchangeStatusFactory @AssistedInject constructor(
clickIntents: TokenDetailsClickIntents,
appCurrencyProvider: Provider<AppCurrency>,
currentStateProvider: Provider<TokenDetailsState>,
userWalletId: UserWalletId,
userWallet: UserWallet,
cryptoCurrency: CryptoCurrency,
): ExchangeStatusFactory
}

View file

@ -10,12 +10,12 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.model.analytics.TokenExchangeAnalyticsEvent
import com.tangem.domain.tokens.model.analytics.TokenOnrampAnalyticsEvent
import com.tangem.domain.tokens.model.analytics.TokenScreenAnalyticsEvent
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.feature.swap.domain.models.domain.ExchangeStatus
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsClickIntents
import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.ExchangeStatusNotification
import com.tangem.feature.tokendetails.presentation.tokendetails.state.express.ExchangeUM
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsClickIntents
import com.tangem.utils.Provider
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.assisted.Assisted
@ -36,7 +36,7 @@ internal class ExpressStatusFactory @AssistedInject constructor(
@Assisted private val clickIntents: TokenDetailsClickIntents,
@Assisted private val cryptoCurrency: CryptoCurrency,
@Assisted appCurrencyProvider: Provider<AppCurrency>,
@Assisted userWalletId: UserWalletId,
@Assisted userWallet: UserWallet,
@Assisted cryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus?>,
private val dispatchers: CoroutineDispatcherProvider,
private val analyticsEventsHandler: AnalyticsEventHandler,
@ -49,7 +49,7 @@ internal class ExpressStatusFactory @AssistedInject constructor(
clickIntents = clickIntents,
appCurrencyProvider = appCurrencyProvider,
currentStateProvider = currentStateProvider,
userWalletId = userWalletId,
userWallet = userWallet,
cryptoCurrency = cryptoCurrency,
)
}
@ -61,7 +61,7 @@ internal class ExpressStatusFactory @AssistedInject constructor(
appCurrencyProvider = appCurrencyProvider,
clickIntents = clickIntents,
cryptoCurrency = cryptoCurrency,
userWalletId = userWalletId,
userWallet = userWallet,
)
}
@ -210,7 +210,7 @@ internal class ExpressStatusFactory @AssistedInject constructor(
clickIntents: TokenDetailsClickIntents,
appCurrencyProvider: Provider<AppCurrency>,
currentStateProvider: Provider<TokenDetailsState>,
userWalletId: UserWalletId,
userWallet: UserWallet,
cryptoCurrency: CryptoCurrency,
cryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus?>,
): ExpressStatusFactory

View file

@ -14,8 +14,8 @@ import com.tangem.domain.onramp.model.OnrampStatus.Status.*
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.model.analytics.TokenOnrampAnalyticsEvent
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsClickIntents
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState
import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.TokenDetailsOnrampTransactionStateConverter
import com.tangem.utils.Provider
@ -39,7 +39,7 @@ internal class OnrampStatusFactory @AssistedInject constructor(
@Assisted private val appCurrencyProvider: Provider<AppCurrency>,
@Assisted private val clickIntents: TokenDetailsClickIntents,
@Assisted private val cryptoCurrency: CryptoCurrency,
@Assisted private val userWalletId: UserWalletId,
@Assisted private val userWallet: UserWallet,
) {
private val onrampTransactionStateConverter by lazy(LazyThreadSafetyMode.NONE) {
@ -54,7 +54,7 @@ internal class OnrampStatusFactory @AssistedInject constructor(
operator fun invoke(): Flow<List<ExpressTransactionStateUM.OnrampUM>> {
return getOnrampTransactionsUseCase(
userWalletId = userWalletId,
userWalletId = userWallet.walletId,
cryptoCurrencyId = cryptoCurrency.id,
).map { maybeTransaction ->
maybeTransaction.fold(
@ -74,7 +74,7 @@ internal class OnrampStatusFactory @AssistedInject constructor(
val selectedTx = bottomSheetConfig.value as? ExpressTransactionStateUM.OnrampUM ?: return
if (selectedTx.activeStatus.isAutoDisposable || isForceDispose) {
onrampRemoveTransactionUseCase(externalTxId = selectedTx.info.txExternalId)
onrampRemoveTransactionUseCase(txId = selectedTx.info.txId)
}
}
@ -82,7 +82,7 @@ internal class OnrampStatusFactory @AssistedInject constructor(
return if (onrampTx.activeStatus.isTerminal) {
onrampTx
} else {
getOnrampStatusUseCase(onrampTx.info.txId).fold(
getOnrampStatusUseCase(userWallet = userWallet, onrampTx.info.txId).fold(
ifLeft = {
Timber.e("Couldn't update onramp status. $it")
onrampTx
@ -97,14 +97,14 @@ internal class OnrampStatusFactory @AssistedInject constructor(
private suspend fun List<ExpressTransactionStateUM.OnrampUM>.clearHiddenTerminal() {
this.filter { it.activeStatus.isHidden && it.activeStatus.isTerminal }
.forEach { onrampRemoveTransactionUseCase(externalTxId = it.info.txExternalId) }
.forEach { onrampRemoveTransactionUseCase(txId = it.info.txId) }
}
private suspend fun sendStatusUpdateAnalytics(
onrampTx: ExpressTransactionStateUM.OnrampUM,
statusModel: OnrampStatus,
) {
val externalTxId = statusModel.externalTxId
val txId = statusModel.txId
val status = toAnalyticStatus(statusModel.status) ?: return
if (statusModel.status != onrampTx.activeStatus) {
@ -117,7 +117,7 @@ internal class OnrampStatusFactory @AssistedInject constructor(
),
)
onrampUpdateTransactionStatusUseCase(
externalTxId = externalTxId,
txId = txId,
externalTxUrl = statusModel.externalTxUrl.orEmpty(),
status = statusModel.status,
)
@ -134,10 +134,12 @@ internal class OnrampStatusFactory @AssistedInject constructor(
PaymentProcessing,
Paid,
Sending,
RefundInProgress,
-> ExpressAnalyticsStatus.InProgress
Verifying -> ExpressAnalyticsStatus.KYC
Failed -> ExpressAnalyticsStatus.Fail
Finished -> ExpressAnalyticsStatus.Done
Refunded -> ExpressAnalyticsStatus.Refunded
null -> null
}
}
@ -150,7 +152,7 @@ internal class OnrampStatusFactory @AssistedInject constructor(
appCurrencyProvider: Provider<AppCurrency>,
clickIntents: TokenDetailsClickIntents,
cryptoCurrency: CryptoCurrency,
userWalletId: UserWalletId,
userWallet: UserWallet,
): OnrampStatusFactory
}
}