Updated on 2026-08-14

This commit is contained in:
Tangem 2026-03-27 18:09:56 +05:00
parent 8829f6f12a
commit 70617df9ad
6 changed files with 40 additions and 2 deletions

View file

@ -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?,
)

View file

@ -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,
)
}
}

View file

@ -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,
)
}
}

View file

@ -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<NotificationUM>.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)
}
}

View file

@ -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,

View file

@ -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,
),
),
)