Updated on 2026-08-14

This commit is contained in:
Tangem 2023-06-05 12:23:48 +03:00
parent fa6b338401
commit 564e558fcc
8 changed files with 34 additions and 28 deletions

View file

@ -13,6 +13,7 @@ import com.tangem.blockchain.common.TransactionData
import com.tangem.blockchain.common.TransactionSender
import com.tangem.blockchain.common.Wallet
import com.tangem.blockchain.common.WalletManager
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.extensions.Result
import com.tangem.blockchain.extensions.SimpleResult
import com.tangem.blockchain.extensions.hexToBigDecimal
@ -85,7 +86,7 @@ class WalletConnectSdkHelper {
val transactionData = TransactionData(
amount = Amount(value, wallet.blockchain),
fee = Amount(fee, wallet.blockchain),
fee = Fee(Amount(fee, wallet.blockchain)),
sourceAddress = transaction.from,
destinationAddress = transaction.to!!,
extras = EthereumTransactionExtras(
@ -194,8 +195,7 @@ class WalletConnectSdkHelper {
val dataToSign = EthereumUtils.buildTransactionToSign(
transactionData = data.transaction,
nonce = null,
blockchain = data.walletManager.wallet.blockchain,
gasLimit = null,
blockchain = data.walletManager.wallet.blockchain
) ?: return null
val command = SignHashCommand(

View file

@ -9,6 +9,7 @@ import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.BlockchainSdkError
import com.tangem.blockchain.common.TransactionSigner
import com.tangem.blockchain.common.WalletManager
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.blockchain.extensions.Result
import com.tangem.blockchain.extensions.SimpleResult
@ -139,7 +140,7 @@ class GnosisRegistrator(
val compiledEthereumTransaction = walletManager.transactionBuilder.buildApproveToSign(
transactionData = walletManager.createTransaction(
amount = approveAmount,
fee = feeAmount,
fee = Fee(feeAmount),
destination = otpProcessorContractAddress,
),
nonce = atomicNonce.getAndIncrement().toBigInteger(),
@ -190,7 +191,7 @@ class GnosisRegistrator(
val transactionData = walletManager.createTransferFromTransaction(
amount = amount,
fee = hardcodeFeeAmount,
feeAmount = hardcodeFeeAmount,
source = addressTreasureSafe,
)
val transactionToSign = walletManager.transactionBuilder.buildTransferFromToSign(

View file

@ -67,7 +67,7 @@ class AmountMiddleware {
}
val amountToSend = Amount(typedAmount, sendState.getTotalAmountToSend(inputCrypto))
val transactionErrors = walletManager.validateTransaction(amountToSend, sendState.feeState.currentFee)
val transactionErrors = walletManager.validateTransaction(amountToSend, sendState.feeState.currentFee?.amount)
val amountFieldErrors = filterErrorsForAmountField(transactionErrors)
if (amountFieldErrors.isEmpty()) {
dispatch(AmountAction.SetAmountError(null))

View file

@ -12,6 +12,7 @@ import com.tangem.blockchain.common.BlockchainSdkError
import com.tangem.blockchain.common.TransactionError
import com.tangem.blockchain.common.TransactionSender
import com.tangem.blockchain.common.WalletManager
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.extensions.SimpleResult
import com.tangem.common.core.TangemSdkError
import com.tangem.common.extensions.guard
@ -118,11 +119,11 @@ private fun verifyAndSendTransaction(
val card = appState.globalState.scanResponse?.card ?: return
val destinationAddress = sendState.addressPayIdState.destinationWalletAddress ?: return
val typedAmount = sendState.amountState.amountToExtract ?: return
val feeAmount = sendState.feeState.currentFee ?: return
val currentFee = sendState.feeState.currentFee ?: return
val amountToSend = Amount(typedAmount, sendState.getTotalAmountToSend())
val transactionErrors = walletManager.validateTransaction(amountToSend, feeAmount)
val transactionErrors = walletManager.validateTransaction(amountToSend, currentFee.amount)
when {
transactionErrors.contains(TransactionError.TezosSendAll) -> {
val reduceAmount = walletManager.wallet.blockchain.minimalAmount()
@ -134,7 +135,7 @@ private fun verifyAndSendTransaction(
},
sendAllCallback = {
sendTransaction(
action, walletManager, amountToSend, feeAmount, destinationAddress,
action, walletManager, amountToSend, currentFee, destinationAddress,
sendState.transactionExtrasState, card, sendState.externalTransactionData,
dispatch,
)
@ -145,7 +146,7 @@ private fun verifyAndSendTransaction(
}
else -> {
sendTransaction(
action, walletManager, amountToSend, feeAmount, destinationAddress,
action, walletManager, amountToSend, currentFee, destinationAddress,
sendState.transactionExtrasState, card, sendState.externalTransactionData, dispatch,
)
}
@ -157,7 +158,7 @@ private fun sendTransaction(
action: SendActionUi.SendAmountToRecipient,
walletManager: WalletManager,
amountToSend: Amount,
feeAmount: Amount,
fee: Fee,
destinationAddress: String,
transactionExtras: TransactionExtrasState,
card: CardDTO,
@ -165,7 +166,7 @@ private fun sendTransaction(
dispatch: (Action) -> Unit,
) {
dispatch(SendAction.ChangeSendButtonState(ButtonState.PROGRESS))
var txData = walletManager.createTransaction(amountToSend, feeAmount, destinationAddress)
var txData = walletManager.createTransaction(amountToSend, fee, destinationAddress)
transactionExtras.xlmMemo?.memo?.let { txData = txData.copy(extras = StellarTransactionExtras(it)) }
transactionExtras.binanceMemo?.memo?.let { txData = txData.copy(extras = BinanceTransactionExtras(it.toString())) }
@ -185,7 +186,7 @@ private fun sendTransaction(
updateFeedbackManagerInfo(
walletManager = walletManager,
amountToSend = amountToSend,
feeAmount = feeAmount,
feeAmount = fee.amount,
destinationAddress = destinationAddress,
)
dispatch(SendAction.Dialog.SendTransactionFails.BlockchainSdkError(error = error))
@ -266,7 +267,7 @@ private fun sendTransaction(
updateFeedbackManagerInfo(
walletManager = walletManager,
amountToSend = amountToSend,
feeAmount = feeAmount,
feeAmount = fee.amount,
destinationAddress = destinationAddress,
)
val error = sendResult.error as? BlockchainSdkError ?: return@withMainContext

View file

@ -1,6 +1,7 @@
package com.tangem.tap.features.send.redux.reducers
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.tap.features.send.redux.FeeAction
import com.tangem.tap.features.send.redux.FeeActionUi
@ -99,17 +100,17 @@ class FeeReducer : SendInternalReducer {
return updateLastState(sendState.copy(feeState = result), result)
}
private fun createValueOfFeeAmount(feeType: FeeType, transactionFee: TransactionFee): Amount {
private fun createValueOfFeeAmount(feeType: FeeType, transactionFee: TransactionFee): Fee {
return when (transactionFee) {
is TransactionFee.Single -> {
transactionFee.normal.amount
transactionFee.normal
}
is TransactionFee.Choosable -> {
when (feeType) {
FeeType.SINGLE -> transactionFee.normal.amount
FeeType.LOW -> transactionFee.minimum.amount
FeeType.NORMAL -> transactionFee.normal.amount
FeeType.PRIORITY -> transactionFee.priority.amount
FeeType.SINGLE -> transactionFee.normal
FeeType.LOW -> transactionFee.minimum
FeeType.NORMAL -> transactionFee.normal
FeeType.PRIORITY -> transactionFee.priority
}
}
}

View file

@ -1,6 +1,7 @@
package com.tangem.tap.features.send.redux.states
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.tap.features.wallet.redux.ProgressState
import java.math.BigDecimal
@ -15,7 +16,7 @@ enum class FeeType {
data class FeeState(
val selectedFeeType: FeeType = FeeType.NORMAL,
val fees: TransactionFee? = null,
val currentFee: Amount? = null,
val currentFee: Fee? = null,
val feeIsIncluded: Boolean = false,
val feeIsApproximate: Boolean = false,
val mainLayoutIsVisible: Boolean = false,
@ -29,5 +30,5 @@ data class FeeState(
fun isReady(): Boolean = currentFee != null
fun getCurrentFeeValue(): BigDecimal = currentFee?.value ?: BigDecimal.ZERO
fun getCurrentFeeValue(): BigDecimal = currentFee?.amount?.value ?: BigDecimal.ZERO
}

View file

@ -100,10 +100,10 @@ suspend fun CurrencyExchangeManager.buyErc20TestnetTokens(
amountToSend,
destinationAddress,
) as? Result.Success ?: return
val fee = feeResult.data.minimum.amount
val fee = feeResult.data.minimum
val coinValue = walletManager.wallet.amounts[AmountType.Coin]?.value ?: BigDecimal.ZERO
if (coinValue < fee.value) return
if (coinValue < fee.amount.value) return
val transaction = walletManager.createTransaction(amountToSend, fee, destinationAddress)

View file

@ -6,6 +6,8 @@ import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionExtras
import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager
import com.tangem.blockchain.blockchains.optimism.OptimismWalletManager
import com.tangem.blockchain.common.*
import com.tangem.blockchain.common.transaction.EthereumFeeExtras
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.blockchain.extensions.Result
import com.tangem.blockchain.extensions.SimpleResult
@ -99,7 +101,7 @@ class TransactionManagerImpl(
): SendTxResult {
val txData = walletManager.createTransaction(
amount = amount,
fee = Amount(value = feeAmount, blockchain = blockchain),
fee = Fee(Amount(value = feeAmount, blockchain = blockchain)),
destination = destinationAddress,
).copy(hash = dataToSign, extras = createExtras(walletManager, gasLimit, dataToSign))
@ -281,15 +283,15 @@ class TransactionManagerImpl(
val choosableFee = fee.data
val minProxyFee = ProxyFee(
gasLimit = walletManager.gasLimit ?: BigInteger.ZERO,
gasLimit = (choosableFee.minimum.extras as EthereumFeeExtras).gasLimit,
fee = convertToProxyAmount(amount = choosableFee.minimum.amount),
)
val normalProxyFee = ProxyFee(
gasLimit = walletManager.gasLimit ?: BigInteger.ZERO,
gasLimit = (choosableFee.normal.extras as EthereumFeeExtras).gasLimit,
fee = convertToProxyAmount(amount = choosableFee.normal.amount),
)
val priorityProxyFee = ProxyFee(
gasLimit = walletManager.gasLimit ?: BigInteger.ZERO,
gasLimit = (choosableFee.priority.extras as EthereumFeeExtras).gasLimit,
fee = convertToProxyAmount(amount = choosableFee.priority.amount),
)