Updated on 2026-08-14
This commit is contained in:
commit
1ef7da031a
4 changed files with 15 additions and 9 deletions
|
|
@ -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<Throwable, Unit> {
|
||||
return transactionRepository.validateTransaction(
|
||||
): Either<Throwable, Unit> = Either.catch {
|
||||
transactionRepository.validateTransaction(
|
||||
amount = amount,
|
||||
fee = fee,
|
||||
memo = memo,
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue