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

@ -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
}