Updated on 2026-08-14
This commit is contained in:
parent
d7a120fc86
commit
bd14f694c5
4 changed files with 40 additions and 0 deletions
|
|
@ -7,6 +7,8 @@ import com.tangem.core.decompose.context.AppComponentContext
|
|||
import com.tangem.core.decompose.model.getOrCreateModel
|
||||
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.notifications.model.SwapNotificationsModel
|
||||
import com.tangem.features.swap.v2.impl.notifications.ui.swapNotifications
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
|
@ -40,6 +42,10 @@ internal class SwapNotificationsComponent(
|
|||
data class SwapNotificationData(
|
||||
val expressError: ExpressError?,
|
||||
val fromCryptoCurrency: CryptoCurrency?,
|
||||
val destinationAddress: String,
|
||||
val memo: String? = null,
|
||||
val toCryptoCurrencyStatus: CryptoCurrencyStatus? = null,
|
||||
val userWalletId: UserWalletId? = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.features.swap.v2.impl.notifications.model
|
||||
|
||||
import com.tangem.blockchain.common.BlockchainSdkError
|
||||
import com.tangem.common.ui.notifications.NotificationUM
|
||||
import com.tangem.core.decompose.di.ModelScoped
|
||||
import com.tangem.core.decompose.model.Model
|
||||
|
|
@ -7,6 +8,8 @@ import com.tangem.core.decompose.model.ParamsContainer
|
|||
import com.tangem.core.ui.format.bigdecimal.crypto
|
||||
import com.tangem.core.ui.format.bigdecimal.format
|
||||
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.notifications.DefaultSwapNotificationsUpdateTrigger
|
||||
import com.tangem.features.swap.v2.impl.notifications.SwapNotificationsComponent
|
||||
|
|
@ -14,6 +17,7 @@ import com.tangem.features.swap.v2.impl.notifications.SwapNotificationsComponent
|
|||
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
|
||||
|
|
@ -30,6 +34,7 @@ internal class SwapNotificationsModel @Inject constructor(
|
|||
private val swapNotificationsUpdateListener: SwapNotificationsUpdateListener,
|
||||
private val swapNotificationsUpdateTrigger: DefaultSwapNotificationsUpdateTrigger,
|
||||
private val swapAmountUpdateTrigger: SwapAmountUpdateTrigger,
|
||||
private val validateTransactionUseCase: ValidateTransactionUseCase,
|
||||
paramsContainer: ParamsContainer,
|
||||
) : Model() {
|
||||
|
||||
|
|
@ -61,12 +66,33 @@ internal class SwapNotificationsModel @Inject constructor(
|
|||
private suspend fun buildNotifications() {
|
||||
val notifications = buildList {
|
||||
addExpressErrorNotification()
|
||||
addDestinationTagRequiredNotification()
|
||||
}
|
||||
|
||||
swapNotificationsUpdateTrigger.callbackHasError(notifications.isNotEmpty())
|
||||
uiState.value = notifications.toImmutableList()
|
||||
}
|
||||
|
||||
private suspend fun MutableList<NotificationUM>.addDestinationTagRequiredNotification() {
|
||||
val toCryptoCurrencyStatus = notificationData.toCryptoCurrencyStatus ?: return
|
||||
val userWalletId = notificationData.userWalletId ?: return
|
||||
val destinationAddress = notificationData.destinationAddress
|
||||
if (destinationAddress.isEmpty()) return
|
||||
|
||||
val validationError = validateTransactionUseCase(
|
||||
amount = BigDecimal.ZERO.convertToSdkAmount(toCryptoCurrencyStatus),
|
||||
fee = null,
|
||||
memo = notificationData.memo,
|
||||
destination = destinationAddress,
|
||||
userWalletId = userWalletId,
|
||||
network = toCryptoCurrencyStatus.currency.network,
|
||||
).leftOrNull()
|
||||
|
||||
if (validationError is BlockchainSdkError.DestinationTagRequired) {
|
||||
add(NotificationUM.Error.DestinationTagRequired)
|
||||
}
|
||||
}
|
||||
|
||||
fun MutableList<NotificationUM>.addExpressErrorNotification() {
|
||||
val expressError = notificationData.expressError ?: return
|
||||
val fromCryptoCurrency = notificationData.fromCryptoCurrency ?: return
|
||||
|
|
|
|||
|
|
@ -133,6 +133,10 @@ internal class SendWithSwapConfirmComponent @AssistedInject constructor(
|
|||
swapNotificationData = SwapNotificationsComponent.Params.SwapNotificationData(
|
||||
expressError = (model.confirmData.quote as? SwapQuoteUM.Error)?.expressError,
|
||||
fromCryptoCurrency = model.confirmData.fromCryptoCurrencyStatus?.currency,
|
||||
destinationAddress = model.confirmData.enteredDestination.orEmpty(),
|
||||
memo = model.confirmData.enteredMemo,
|
||||
toCryptoCurrencyStatus = model.confirmData.toCryptoCurrencyStatus,
|
||||
userWalletId = params.userWallet.walletId,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -429,6 +429,10 @@ internal class SendWithSwapConfirmModel @Inject constructor(
|
|||
data = SwapNotificationData(
|
||||
expressError = (confirmData.quote as? SwapQuoteUM.Error)?.expressError,
|
||||
fromCryptoCurrency = confirmData.fromCryptoCurrencyStatus?.currency,
|
||||
destinationAddress = confirmData.enteredDestination.orEmpty(),
|
||||
memo = confirmData.enteredMemo,
|
||||
toCryptoCurrencyStatus = confirmData.toCryptoCurrencyStatus,
|
||||
userWalletId = params.userWallet.walletId,
|
||||
),
|
||||
)
|
||||
uiState.transformerUpdate(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue