diff --git a/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt b/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt index 5ccf53357d..af3a5c19f9 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt @@ -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.Common(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( diff --git a/app/src/main/java/com/tangem/tap/features/demo/DemoHelper.kt b/app/src/main/java/com/tangem/tap/features/demo/DemoHelper.kt index 56a60b96a3..83ea251268 100644 --- a/app/src/main/java/com/tangem/tap/features/demo/DemoHelper.kt +++ b/app/src/main/java/com/tangem/tap/features/demo/DemoHelper.kt @@ -6,6 +6,7 @@ import com.tangem.blockchain.common.TransactionSender import com.tangem.blockchain.common.TransactionSigner import com.tangem.blockchain.common.WalletManager import com.tangem.blockchain.common.toBlockchainSdkError +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 @@ -89,9 +90,9 @@ class DemoTransactionSender(private val walletManager: WalletManager) : Transact val blockchain = walletManager.wallet.blockchain return Result.Success( TransactionFee.Choosable( - minimum = Amount(minimumFee, blockchain), - normal = Amount(normalFee, blockchain), - priority = Amount(priorityFee, blockchain) + minimum = Fee.Common(Amount(minimumFee, blockchain)), + normal = Fee.Common(Amount(normalFee, blockchain)), + priority = Fee.Common(Amount(priorityFee, blockchain)) ) ) } diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/saltPay/GnosisRegistrator.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/saltPay/GnosisRegistrator.kt index fb513d2e11..fa982df1c9 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/saltPay/GnosisRegistrator.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/saltPay/GnosisRegistrator.kt @@ -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.Common(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( @@ -215,7 +216,7 @@ class GnosisRegistrator( } is TransactionFee.Choosable -> { val normalFee = (data as TransactionFee.Choosable).normal - Result.Success(normalFee) + Result.Success(normalFee.amount) } } } diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AmountMiddleware.kt b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AmountMiddleware.kt index 15522e87d2..0564218bcd 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AmountMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AmountMiddleware.kt @@ -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)) diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/RequestFeeMiddleware.kt b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/RequestFeeMiddleware.kt index 4e68e14449..1277c0993b 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/RequestFeeMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/RequestFeeMiddleware.kt @@ -56,7 +56,7 @@ class RequestFeeMiddleware { dispatch(FeeAction.FeeCalculation.SetFeeResult(result)) when(result) { is TransactionFee.Single -> { - val fee = result.normal.value ?: BigDecimal.ZERO + val fee = result.normal.amount.value ?: BigDecimal.ZERO if (fee.isZero()) { dispatch(FeeAction.ChangeLayoutVisibility(main = false)) } else { diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt index 2d22340b26..679da154f1 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt @@ -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 diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/FeeReducer.kt b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/FeeReducer.kt index 4c41cf308a..ba706cf281 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/FeeReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/FeeReducer.kt @@ -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 @@ -28,21 +29,17 @@ class FeeReducer : SendInternalReducer { state.copy(controlsLayoutIsVisible = !state.controlsLayoutIsVisible) } is FeeActionUi.ChangeSelectedFee -> { - state.fees?.let { - val currentFee = createValueOfFeeAmount(action.feeType, it) - state.copy( - selectedFeeType = action.feeType, - currentFee = currentFee, - ) - } ?: state - // TODO? + val currentFee = state.fees?.let { + createValueOfFeeAmount(action.feeType, it) + } + state.copy( + selectedFeeType = action.feeType, + currentFee = currentFee + ) } is FeeActionUi.ChangeIncludeFee -> state.copy(feeIsIncluded = action.isIncluded) } - return updateLastState(sendState.copy( - feeState = result, - transactionExtrasState = TransactionExtrasState() - ), result) + return updateLastState(sendState.copy(feeState = result), result) } private fun handleAction(action: FeeAction, sendState: SendState, state: FeeState): SendState { @@ -99,7 +96,7 @@ 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 diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/states/FeeState.kt b/app/src/main/java/com/tangem/tap/features/send/redux/states/FeeState.kt index d1191cf2a4..4fd9516f9a 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/states/FeeState.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/states/FeeState.kt @@ -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 } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/network/exchangeServices/CurrencyExchangeManager.kt b/app/src/main/java/com/tangem/tap/network/exchangeServices/CurrencyExchangeManager.kt index 6be6ffc898..b04348a966 100644 --- a/app/src/main/java/com/tangem/tap/network/exchangeServices/CurrencyExchangeManager.kt +++ b/app/src/main/java/com/tangem/tap/network/exchangeServices/CurrencyExchangeManager.kt @@ -103,7 +103,7 @@ suspend fun CurrencyExchangeManager.buyErc20TestnetTokens( 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) diff --git a/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt b/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt index 7c511dbceb..24b221cc39 100644 --- a/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt +++ b/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt @@ -6,6 +6,7 @@ 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.Fee import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.blockchain.extensions.Result import com.tangem.blockchain.extensions.SimpleResult @@ -99,7 +100,7 @@ class TransactionManagerImpl( ): SendTxResult { val txData = walletManager.createTransaction( amount = amount, - fee = Amount(value = feeAmount, blockchain = blockchain), + fee = Fee.Common(Amount(value = feeAmount, blockchain = blockchain)), destination = destinationAddress, ).copy(hash = dataToSign, extras = createExtras(walletManager, gasLimit, dataToSign)) @@ -200,10 +201,10 @@ class TransactionManagerImpl( // for not EVM blockchains set gasLimit ZERO for now when (fee.data) { is TransactionFee.Single -> { - val amount = (fee.data as TransactionFee.Single).normal + val fee = (fee.data as TransactionFee.Single).normal val singleFee = ProxyFee( gasLimit = BigInteger.ZERO, - fee = convertToProxyAmount(amount = amount), + fee = convertToProxyAmount(amount = fee.amount), ) ProxyFees( minFee = singleFee, @@ -212,19 +213,19 @@ class TransactionManagerImpl( ) } is TransactionFee.Choosable -> { - val setOfThree = fee.data as TransactionFee.Choosable + val choosableFee = fee.data as TransactionFee.Choosable ProxyFees( minFee = ProxyFee( gasLimit = BigInteger.ZERO, - fee = convertToProxyAmount(amount = setOfThree.minimum), + fee = convertToProxyAmount(amount = choosableFee.minimum.amount), ), normalFee = ProxyFee( gasLimit = BigInteger.ZERO, - fee = convertToProxyAmount(amount = setOfThree.normal), + fee = convertToProxyAmount(amount = choosableFee.normal.amount), ), priorityFee = ProxyFee( gasLimit = BigInteger.ZERO, - fee = convertToProxyAmount(amount = setOfThree.priority), + fee = convertToProxyAmount(amount = choosableFee.priority.amount), ) ) } @@ -281,16 +282,16 @@ class TransactionManagerImpl( val choosableFee = fee.data val minProxyFee = ProxyFee( - gasLimit = walletManager.gasLimit ?: BigInteger.ZERO, - fee = convertToProxyAmount(amount = choosableFee.minimum), + gasLimit = (choosableFee.minimum as Fee.Ethereum).gasLimit, + fee = convertToProxyAmount(amount = choosableFee.minimum.amount), ) val normalProxyFee = ProxyFee( - gasLimit = walletManager.gasLimit ?: BigInteger.ZERO, - fee = convertToProxyAmount(amount = choosableFee.normal), + gasLimit = (choosableFee.normal as Fee.Ethereum).gasLimit, + fee = convertToProxyAmount(amount = choosableFee.normal.amount), ) val priorityProxyFee = ProxyFee( - gasLimit = walletManager.gasLimit ?: BigInteger.ZERO, - fee = convertToProxyAmount(amount = choosableFee.priority), + gasLimit = (choosableFee.priority as Fee.Ethereum).gasLimit, + fee = convertToProxyAmount(amount = choosableFee.priority.amount), ) ProxyFees(