diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/ValidateTransactionUseCase.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/ValidateTransactionUseCase.kt index 7ade9be75d..499e222199 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/ValidateTransactionUseCase.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/ValidateTransactionUseCase.kt @@ -6,8 +6,8 @@ import arrow.core.right import com.tangem.blockchain.common.Amount import com.tangem.blockchain.common.transaction.Fee import com.tangem.domain.models.network.Network -import com.tangem.domain.transaction.TransactionRepository import com.tangem.domain.models.wallet.UserWalletId +import com.tangem.domain.transaction.TransactionRepository class ValidateTransactionUseCase( private val transactionRepository: TransactionRepository, @@ -21,8 +21,8 @@ class ValidateTransactionUseCase( destination: String, userWalletId: UserWalletId, network: Network, - ): Either { - return transactionRepository.validateTransaction( + ): Either = Either.catch { + transactionRepository.validateTransaction( amount = amount, fee = fee, memo = memo, diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountQuoteUtils.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountQuoteUtils.kt index d696518b75..d9adf89a0c 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountQuoteUtils.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountQuoteUtils.kt @@ -9,7 +9,7 @@ import com.tangem.domain.swap.models.SwapDirection import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM -import com.tangem.utils.extensions.isZero +import com.tangem.utils.isNullOrZero import java.math.BigDecimal import java.math.RoundingMode import kotlin.math.min @@ -32,12 +32,11 @@ internal object SwapAmountQuoteUtils { secondaryCryptoCurrencyStatus.value.fiatRate to primaryCryptoCurrencyStatus.value.fiatRate } + if (fromRate.isNullOrZero() || toRate.isNullOrZero()) return null + val fromTokenFiatValue = fromTokenAmount.multiply(fromRate) val toTokenFiatValue = toTokenAmount.multiply(toRate) - // Check for zero division - if (fromTokenFiatValue.isZero() || toTokenFiatValue.isZero()) return null - val value = BigDecimal.ONE - toTokenFiatValue.divide(fromTokenFiatValue, 2, RoundingMode.HALF_UP) return stringReference("$(-${value.format { percent(withoutSign = false) }})").takeIf { 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 94f6d53022..b0cfea80d2 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 @@ -11,6 +11,7 @@ import com.tangem.core.decompose.model.getOrCreateModel import com.tangem.core.navigation.url.UrlOpener import com.tangem.core.ui.decompose.ComposableContentComponent import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.swap.models.SwapDirection @@ -104,7 +105,10 @@ internal class SendWithSwapConfirmComponent @AssistedInject constructor( appCurrency = params.appCurrency, callback = model, notificationData = SendNotificationsComponent.Params.NotificationData( - destinationAddress = model.confirmData.enteredDestination.orEmpty(), + destinationAddress = when (val currency = model.primaryCurrencyStatus.currency) { + is CryptoCurrency.Token -> currency.contractAddress + is CryptoCurrency.Coin -> "0" + }, memo = null, amountValue = model.confirmData.enteredAmount.orZero(), reduceAmountBy = model.confirmData.reduceAmountBy.orZero(), diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt index 5ebe7db905..a5aa42ce31 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt @@ -329,7 +329,10 @@ internal class SendWithSwapConfirmModel @Inject constructor( modelScope.launch { sendNotificationsUpdateTrigger.triggerUpdate( data = NotificationData( - destinationAddress = confirmData.enteredDestination.orEmpty(), + destinationAddress = when (val currency = primaryCurrencyStatus.currency) { + is CryptoCurrency.Token -> currency.contractAddress + is CryptoCurrency.Coin -> "0" + }, memo = null, amountValue = confirmData.enteredAmount.orZero(), reduceAmountBy = confirmData.reduceAmountBy,