From 2e8d0bc03b2ee608c613c0a18ab8f0e3de7df7f4 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 16 Jun 2026 19:08:38 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../ui/expressStatus/ExpressStatusItems.kt | 2 + .../state/ExpressTransactionStateUM.kt | 2 + ...reviewEmptyExpressTransactionsComponent.kt | 2 + ...nDetailsOnrampTransactionStateConverter.kt | 6 +- ...enDetailsSwapTransactionsStateConverter.kt | 61 ++++++--- .../factory/express/ExchangeStatusFactory.kt | 14 +- .../ExpressStatusBottomSheetStateProvider.kt | 2 + .../express/MakeExpressShareContent.kt | 123 ++++++++++-------- .../SingleWalletOnrampTransactionConverter.kt | 2 + 9 files changed, 132 insertions(+), 82 deletions(-) diff --git a/common/ui/src/main/java/com/tangem/common/ui/expressStatus/ExpressStatusItems.kt b/common/ui/src/main/java/com/tangem/common/ui/expressStatus/ExpressStatusItems.kt index c52bf8b905..5419047911 100644 --- a/common/ui/src/main/java/com/tangem/common/ui/expressStatus/ExpressStatusItems.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/expressStatus/ExpressStatusItems.kt @@ -216,12 +216,14 @@ private val PreviewExpressTransactionState: ExpressTransactionStateUM = object : toAmountSymbol = "BTC", toCurrencyIcon = CurrencyIconState.Loading, toAddress = "0x", + toAmountDecimals = 2, fromAmount = stringReference("100 SOL"), fromAmountValue = "100".toBigDecimal(), fromFiatAmount = null, fromAmountSymbol = "SOL", fromCurrencyIcon = CurrencyIconState.Loading, fromAddress = "0x", + fromAmountDecimals = 2, ) } // endregion \ No newline at end of file diff --git a/common/ui/src/main/java/com/tangem/common/ui/expressStatus/state/ExpressTransactionStateUM.kt b/common/ui/src/main/java/com/tangem/common/ui/expressStatus/state/ExpressTransactionStateUM.kt index f2c1d7ff28..4131c8fa30 100644 --- a/common/ui/src/main/java/com/tangem/common/ui/expressStatus/state/ExpressTransactionStateUM.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/expressStatus/state/ExpressTransactionStateUM.kt @@ -40,11 +40,13 @@ data class ExpressTransactionStateInfoUM( val toAmount: TextReference, val toAmountValue: BigDecimal, val toFiatAmount: TextReference?, + val toAmountDecimals: Int, val toAmountSymbol: String, val toCurrencyIcon: CurrencyIconState, val toAddress: String, val fromAmount: TextReference, val fromAmountValue: BigDecimal, + val fromAmountDecimals: Int, val fromFiatAmount: TextReference?, val fromAmountSymbol: String, val fromCurrencyIcon: CurrencyIconState, diff --git a/features/tangempay/details/impl/src/main/kotlin/com/tangem/features/tangempay/components/express/PreviewEmptyExpressTransactionsComponent.kt b/features/tangempay/details/impl/src/main/kotlin/com/tangem/features/tangempay/components/express/PreviewEmptyExpressTransactionsComponent.kt index dbba5c5cf0..0567ebae39 100644 --- a/features/tangempay/details/impl/src/main/kotlin/com/tangem/features/tangempay/components/express/PreviewEmptyExpressTransactionsComponent.kt +++ b/features/tangempay/details/impl/src/main/kotlin/com/tangem/features/tangempay/components/express/PreviewEmptyExpressTransactionsComponent.kt @@ -120,12 +120,14 @@ internal class PreviewEmptyExpressTransactionsComponent : ExpressTransactionsCom toAmountSymbol = toSymbol, toCurrencyIcon = CurrencyIconState.Empty(), toAddress = "", + toAmountDecimals = 2, fromAmount = TextReference.Str(fromAmount), fromAmountValue = fromAmount.toBigDecimal(), fromFiatAmount = null, fromAmountSymbol = fromSymbol, fromCurrencyIcon = CurrencyIconState.Empty(), fromAddress = "", + fromAmountDecimals = 2, ), providerName = "Preview Provider", providerImageUrl = "", diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsOnrampTransactionStateConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsOnrampTransactionStateConverter.kt index 89fd4d64b8..1a72f86552 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsOnrampTransactionStateConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsOnrampTransactionStateConverter.kt @@ -61,9 +61,7 @@ internal class TokenDetailsOnrampTransactionStateConverter( ), timestampAgoFormatted = mapFormattedDate(value.timestamp), activeStatus = value.status.toActiveStatusText(cryptoCurrency.name), - toAmount = stringReference( - value.toAmount.format { crypto(cryptoCurrency) }, - ), + toAmount = stringReference(value.toAmount.format { crypto(cryptoCurrency) }), toAmountValue = value.toAmount, toFiatAmount = stringReference( statusValue?.fiatRate?.multiply(value.toAmount).format { @@ -73,6 +71,7 @@ internal class TokenDetailsOnrampTransactionStateConverter( ) }, ), + toAmountDecimals = cryptoCurrency.decimals, toAmountSymbol = cryptoCurrency.symbol, toCurrencyIcon = iconStateConverter.convert(cryptoCurrency), toAddress = statusValue?.networkAddress?.defaultAddress?.value.orEmpty(), @@ -91,6 +90,7 @@ internal class TokenDetailsOnrampTransactionStateConverter( url = value.fromCurrency.image, fallbackResId = R.drawable.ic_currency_24, ), + fromAmountDecimals = value.fromCurrency.precision, fromAddress = null, iconState = value.status.toIconState(), onGoToProviderClick = { url -> diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt index 78b32deba5..8a6ded8831 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt @@ -59,7 +59,7 @@ internal class TokenDetailsSwapTransactionsStateConverter( fun convert( savedTransactions: List, - accountStatuses: Map, + accountStatuses: Map>, ): PersistentList { val result = mutableListOf() @@ -67,29 +67,18 @@ internal class TokenDetailsSwapTransactionsStateConverter( .forEach { swapTransaction -> val toCryptoCurrency = swapTransaction.toCryptoCurrency val fromCryptoCurrency = swapTransaction.fromCryptoCurrency - val toCryptoCurrencyRawId = swapTransaction.toCryptoCurrency.id.rawCurrencyId - val fromCryptoCurrencyRawId = swapTransaction.fromCryptoCurrency.id.rawCurrencyId - var fromCryptoCurrencyStatus: CryptoCurrencyStatus? = null - var toCryptoCurrencyStatus: CryptoCurrencyStatus? = null + + val (fromCryptoCurrencyStatus, toCryptoCurrencyStatus) = extractCryptoCurrencyStatuses( + swapTransaction = swapTransaction, + accountStatuses = accountStatuses, + ) + swapTransaction.transactions.forEach { transaction -> val toAmount = transaction.toCryptoAmount val fromAmount = transaction.fromCryptoAmount - var toFiatAmount: BigDecimal? = null - var fromFiatAmount: BigDecimal? = null - accountStatuses.forEach { (account, cryptoCurrencyStatus) -> - if (cryptoCurrencyStatus.currency.id.rawCurrencyId == fromCryptoCurrencyRawId && - account.userWalletId.stringValue == swapTransaction.fromUserWalletId - ) { - fromFiatAmount = cryptoCurrencyStatus.value.fiatRate?.multiply(fromAmount) - fromCryptoCurrencyStatus = cryptoCurrencyStatus - } - if (cryptoCurrencyStatus.currency.id.rawCurrencyId == toCryptoCurrencyRawId && - account.userWalletId.stringValue == swapTransaction.toUserWalletId - ) { - toFiatAmount = cryptoCurrencyStatus.value.fiatRate?.multiply(toAmount) - toCryptoCurrencyStatus = cryptoCurrencyStatus - } - } + val toFiatAmount = toCryptoCurrencyStatus?.value?.fiatRate?.multiply(toAmount) + val fromFiatAmount = fromCryptoCurrencyStatus?.value?.fiatRate?.multiply(fromAmount) + val statusModel = transaction.status val notification = getNotification( status = statusModel?.status, @@ -153,6 +142,34 @@ internal class TokenDetailsSwapTransactionsStateConverter( ) } + private fun extractCryptoCurrencyStatuses( + swapTransaction: SavedSwapTransactionListModel, + accountStatuses: Map>, + ): Pair { + val toCryptoCurrencyId = swapTransaction.toCryptoCurrency.id + val fromCryptoCurrencyId = swapTransaction.fromCryptoCurrency.id + + var fromCryptoCurrencyStatus: CryptoCurrencyStatus? = null + var toCryptoCurrencyStatus: CryptoCurrencyStatus? = null + + accountStatuses.forEach { (account, cryptoCurrencyStatuses) -> + cryptoCurrencyStatuses.forEach { cryptoCurrencyStatus -> + if (cryptoCurrencyStatus.currency.id == fromCryptoCurrencyId && + account.userWalletId.stringValue == swapTransaction.fromUserWalletId + ) { + fromCryptoCurrencyStatus = cryptoCurrencyStatus + } + if (cryptoCurrencyStatus.currency.id == toCryptoCurrencyId && + account.userWalletId.stringValue == swapTransaction.toUserWalletId + ) { + toCryptoCurrencyStatus = cryptoCurrencyStatus + } + } + } + + return fromCryptoCurrencyStatus to toCryptoCurrencyStatus + } + @Suppress("LongParameterList") private fun createStateInfo( transaction: SavedSwapTransactionModel, @@ -182,12 +199,14 @@ internal class TokenDetailsSwapTransactionsStateConverter( toFiatAmount = getFiatAmount(toFiatAmount), toCurrencyIcon = iconStateConverter.convert(toCryptoCurrency), toAmountSymbol = toCryptoCurrency.symbol, + toAmountDecimals = toCryptoCurrency.decimals, toAddress = toStatusValue?.networkAddress?.defaultAddress?.value.orEmpty(), fromAmount = getCryptoAmount(transaction.fromCryptoAmount, fromCryptoCurrency), fromAmountValue = transaction.fromCryptoAmount, fromFiatAmount = getFiatAmount(fromFiatAmount), fromCurrencyIcon = iconStateConverter.convert(fromCryptoCurrency), fromAmountSymbol = fromCryptoCurrency.symbol, + fromAmountDecimals = fromCryptoCurrency.decimals, fromAddress = fromStatusValue?.networkAddress?.defaultAddress?.value.orEmpty(), onClick = { clickIntents.onExpressTransactionClick(transaction.txId) }, onGoToProviderClick = { url -> diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/express/ExchangeStatusFactory.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/express/ExchangeStatusFactory.kt index 924b9619b7..a3d5d3af06 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/express/ExchangeStatusFactory.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/express/ExchangeStatusFactory.kt @@ -67,13 +67,12 @@ internal class ExchangeStatusFactory @AssistedInject constructor( ).conflate() .map { savedTransactions -> val accountStatuses = savedTransactions - ?.flatMap { swapTransaction -> - setOf( + ?.flatMapTo(mutableSetOf()) { swapTransaction -> + listOf( swapTransaction.fromAccount to swapTransaction.fromCryptoCurrency, swapTransaction.toAccount to swapTransaction.toCryptoCurrency, ) } - ?.toMap() ?.getStatuses() .orEmpty() @@ -199,7 +198,7 @@ internal class ExchangeStatusFactory @AssistedInject constructor( private fun getExchangeStatusState( savedTransactions: List?, - accountStatuses: Map, + accountStatuses: Map>, ): PersistentList { if (savedTransactions == null) { return persistentListOf() @@ -231,7 +230,7 @@ internal class ExchangeStatusFactory @AssistedInject constructor( } } - private suspend fun Map.getStatuses(): Map { + private suspend fun Set>.getStatuses(): Map> { return mapNotNull { (account, cryptoCurrency) -> when (account) { is Account.CryptoPortfolio -> { @@ -248,7 +247,10 @@ internal class ExchangeStatusFactory @AssistedInject constructor( ).getOrNull() else -> null } - }.toMap() + }.groupBy( + keySelector = { (account, _) -> account }, + valueTransform = { (_, status) -> status }, + ) } @AssistedFactory diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/express/ExpressStatusBottomSheetStateProvider.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/express/ExpressStatusBottomSheetStateProvider.kt index cc256b1136..24243614fe 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/express/ExpressStatusBottomSheetStateProvider.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/express/ExpressStatusBottomSheetStateProvider.kt @@ -54,12 +54,14 @@ class ExpressStatusBottomSheetStateProvider : PreviewParameterProvider