Updated on 2026-08-14
This commit is contained in:
parent
5f1f826412
commit
7a177e3467
13 changed files with 274 additions and 100 deletions
|
|
@ -4,16 +4,13 @@ import com.tangem.feature.swap.domain.cache.SwapDataCache
|
|||
import com.tangem.feature.swap.domain.converters.CryptoCurrencyConverter
|
||||
import com.tangem.feature.swap.domain.models.DataError
|
||||
import com.tangem.feature.swap.domain.models.SwapAmount
|
||||
import com.tangem.feature.swap.domain.models.domain.*
|
||||
import com.tangem.feature.swap.domain.models.domain.Currency
|
||||
import com.tangem.feature.swap.domain.models.domain.PermissionOptions
|
||||
import com.tangem.feature.swap.domain.models.domain.PreparedSwapConfigState
|
||||
import com.tangem.feature.swap.domain.models.domain.SwapApproveType
|
||||
import com.tangem.feature.swap.domain.models.toStringWithRightOffset
|
||||
import com.tangem.feature.swap.domain.models.ui.*
|
||||
import com.tangem.lib.crypto.TransactionManager
|
||||
import com.tangem.lib.crypto.UserWalletManager
|
||||
import com.tangem.lib.crypto.models.ProxyFees
|
||||
import com.tangem.lib.crypto.models.ProxyFiatCurrency
|
||||
import com.tangem.lib.crypto.models.*
|
||||
import com.tangem.lib.crypto.models.transactions.SendTxResult
|
||||
import com.tangem.utils.toFiatString
|
||||
import java.math.BigDecimal
|
||||
|
|
@ -115,12 +112,19 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
permissionOptions.approveData.approveModel.data
|
||||
}
|
||||
val result = transactionManager.sendApproveTransaction(
|
||||
networkId = networkId,
|
||||
feeAmount = permissionOptions.txFee.feeValue,
|
||||
gasLimit = permissionOptions.txFee.gasLimit,
|
||||
destinationAddress = permissionOptions.approveData.approveModel.toAddress,
|
||||
dataToSign = dataToSign,
|
||||
txData = ApproveTxData(
|
||||
networkId = networkId,
|
||||
feeAmount = permissionOptions.txFee.feeValue,
|
||||
gasLimit = permissionOptions.txFee.gasLimit,
|
||||
destinationAddress = permissionOptions.approveData.approveModel.toAddress,
|
||||
dataToSign = dataToSign,
|
||||
),
|
||||
derivationPath = derivationPath,
|
||||
analyticsData = AnalyticsData(
|
||||
feeType = permissionOptions.txFee.feeType.getNameForAnalytics(),
|
||||
tokenSymbol = permissionOptions.fromToken.symbol,
|
||||
permissionType = permissionOptions.approveType.getNameForAnalytics(),
|
||||
),
|
||||
)
|
||||
return when (result) {
|
||||
is SendTxResult.Success -> {
|
||||
|
|
@ -188,15 +192,21 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
): TxState {
|
||||
val amount = requireNotNull(toBigDecimalOrNull(amountToSwap)) { "wrong amount format, use only digits" }
|
||||
val result = transactionManager.sendTransaction(
|
||||
networkId = networkId,
|
||||
amountToSend = amount,
|
||||
currencyToSend = cryptoCurrencyConverter.convert(currencyToSend),
|
||||
feeAmount = fee.feeValue,
|
||||
gasLimit = fee.gasLimit,
|
||||
destinationAddress = swapStateData.swapModel.transaction.toWalletAddress,
|
||||
dataToSign = swapStateData.swapModel.transaction.data,
|
||||
txData = SwapTxData(
|
||||
networkId = networkId,
|
||||
amountToSend = amount,
|
||||
currencyToSend = cryptoCurrencyConverter.convert(currencyToSend),
|
||||
feeAmount = fee.feeValue,
|
||||
gasLimit = fee.gasLimit,
|
||||
destinationAddress = swapStateData.swapModel.transaction.toWalletAddress,
|
||||
dataToSign = swapStateData.swapModel.transaction.data,
|
||||
),
|
||||
isSwap = true,
|
||||
derivationPath = derivationPath,
|
||||
analyticsData = AnalyticsData(
|
||||
feeType = fee.feeType.getNameForAnalytics(),
|
||||
tokenSymbol = currencyToSend.symbol,
|
||||
),
|
||||
)
|
||||
return when (result) {
|
||||
is SendTxResult.Success -> {
|
||||
|
|
@ -587,12 +597,14 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
gasLimit = normalFeeGas,
|
||||
feeFiatFormatted = normalFiatFee,
|
||||
feeCryptoFormatted = normalCryptoFee,
|
||||
feeType = FeeType.NORMAL,
|
||||
),
|
||||
priorityFee = TxFee(
|
||||
feeValue = priorityFeeValue,
|
||||
gasLimit = priorityFeeGas,
|
||||
feeFiatFormatted = priorityFiatFee,
|
||||
feeCryptoFormatted = priorityCryptoFee,
|
||||
feeType = FeeType.PRIORITY,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,11 @@ package com.tangem.feature.swap.domain.models.domain
|
|||
|
||||
enum class SwapApproveType {
|
||||
LIMITED, UNLIMITED
|
||||
}
|
||||
|
||||
fun SwapApproveType.getNameForAnalytics(): String {
|
||||
return when (this) {
|
||||
SwapApproveType.LIMITED -> "Transaction"
|
||||
SwapApproveType.UNLIMITED -> "Unlimited"
|
||||
}
|
||||
}
|
||||
|
|
@ -77,4 +77,16 @@ data class TxFee(
|
|||
val gasLimit: Int,
|
||||
val feeFiatFormatted: String,
|
||||
val feeCryptoFormatted: String,
|
||||
)
|
||||
val feeType: FeeType,
|
||||
)
|
||||
|
||||
enum class FeeType {
|
||||
NORMAL, PRIORITY
|
||||
}
|
||||
|
||||
fun FeeType.getNameForAnalytics(): String {
|
||||
return when (this) {
|
||||
FeeType.NORMAL -> "Normal"
|
||||
FeeType.PRIORITY -> "Max"
|
||||
}
|
||||
}
|
||||
|
|
@ -25,6 +25,7 @@ import com.tangem.core.ui.extensions.TextReference
|
|||
import com.tangem.core.ui.extensions.getActiveIconRes
|
||||
import com.tangem.core.ui.extensions.getActiveIconResByCoinId
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.feature.swap.domain.models.ui.FeeType
|
||||
import com.tangem.feature.swap.domain.models.ui.TxFee
|
||||
import com.tangem.feature.swap.models.*
|
||||
import com.tangem.feature.swap.presentation.R
|
||||
|
|
@ -394,6 +395,7 @@ val stateSelectable = SelectableItemsState<TxFee>(
|
|||
gasLimit = 0,
|
||||
feeFiatFormatted = "",
|
||||
feeCryptoFormatted = "",
|
||||
feeType = FeeType.NORMAL,
|
||||
),
|
||||
),
|
||||
items = listOf(
|
||||
|
|
@ -407,6 +409,7 @@ val stateSelectable = SelectableItemsState<TxFee>(
|
|||
gasLimit = 0,
|
||||
feeFiatFormatted = "",
|
||||
feeCryptoFormatted = "",
|
||||
feeType = FeeType.NORMAL,
|
||||
),
|
||||
),
|
||||
Item(
|
||||
|
|
@ -419,6 +422,7 @@ val stateSelectable = SelectableItemsState<TxFee>(
|
|||
gasLimit = 0,
|
||||
feeFiatFormatted = "",
|
||||
feeCryptoFormatted = "",
|
||||
feeType = FeeType.NORMAL,
|
||||
),
|
||||
),
|
||||
).toImmutableList(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue