From 70617df9ad424e34b4798b1f19413d96acb4b6ea Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 27 Mar 2026 18:09:56 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../swap/v2/impl/common/ConfirmData.kt | 2 ++ .../SwapNotificationsComponent.kt | 2 ++ .../entity/SwapNotificationUM.kt | 11 ++++++++ .../model/SwapNotificationsModel.kt | 25 +++++++++++++++++-- .../ui/SwapNotificationsContent.kt | 1 + .../confirm/SendWithSwapConfirmComponent.kt | 1 + 6 files changed, 40 insertions(+), 2 deletions(-) diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/common/ConfirmData.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/common/ConfirmData.kt index f42349e6c2..98d185084b 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/common/ConfirmData.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/common/ConfirmData.kt @@ -6,6 +6,7 @@ import com.tangem.domain.models.account.Account import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.swap.models.SwapAmountType import com.tangem.domain.transaction.error.GetFeeError +import com.tangem.features.swap.v2.impl.amount.entity.PriceImpact import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM import java.math.BigDecimal @@ -24,4 +25,5 @@ internal data class ConfirmData( val quote: SwapQuoteUM?, val rateType: ExpressRateType?, val amountType: SwapAmountType, + val priceImpact: PriceImpact?, ) \ No newline at end of file diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/SwapNotificationsComponent.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/SwapNotificationsComponent.kt index db6c8d8dbe..ecd9813de0 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/SwapNotificationsComponent.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/SwapNotificationsComponent.kt @@ -9,6 +9,7 @@ import com.tangem.domain.express.models.ExpressError import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.wallet.UserWalletId +import com.tangem.features.swap.v2.impl.amount.entity.PriceImpact import java.math.BigDecimal import com.tangem.features.swap.v2.impl.notifications.model.SwapNotificationsModel import com.tangem.features.swap.v2.impl.notifications.ui.swapNotifications @@ -49,6 +50,7 @@ internal class SwapNotificationsComponent( val userWalletId: UserWalletId? = null, val enteredFromAmount: BigDecimal? = null, val fromCryptoCurrencyStatus: CryptoCurrencyStatus? = null, + val priceImpact: PriceImpact? = null, ) } } \ No newline at end of file diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/entity/SwapNotificationUM.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/entity/SwapNotificationUM.kt index fc14191b9b..de64062b75 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/entity/SwapNotificationUM.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/entity/SwapNotificationUM.kt @@ -82,5 +82,16 @@ internal object SwapNotificationUM { onClick = onConfirmClick, ), ) + + data object HighPriceImpact : Warning( + title = resourceReference(R.string.swapping_high_price_impact_title), + subtitle = resourceReference(R.string.swapping_high_price_impact_text), + ) + + data object TradeTooHigh : Warning( + title = resourceReference(R.string.swapping_trade_too_large_title), + subtitle = resourceReference(R.string.swapping_trade_too_large_text), + iconResId = R.drawable.ic_alert_circle_24, + ) } } \ No newline at end of file diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/model/SwapNotificationsModel.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/model/SwapNotificationsModel.kt index 73dc591264..7a265478bb 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/model/SwapNotificationsModel.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/model/SwapNotificationsModel.kt @@ -11,13 +11,13 @@ import com.tangem.domain.express.models.ExpressError import com.tangem.domain.transaction.usecase.ValidateTransactionUseCase import com.tangem.domain.utils.convertToSdkAmount import com.tangem.features.swap.v2.api.subcomponents.SwapAmountUpdateTrigger +import com.tangem.features.swap.v2.impl.amount.entity.PriceImpact import com.tangem.features.swap.v2.impl.notifications.DefaultSwapNotificationsUpdateTrigger import com.tangem.features.swap.v2.impl.notifications.SwapNotificationsComponent import com.tangem.features.swap.v2.impl.notifications.SwapNotificationsComponent.Params.SwapNotificationData import com.tangem.features.swap.v2.impl.notifications.SwapNotificationsUpdateListener import com.tangem.features.swap.v2.impl.notifications.entity.SwapNotificationUM import com.tangem.utils.coroutines.CoroutineDispatcherProvider -import java.math.BigDecimal import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList @@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch +import java.math.BigDecimal import javax.inject.Inject @ModelScoped @@ -68,9 +69,16 @@ internal class SwapNotificationsModel @Inject constructor( addInsufficientFundsNotification() addExpressErrorNotification() addDestinationTagRequiredNotification() + maybeAddPriceImpactNotification() } - swapNotificationsUpdateTrigger.callbackHasError(notifications.isNotEmpty()) + val hasErrorNotification = notifications + .filterNot { notification -> + notification == SwapNotificationUM.Warning.TradeTooHigh || + notification == SwapNotificationUM.Warning.HighPriceImpact + } + .isNotEmpty() + swapNotificationsUpdateTrigger.callbackHasError(hasErrorNotification) uiState.value = notifications.toImmutableList() } @@ -135,4 +143,17 @@ internal class SwapNotificationsModel @Inject constructor( add(errorNotification) } + + private fun MutableList.maybeAddPriceImpactNotification() { + val priceImpact = notificationData.priceImpact ?: return + if (!priceImpact.shouldShowWarning()) return + + val notification = when (priceImpact.type) { + PriceImpact.Type.HIGH -> SwapNotificationUM.Warning.TradeTooHigh + PriceImpact.Type.MEDIUM -> SwapNotificationUM.Warning.HighPriceImpact + else -> return + } + + add(notification) + } } \ No newline at end of file diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/ui/SwapNotificationsContent.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/ui/SwapNotificationsContent.kt index 9f1ec2d283..ae06a1fc78 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/ui/SwapNotificationsContent.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/notifications/ui/SwapNotificationsContent.kt @@ -38,6 +38,7 @@ internal fun LazyListScope.swapNotifications( else -> TangemTheme.colors.button.disabled }, iconTint = when (item) { + is SwapNotificationUM.Warning.TradeTooHigh -> TangemTheme.colors.icon.warning is SwapNotificationUM.Error, is NotificationUM.Error.TokenExceedsBalance, is NotificationUM.Warning, diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/SendWithSwapConfirmComponent.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/SendWithSwapConfirmComponent.kt index 98b57000b7..1b837de7c9 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/SendWithSwapConfirmComponent.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/SendWithSwapConfirmComponent.kt @@ -139,6 +139,7 @@ internal class SendWithSwapConfirmComponent @AssistedInject constructor( userWalletId = params.userWallet.walletId, enteredFromAmount = model.confirmData.enteredFromAmount, fromCryptoCurrencyStatus = model.confirmData.fromCryptoCurrencyStatus, + priceImpact = model.confirmData.priceImpact, ), ), )