diff --git a/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt b/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt index c622163be0..7253b1fccf 100644 --- a/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt +++ b/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt @@ -31,7 +31,7 @@ fun WalletManagerFactory.makeWalletManagerForApp( val seedKey = wallet.extendedPublicKey return when { scanResponse.cardTypesResolver.isTangemTwins() && scanResponse.secondTwinPublicKey != null -> { - makeTwinWalletManager( + createTwinWalletManager( walletPublicKey = wallet.publicKey, pairPublicKey = scanResponse.secondTwinPublicKey!!.hexToBytes(), blockchain = environmentBlockchain, @@ -47,7 +47,7 @@ fun WalletManagerFactory.makeWalletManagerForApp( val derivedKey = derivedKeys?.get(derivationPath) ?: return null - makeWalletManager( + createWalletManager( blockchain = environmentBlockchain, seedKey = wallet.publicKey, derivedKey = derivedKey, @@ -55,7 +55,7 @@ fun WalletManagerFactory.makeWalletManagerForApp( ) } else -> { - makeWalletManager( + createLegacyWalletManager( blockchain = environmentBlockchain, walletPublicKey = wallet.publicKey, curve = wallet.curve, 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 134a915fbd..6466ac2f85 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 @@ -6,6 +6,7 @@ import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionExtras import com.tangem.blockchain.blockchains.ethereum.EthereumUtils import com.tangem.blockchain.blockchains.ethereum.EthereumUtils.Companion.toKeccak import com.tangem.blockchain.common.* +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 @@ -76,7 +77,8 @@ class WalletConnectSdkHelper { val transactionData = TransactionData( amount = Amount(value, wallet.blockchain), - fee = Amount(fee, wallet.blockchain), + // TODO refactoring + fee = Fee.Common(Amount(fee, wallet.blockchain)), sourceAddress = transaction.from, destinationAddress = transaction.to!!, extras = EthereumTransactionExtras( @@ -182,7 +184,6 @@ class WalletConnectSdkHelper { transactionData = data.transaction, nonce = null, blockchain = data.walletManager.wallet.blockchain, - gasLimit = null, ) ?: 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 cccc4167ae..ef011c6dc1 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,8 @@ 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 import com.tangem.common.CompletionResult @@ -84,13 +86,13 @@ object DemoHelper { class DemoTransactionSender(private val walletManager: WalletManager) : TransactionSender { - override suspend fun getFee(amount: Amount, destination: String): Result> { + override suspend fun getFee(amount: Amount, destination: String): Result { val blockchain = walletManager.wallet.blockchain return Result.Success( - listOf( - Amount(0.0001.toBigDecimal(), blockchain), - Amount(0.0002.toBigDecimal(), blockchain), - Amount(0.0003.toBigDecimal(), blockchain), + TransactionFee.Choosable( + minimum = Fee.Common(Amount(minimumFee, blockchain)), + normal = Fee.Common(Amount(normalFee, blockchain)), + priority = Fee.Common(Amount(priorityFee, blockchain)), ), ) } @@ -120,5 +122,9 @@ class DemoTransactionSender(private val walletManager: WalletManager) : Transact companion object { val ID = DemoTransactionSender::class.java.simpleName + + private val minimumFee = 0.0001.toBigDecimal() + private val normalFee = 0.0002.toBigDecimal() + private val priorityFee = 0.0003.toBigDecimal() } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt b/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt index 5f92c3c10b..cd9ad2160d 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt @@ -4,6 +4,7 @@ import com.tangem.Message import com.tangem.blockchain.common.Amount import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.WalletManager +import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.common.core.TangemSdkError import com.tangem.tap.common.analytics.events.Token.Send.AddressEntered import com.tangem.tap.common.redux.StateDialog @@ -114,7 +115,7 @@ sealed class FeeAction : SendScreenAction { object RequestFee : FeeAction() sealed class FeeCalculation : FeeAction() { - data class SetFeeResult(val fee: List) : FeeCalculation() + data class SetFeeResult(val fee: TransactionFee) : FeeCalculation() object ClearResult : FeeCalculation() } 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 3cbd54e044..efdd59f799 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 @@ -3,6 +3,7 @@ package com.tangem.tap.features.send.redux.middlewares import com.tangem.blockchain.common.Amount import com.tangem.blockchain.common.BlockchainSdkError import com.tangem.blockchain.common.TransactionSender +import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.blockchain.extensions.Result import com.tangem.common.extensions.isZero import com.tangem.tap.common.redux.AppState @@ -53,15 +54,18 @@ class RequestFeeMiddleware { val result = feeResult.data // val result = FeeMock.getFee(walletManager.wallet.blockchain) dispatch(FeeAction.FeeCalculation.SetFeeResult(result)) - if (result.size == 1) { - val fee = result[0].value ?: BigDecimal.ZERO - if (fee.isZero()) { - dispatch(FeeAction.ChangeLayoutVisibility(main = false)) - } else { - dispatch(FeeAction.ChangeLayoutVisibility(main = true, chipGroup = false)) + when (result) { + is TransactionFee.Single -> { + val fee = result.normal.amount.value ?: BigDecimal.ZERO + if (fee.isZero()) { + dispatch(FeeAction.ChangeLayoutVisibility(main = false)) + } else { + dispatch(FeeAction.ChangeLayoutVisibility(main = true, chipGroup = false)) + } + } + is TransactionFee.Choosable -> { + dispatch(FeeAction.ChangeLayoutVisibility(main = true, chipGroup = true)) } - } else { - dispatch(FeeAction.ChangeLayoutVisibility(main = true, chipGroup = true)) } } is Result.Failure -> { 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 af8480549a..69891195d6 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 @@ -9,6 +9,7 @@ import com.tangem.blockchain.blockchains.ton.TonTransactionExtras import com.tangem.blockchain.blockchains.xrp.XrpTransactionBuilder.XrpTransactionExtras import com.tangem.core.navigation.NavigationAction import com.tangem.blockchain.common.* +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 @@ -97,11 +98,11 @@ private fun verifyAndSendTransaction( val card = appState.globalState.scanResponse?.card ?: return val destinationAddress = sendState.addressState.destinationWalletAddress ?: return val typedAmount = sendState.amountState.amountToExtract ?: return - val feeAmount = sendState.feeState.currentFee ?: return + val fee = sendState.feeState.currentFee ?: return val amountToSend = Amount(typedAmount, sendState.getTotalAmountToSend()) - val transactionErrors = walletManager.validateTransaction(amountToSend, feeAmount) + val transactionErrors = walletManager.validateTransaction(amountToSend, fee.amount) when { transactionErrors.contains(TransactionError.TezosSendAll) -> { val reduceAmount = walletManager.wallet.blockchain.minimalAmount() @@ -116,7 +117,7 @@ private fun verifyAndSendTransaction( action = action, walletManager = walletManager, amountToSend = amountToSend, - feeAmount = feeAmount, + fee = fee, feeType = sendState.feeState.selectedFeeType, destinationAddress = destinationAddress, transactionExtras = sendState.transactionExtrasState, @@ -135,7 +136,7 @@ private fun verifyAndSendTransaction( action = action, walletManager = walletManager, amountToSend = amountToSend, - feeAmount = feeAmount, + fee = fee, feeType = sendState.feeState.selectedFeeType, destinationAddress = destinationAddress, transactionExtras = sendState.transactionExtrasState, @@ -153,7 +154,7 @@ private fun sendTransaction( action: SendActionUi.SendAmountToRecipient, walletManager: WalletManager, amountToSend: Amount, - feeAmount: Amount, + fee: Fee, feeType: FeeType, destinationAddress: String, transactionExtras: TransactionExtrasState, @@ -163,7 +164,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())) } @@ -181,7 +182,7 @@ private fun sendTransaction( updateFeedbackManagerInfo( walletManager = walletManager, amountToSend = amountToSend, - feeAmount = feeAmount, + feeAmount = fee.amount, destinationAddress = destinationAddress, ) dispatch(SendAction.Dialog.SendTransactionFails.BlockchainSdkError(error = error)) @@ -276,7 +277,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 d0548132b9..7e2e65171e 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 import com.tangem.tap.features.send.redux.SendScreenAction @@ -13,6 +14,7 @@ import com.tangem.tap.features.wallet.redux.ProgressState [REDACTED_AUTHOR] */ class FeeReducer : SendInternalReducer { + override fun handle(action: SendScreenAction, sendState: SendState): SendState = when (action) { is FeeActionUi -> handleUiAction(action, sendState, sendState.feeState) is FeeAction -> handleAction(action, sendState, sendState.feeState) @@ -25,7 +27,9 @@ class FeeReducer : SendInternalReducer { state.copy(controlsLayoutIsVisible = !state.controlsLayoutIsVisible) } is FeeActionUi.ChangeSelectedFee -> { - val currentFee = createValueOfFeeAmount(action.feeType, state.feeList) + val currentFee = state.fees?.let { + createValueOfFeeAmount(action.feeType, it) + } state.copy( selectedFeeType = action.feeType, currentFee = currentFee, @@ -50,34 +54,36 @@ class FeeReducer : SendInternalReducer { ) } is FeeAction.FeeCalculation.SetFeeResult -> { - val fees = action.fee - if (fees.size == 1) { - val feeType = FeeType.SINGLE - val currentFee = createValueOfFeeAmount(feeType, fees) + when (val fees = action.fee) { + is TransactionFee.Single -> { + val feeType = FeeType.SINGLE + val currentFee = createValueOfFeeAmount(feeType, fees) - state.copy( - selectedFeeType = feeType, - feeList = fees, - currentFee = currentFee, - feeIsApproximate = isFeeApproximate(sendState), - ) - } else { - val feeType = getCurrentFeeType(state) - val currentFee = createValueOfFeeAmount(feeType, fees) + state.copy( + selectedFeeType = feeType, + fees = fees, + currentFee = currentFee, + feeIsApproximate = isFeeApproximate(sendState), + ) + } + is TransactionFee.Choosable -> { + val feeType = getCurrentFeeType(state) + val currentFee = createValueOfFeeAmount(feeType, fees) - state.copy( - selectedFeeType = feeType, - feeList = fees, - currentFee = currentFee, - feeIsApproximate = isFeeApproximate(sendState), - ) + state.copy( + selectedFeeType = feeType, + fees = fees, + currentFee = currentFee, + feeIsApproximate = isFeeApproximate(sendState), + ) + } }.copy( progressState = ProgressState.Done, ) } FeeAction.FeeCalculation.ClearResult -> { state.copy( - feeList = null, + fees = null, currentFee = null, progressState = ProgressState.Done, ) @@ -87,17 +93,18 @@ class FeeReducer : SendInternalReducer { return updateLastState(sendState.copy(feeState = result), result) } - private fun createValueOfFeeAmount(feeType: FeeType, list: List?): Amount? { - if (list == null || list.isEmpty()) return null - - return if (list.size == 1) { - list[0] - } else { - when (feeType) { - FeeType.SINGLE -> list[1] - FeeType.LOW -> list[0] - FeeType.NORMAL -> list[1] - FeeType.PRIORITY -> list[2] + private fun createValueOfFeeAmount(feeType: FeeType, transactionFee: TransactionFee): Fee { + return when (transactionFee) { + is TransactionFee.Single -> { + transactionFee.normal + } + is TransactionFee.Choosable -> { + when (feeType) { + FeeType.SINGLE -> transactionFee.normal + FeeType.LOW -> transactionFee.minimum + FeeType.NORMAL -> transactionFee.normal + FeeType.PRIORITY -> transactionFee.priority + } } } } 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 65067fc0f8..f7a3a5e41b 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.common.analytics.events.AnalyticsParam import com.tangem.tap.features.wallet.redux.ProgressState import java.math.BigDecimal @@ -23,8 +24,8 @@ fun FeeType.convertToAnalyticsFeeType(): AnalyticsParam.FeeType { data class FeeState( val selectedFeeType: FeeType = FeeType.NORMAL, - val feeList: List? = null, - val currentFee: Amount? = null, + val fees: TransactionFee? = null, + val currentFee: Fee? = null, val feeIsIncluded: Boolean = false, val feeIsApproximate: Boolean = false, val mainLayoutIsVisible: Boolean = false, @@ -38,5 +39,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/features/wallet/redux/reducers/WalletReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt index a196a6146b..ac44f59413 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt @@ -1,6 +1,7 @@ package com.tangem.tap.features.wallet.redux.reducers import com.tangem.blockchain.common.Wallet +import com.tangem.blockchain.common.address.AddressType import com.tangem.domain.common.TapWorkarounds.isTestCard import com.tangem.domain.models.scan.CardDTO import com.tangem.tap.common.redux.AppState @@ -151,7 +152,7 @@ fun Wallet.createAddressesData(): List { getShareUri(it.value), getExploreUrl(it.value), ) - if (it.type == blockchain.defaultAddressType()) { + if (it.type == AddressType.Default) { listOfAddressData.add(0, addressData) } else { listOfAddressData.add(addressData) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/MultipleAddressUiHelper.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/MultipleAddressUiHelper.kt index e82c2f9547..c61cb57c3f 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/MultipleAddressUiHelper.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/MultipleAddressUiHelper.kt @@ -1,44 +1,38 @@ package com.tangem.tap.features.wallet.ui import android.view.View -import com.tangem.blockchain.blockchains.bitcoin.BitcoinAddressType -import com.tangem.blockchain.blockchains.cardano.CardanoAddressType import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.address.AddressType import com.tangem.wallet.R object MultipleAddressUiHelper { - fun typeToId(type: AddressType): Int { - return when (type) { - is BitcoinAddressType.Legacy -> R.id.chip_legacy - is BitcoinAddressType.Segwit -> R.id.chip_default - is CardanoAddressType.Byron -> R.id.chip_legacy - is CardanoAddressType.Shelley -> R.id.chip_default - else -> View.NO_ID + + private val blockchainsSupportingSplit = listOf( + Blockchain.Bitcoin, + Blockchain.BitcoinTestnet, + Blockchain.Litecoin, + Blockchain.BitcoinCash, + Blockchain.CardanoShelley, + ) + + fun typeToId(type: AddressType, blockchain: Blockchain): Int { + return if (blockchain in blockchainsSupportingSplit) { + if (type == AddressType.Legacy) { + R.id.chip_legacy + } else { + R.id.chip_default + } + } else { + View.NO_ID } } - fun idToType(id: Int, blockchain: Blockchain?): AddressType? { - return when (id) { - R.id.chip_default -> { - when (blockchain) { - Blockchain.Bitcoin, - Blockchain.BitcoinTestnet, - Blockchain.Litecoin, - Blockchain.BitcoinCash, - -> BitcoinAddressType.Segwit - Blockchain.CardanoShelley -> CardanoAddressType.Shelley - else -> null - } - } - R.id.chip_legacy -> { - when (blockchain) { - Blockchain.Bitcoin, - Blockchain.BitcoinTestnet, - Blockchain.Litecoin, - Blockchain.BitcoinCash, - -> BitcoinAddressType.Legacy - Blockchain.CardanoShelley -> CardanoAddressType.Byron + fun idToType(id: Int, blockchain: Blockchain): AddressType? { + return when (blockchain) { + in blockchainsSupportingSplit -> { + when (id) { + R.id.chip_default -> AddressType.Default + R.id.chip_legacy -> AddressType.Legacy else -> null } } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt index 09946690a4..c6cad8e1bc 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt @@ -390,7 +390,7 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), SafeSt chipGroupAddressType.show() chipGroupAddressType.fitChipsByGroupWidth() - val checkedId = MultipleAddressUiHelper.typeToId(selectedAddress.type) + val checkedId = MultipleAddressUiHelper.typeToId(selectedAddress.type, currency.blockchain) if (checkedId != View.NO_ID) chipGroupAddressType.check(checkedId) chipGroupAddressType.setOnCheckedChangeListener { _, checkedId -> diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt index a97a94e9f3..23a4645bb2 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt @@ -190,7 +190,10 @@ class SingleWalletView : WalletView() { (binding.lAddress.root as? ViewGroup)?.beginDelayedTransition() chipGroupAddressType.show() chipGroupAddressType.fitChipsByGroupWidth() - val checkedId = MultipleAddressUiHelper.typeToId(primaryWallet.walletAddresses.selectedAddress.type) + val checkedId = MultipleAddressUiHelper.typeToId( + primaryWallet.walletAddresses.selectedAddress.type, + primaryWallet.currency.blockchain, + ) if (checkedId != View.NO_ID) chipGroupAddressType.check(checkedId) chipGroupAddressType.setOnCheckedChangeListener { group, checkedId -> 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 a73937a8ee..d886b5873f 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 @@ -72,7 +72,7 @@ class CurrencyExchangeManager( return when (action) { Action.Buy -> buyService Action.Sell -> sellService - } as ExchangeUrlBuilder + } } enum class Action { Buy, Sell } @@ -96,15 +96,14 @@ suspend fun CurrencyExchangeManager.buyErc20TestnetTokens( val amountToSend = Amount(walletManager.wallet.blockchain) val destinationAddress = token.contractAddress - val feeResult = - walletManager.getFee( - amountToSend, - destinationAddress, - ) as? Result.Success ?: return - val fee = feeResult.data[0] + val feeResult = walletManager.getFee( + amountToSend, + destinationAddress, + ) as? Result.Success ?: return + 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 e6090dd5f0..fe86122123 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,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.Fee +import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.blockchain.extensions.Result import com.tangem.blockchain.extensions.SimpleResult import com.tangem.blockchain.extensions.isNetworkError @@ -112,7 +114,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)) @@ -214,24 +216,37 @@ class TransactionManagerImpl( return when (fee) { is Result.Success -> { // for not EVM blockchains set gasLimit ZERO for now - val firstFee = fee.data.firstOrNull() ?: error("no fee found") - val minFee = ProxyFee( - gasLimit = BigInteger.ZERO, - fee = convertToProxyAmount(amount = firstFee), - ) - val normalFee = ProxyFee( - gasLimit = BigInteger.ZERO, - fee = convertToProxyAmount(fee.data.getOrNull(index = 1) ?: firstFee), - ) - val priorityFee = ProxyFee( - gasLimit = BigInteger.ZERO, - fee = convertToProxyAmount(fee.data.getOrNull(index = 2) ?: firstFee), - ) - ProxyFees( - minFee = minFee, - normalFee = normalFee, - priorityFee = priorityFee, - ) + when (fee.data) { + is TransactionFee.Single -> { + val fee = (fee.data as TransactionFee.Single).normal + val singleFee = ProxyFee( + gasLimit = BigInteger.ZERO, + fee = convertToProxyAmount(amount = fee.amount), + ) + ProxyFees( + minFee = singleFee, + normalFee = singleFee, + priorityFee = singleFee, + ) + } + is TransactionFee.Choosable -> { + val choosableFee = fee.data as TransactionFee.Choosable + ProxyFees( + minFee = ProxyFee( + gasLimit = BigInteger.ZERO, + fee = convertToProxyAmount(amount = choosableFee.minimum.amount), + ), + normalFee = ProxyFee( + gasLimit = BigInteger.ZERO, + fee = convertToProxyAmount(amount = choosableFee.normal.amount), + ), + priorityFee = ProxyFee( + gasLimit = BigInteger.ZERO, + fee = convertToProxyAmount(amount = choosableFee.priority.amount), + ), + ) + } + } } is Result.Failure -> { error(fee.error.message ?: fee.error.customMessage) @@ -280,19 +295,21 @@ class TransactionManagerImpl( } return when (fee) { is Result.Success -> { - val minFee = fee.data.firstOrNull() ?: error("no fee found") + val choosableFee = fee.data + val minProxyFee = ProxyFee( - gasLimit = walletManager.gasLimit ?: BigInteger.ZERO, - fee = convertToProxyAmount(minFee), + gasLimit = (choosableFee.minimum as Fee.Ethereum).gasLimit, + fee = convertToProxyAmount(amount = choosableFee.minimum.amount), ) val normalProxyFee = ProxyFee( - gasLimit = walletManager.gasLimit ?: BigInteger.ZERO, - fee = convertToProxyAmount(fee.data.getOrNull(index = 1) ?: minFee), + gasLimit = (choosableFee.normal as Fee.Ethereum).gasLimit, + fee = convertToProxyAmount(amount = choosableFee.normal.amount), ) val priorityProxyFee = ProxyFee( - gasLimit = walletManager.gasLimit ?: BigInteger.ZERO, - fee = convertToProxyAmount(fee.data.lastOrNull() ?: minFee), + gasLimit = (choosableFee.priority as Fee.Ethereum).gasLimit, + fee = convertToProxyAmount(amount = choosableFee.priority.amount), ) + ProxyFees( minFee = minProxyFee, normalFee = normalProxyFee, diff --git a/buildSrc/build/libs/buildSrc.jar b/buildSrc/build/libs/buildSrc.jar new file mode 100644 index 0000000000..270c7fdce9 Binary files /dev/null and b/buildSrc/build/libs/buildSrc.jar differ diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index 9b0fbad374..d2f864a9ab 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -80,7 +80,7 @@ okHttp-prettyLogging = "3.1.0" # endregion Other libraries # region Tangem -tangemBlockchainSdk = "develop-264" +tangemBlockchainSdk = "develop-281" #tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds tangemCardSdk = "develop-273" #tangemCardSdk = "0.0.1" # Keep it! - used for local builds