From a95360aa75213f50af3bddf7128312c0a627de5a Mon Sep 17 00:00:00 2001 From: Anton Paymyshev Date: Thu, 12 Mar 2026 22:13:34 +0700 Subject: [PATCH] Drop gas_estimation field from TxData1559 (#34515) * Drop gas_estimation field from TxData1559 * fix ci * fix ci * fix ci * fix ci * fix ci * fix ci * Address review --- .../crypto_wallet/fragments/TxFragment.java | 509 ++++++++---------- .../brave_wallet/BraveWalletUtilsTest.java | 13 +- .../browser/eip1559_transaction.cc | 178 +----- .../browser/eip1559_transaction.h | 30 +- .../browser/eip1559_transaction_unittest.cc | 112 +--- .../brave_wallet/browser/eth_tx_manager.cc | 81 +-- .../browser/eth_tx_manager_unittest.cc | 90 +--- .../brave_wallet/browser/eth_tx_meta.cc | 7 +- .../browser/eth_tx_meta_unittest.cc | 87 +-- .../browser/eth_tx_state_manager_unittest.cc | 10 +- .../simulation_request_helper_unittest.cc | 13 +- .../browser/simulation_service_unittest.cc | 2 +- .../brave_wallet/common/brave_wallet.mojom | 1 - components/brave_wallet/common/hex_utils.cc | 16 + components/brave_wallet/common/hex_utils.h | 2 + .../brave_wallet/common/hex_utils_unittest.cc | 30 ++ .../brave_wallet_ui/common/constants/mocks.ts | 1 - .../pending_transaction_details.test.tsx | 1 - .../mock-data/mock-account-transactions.ts | 7 - .../mock-data/mock-transaction-info.ts | 29 - .../stories/wallet-extension-panels.tsx | 7 - .../brave_wallet_ui/utils/tx-utils.test.ts | 3 - .../Stores/TransactionConfirmationStore.swift | 2 +- .../PreviewContent/MockContent.swift | 12 +- .../TransactionParserTests.swift | 30 +- 25 files changed, 377 insertions(+), 896 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/TxFragment.java b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/TxFragment.java index 93f0b1de3af..f641d0886d9 100644 --- a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/TxFragment.java +++ b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/TxFragment.java @@ -28,6 +28,7 @@ import org.chromium.brave_wallet.mojom.AssetPrice; import org.chromium.brave_wallet.mojom.BlockchainToken; import org.chromium.brave_wallet.mojom.CoinType; import org.chromium.brave_wallet.mojom.EthTxManagerProxy; +import org.chromium.brave_wallet.mojom.GasEstimation1559; import org.chromium.brave_wallet.mojom.NetworkInfo; import org.chromium.brave_wallet.mojom.SolanaSendTransactionOptions; import org.chromium.brave_wallet.mojom.SolanaTxData; @@ -61,6 +62,7 @@ public class TxFragment extends Fragment { private int mCheckedPriorityId; private int mPreviousCheckedPriorityId; private final long mSolanaEstimatedTxFee; + @Nullable private GasEstimation1559 mEstimation; @Nullable private Dialog mEditGasDialog; // mUpdateTxObjectManually is used to detect do we need to update dialog values @@ -116,6 +118,7 @@ public class TxFragment extends Fragment { mUpdateTxObjectManually = updateTxObjectManually; mSolanaEstimatedTxFee = solanaEstimatedTxFee; mIsSolanaInstruction = TransactionUtils.isSolanaTx(txInfo); + mEstimation = null; } @Override @@ -153,300 +156,7 @@ public class TxFragment extends Fragment { TextView editGasFee = view.findViewById(R.id.edit_gas_fee); editGasFee.setVisibility(isEditTxEnabled(mTxNetwork) ? View.VISIBLE : View.INVISIBLE); - editGasFee.setOnClickListener( - v -> { - if (!canShowDialog()) return; - dismissEditGasDialog(); - mEditGasDialog = new Dialog(requireContext()); - final Dialog dialog = mEditGasDialog; - dialog.setOnDismissListener( - unused -> { - if (mEditGasDialog == dialog) { - mEditGasDialog = null; - } - mFilterEIP1559TextWatcher.clearDialog(); - }); - dialog.setContentView(R.layout.brave_wallet_edit_gas); - dialog.show(); - mPreviousCheckedPriorityId = mCheckedPriorityId; - - LinearLayout gasPriceLayout = dialog.findViewById(R.id.gas_price_layout); - LinearLayout gasLimitLayout = dialog.findViewById(R.id.gas_limit_layout); - if (!mParsedTx.getIsEIP1559Transaction()) { - EditText gasFeeEdit = dialog.findViewById(R.id.gas_fee_edit); - gasFeeEdit.setText( - String.format( - Locale.getDefault(), - "%.0f", - Utils.fromHexWei(mParsedTx.getGasPrice(), 9))); - - EditText gasLimitEdit = dialog.findViewById(R.id.gas_limit_edit); - gasLimitEdit.setText( - String.format( - Locale.getDefault(), - "%.0f", - Utils.fromHexGWeiToGWEI(mParsedTx.getGasLimit()))); - } else { - TextView dialogTitle = dialog.findViewById(R.id.edit_gas_dialog_title); - dialogTitle.setText( - getResources().getString(R.string.wallet_max_priority_fee_title)); - gasPriceLayout.setVisibility(View.GONE); - gasLimitLayout.setVisibility(View.GONE); - dialog.findViewById(R.id.max_priority_fee_msg).setVisibility(View.VISIBLE); - dialog.findViewById(R.id.max_priority_radio_group) - .setVisibility(View.VISIBLE); - RadioGroup radioGroup = dialog.findViewById(R.id.max_priority_radio_group); - radioGroup.clearCheck(); - radioGroup.setOnCheckedChangeListener( - (group, checkedId) -> { - EthTxManagerProxy ethTxManagerProxy = getEthTxManagerProxy(); - assert ethTxManagerProxy != null; - ethTxManagerProxy.getGasEstimation1559( - mTxInfo.chainId, - estimation -> { - mTxInfo.txDataUnion.getEthTxData1559() - .gasEstimation = - estimation; - mCheckedPriorityId = checkedId; - String maxPriorityFeePerGas = - mParsedTx.getMaxPriorityFeePerGas(); - String maxFeePerGas = mParsedTx.getMaxFeePerGas(); - TextView currentBaseFeeMsg = - dialog.findViewById( - R.id.current_base_fee_msg); - currentBaseFeeMsg.setVisibility(View.GONE); - LinearLayout gasAmountLimitLayout = - dialog.findViewById( - R.id.gas_amount_limit_layout); - gasAmountLimitLayout.setVisibility(View.GONE); - LinearLayout perGasTipLimitLayout = - dialog.findViewById( - R.id.per_gas_tip_limit_layout); - perGasTipLimitLayout.setVisibility(View.GONE); - LinearLayout perGasPriceLimitLayout = - dialog.findViewById( - R.id.per_gas_price_limit_layout); - perGasPriceLimitLayout.setVisibility(View.GONE); - if (mCheckedPriorityId == R.id.radio_low) { - maxFeePerGas = - mTxInfo.txDataUnion.getEthTxData1559() - .gasEstimation - .slowMaxFeePerGas; - } else if (mCheckedPriorityId - == R.id.radio_optimal) { - maxFeePerGas = - mTxInfo.txDataUnion.getEthTxData1559() - .gasEstimation - .avgMaxFeePerGas; - } else if (mCheckedPriorityId == R.id.radio_high) { - maxFeePerGas = - mTxInfo.txDataUnion.getEthTxData1559() - .gasEstimation - .fastMaxFeePerGas; - } else if (mCheckedPriorityId - == R.id.radio_custom) { - currentBaseFeeMsg.setVisibility(View.VISIBLE); - currentBaseFeeMsg.setText( - String.format( - getResources() - .getString( - R.string - .wallet_current_base_fee), - String.format( - Locale.getDefault(), - "%.0f", - Utils.fromHexWei( - mTxInfo - .txDataUnion - .getEthTxData1559() - .gasEstimation - .baseFeePerGas, - 9)))); - gasAmountLimitLayout.setVisibility( - View.VISIBLE); - EditText gasAmountLimitEdit = - dialog.findViewById( - R.id.gas_amount_limit_edit); - gasAmountLimitEdit.setText( - String.format( - Locale.getDefault(), - "%.0f", - Utils.fromHexGWeiToGWEI( - mParsedTx - .getGasLimit()))); - perGasTipLimitLayout.setVisibility( - View.VISIBLE); - EditText perGasTipLimitEdit = - dialog.findViewById( - R.id.per_gas_tip_limit_edit); - perGasTipLimitEdit.setText( - String.format( - Locale.getDefault(), - "%.0f", - Utils.fromHexWei( - maxPriorityFeePerGas, - 9))); - perGasPriceLimitLayout.setVisibility( - View.VISIBLE); - EditText perGasPriceLimitEdit = - dialog.findViewById( - R.id.per_gas_price_limit_edit); - perGasPriceLimitEdit.setText( - String.format( - Locale.getDefault(), - "%.0f", - Utils.fromHexWei( - maxFeePerGas, 9))); - mFilterEIP1559TextWatcher.setDialog( - dialog, - String.format( - Locale.getDefault(), - "%.0f", - Utils.fromHexWei( - mTxInfo.txDataUnion - .getEthTxData1559() - .gasEstimation - .baseFeePerGas, - 9))); - gasAmountLimitEdit.addTextChangedListener( - mFilterEIP1559TextWatcher); - perGasTipLimitEdit.addTextChangedListener( - mFilterEIP1559TextWatcher); - perGasPriceLimitEdit.addTextChangedListener( - mFilterEIP1559TextWatcher); - } - fillMaxFee( - dialog.findViewById(R.id.maximum_fee_msg), - mParsedTx.getGasLimit(), - maxFeePerGas); - }); - }); - if (mCheckedPriorityId == -1) { - mCheckedPriorityId = R.id.radio_optimal; - } - radioGroup.check(mCheckedPriorityId); - dialog.findViewById(R.id.maximum_fee_msg).setVisibility(View.VISIBLE); - } - - Button cancel = dialog.findViewById(R.id.cancel); - cancel.setOnClickListener( - v1 -> { - mCheckedPriorityId = mPreviousCheckedPriorityId; - dialog.dismiss(); - }); - Button ok = dialog.findViewById(R.id.ok); - ok.setOnClickListener( - v2 -> { - mPreviousCheckedPriorityId = mCheckedPriorityId; - EthTxManagerProxy ethTxManagerProxy = getEthTxManagerProxy(); - assert ethTxManagerProxy != null; - if (!mParsedTx.getIsEIP1559Transaction()) { - EditText gasLimitEdit = - dialog.findViewById(R.id.gas_limit_edit); - mTxInfo.txDataUnion.getEthTxData1559().baseData.gasLimit = - Utils.toHexGWeiFromGWEI( - gasLimitEdit.getText().toString()); - EditText gasFeeEdit = dialog.findViewById(R.id.gas_fee_edit); - mTxInfo.txDataUnion.getEthTxData1559().baseData.gasPrice = - Utils.toHexWei(gasFeeEdit.getText().toString(), 9); - ethTxManagerProxy.setGasPriceAndLimitForUnapprovedTransaction( - mTxInfo.chainId, - mTxInfo.id, - mTxInfo.txDataUnion.getEthTxData1559() - .baseData - .gasPrice, - mTxInfo.txDataUnion.getEthTxData1559() - .baseData - .gasLimit, - success -> { - if (!success) { - return; - } - if (mUpdateTxObjectManually) { - setupView(view); - } - dialog.dismiss(); - }); - } else { - String gasLimit = mParsedTx.getGasLimit(); - String maxPriorityFeePerGas = - mParsedTx.getMaxPriorityFeePerGas(); - String maxFeePerGas = mParsedTx.getMaxFeePerGas(); - if (mCheckedPriorityId == R.id.radio_low - && mTxInfo.txDataUnion.getEthTxData1559().gasEstimation - != null) { - maxPriorityFeePerGas = - mTxInfo.txDataUnion.getEthTxData1559() - .gasEstimation - .slowMaxPriorityFeePerGas; - maxFeePerGas = - mTxInfo.txDataUnion.getEthTxData1559() - .gasEstimation - .slowMaxFeePerGas; - } else if (mCheckedPriorityId == R.id.radio_optimal - && mTxInfo.txDataUnion.getEthTxData1559().gasEstimation - != null) { - maxPriorityFeePerGas = - mTxInfo.txDataUnion.getEthTxData1559() - .gasEstimation - .avgMaxPriorityFeePerGas; - maxFeePerGas = - mTxInfo.txDataUnion.getEthTxData1559() - .gasEstimation - .avgMaxFeePerGas; - } else if (mCheckedPriorityId == R.id.radio_high - && mTxInfo.txDataUnion.getEthTxData1559().gasEstimation - != null) { - maxPriorityFeePerGas = - mTxInfo.txDataUnion.getEthTxData1559() - .gasEstimation - .fastMaxPriorityFeePerGas; - maxFeePerGas = - mTxInfo.txDataUnion.getEthTxData1559() - .gasEstimation - .fastMaxFeePerGas; - } else if (mCheckedPriorityId == R.id.radio_custom) { - EditText gasAmountLimitEdit = - dialog.findViewById(R.id.gas_amount_limit_edit); - EditText perGasTipLimitEdit = - dialog.findViewById(R.id.per_gas_tip_limit_edit); - EditText perGasPriceLimitEdit = - dialog.findViewById(R.id.per_gas_price_limit_edit); - gasLimit = - Utils.toHexGWeiFromGWEI( - gasAmountLimitEdit.getText().toString()); - maxPriorityFeePerGas = - Utils.toHexWei( - perGasTipLimitEdit.getText().toString(), 9); - maxFeePerGas = - Utils.toHexWei( - perGasPriceLimitEdit.getText().toString(), - 9); - } - mTxInfo.txDataUnion.getEthTxData1559().baseData.gasLimit = - gasLimit; - mTxInfo.txDataUnion.getEthTxData1559().maxPriorityFeePerGas = - maxPriorityFeePerGas; - mTxInfo.txDataUnion.getEthTxData1559().maxFeePerGas = - maxFeePerGas; - ethTxManagerProxy.setGasFeeAndLimitForUnapprovedTransaction( - mTxInfo.chainId, - mTxInfo.id, - maxPriorityFeePerGas, - maxFeePerGas, - gasLimit, - success -> { - if (!success) { - return; - } - if (mUpdateTxObjectManually) { - setupView(view); - } - dialog.dismiss(); - }); - } - }); - }); + editGasFee.setOnClickListener(v -> showEditGasDialog(view)); return view; } @@ -527,6 +237,217 @@ public class TxFragment extends Fragment { } ; + private void showEditGasDialog(View view) { + if (!canShowDialog()) return; + dismissEditGasDialog(); + mEditGasDialog = new Dialog(requireContext()); + mEditGasDialog.setOnDismissListener( + unused -> { + mEditGasDialog = null; + mFilterEIP1559TextWatcher.clearDialog(); + }); + mEditGasDialog.setContentView(R.layout.brave_wallet_edit_gas); + mEditGasDialog.show(); + mPreviousCheckedPriorityId = mCheckedPriorityId; + + LinearLayout gasPriceLayout = mEditGasDialog.findViewById(R.id.gas_price_layout); + LinearLayout gasLimitLayout = mEditGasDialog.findViewById(R.id.gas_limit_layout); + if (!mParsedTx.getIsEIP1559Transaction()) { + EditText gasFeeEdit = mEditGasDialog.findViewById(R.id.gas_fee_edit); + gasFeeEdit.setText( + String.format( + Locale.getDefault(), + "%.0f", + Utils.fromHexWei(mParsedTx.getGasPrice(), 9))); + + EditText gasLimitEdit = mEditGasDialog.findViewById(R.id.gas_limit_edit); + gasLimitEdit.setText( + String.format( + Locale.getDefault(), + "%.0f", + Utils.fromHexGWeiToGWEI(mParsedTx.getGasLimit()))); + } else { + TextView dialogTitle = mEditGasDialog.findViewById(R.id.edit_gas_dialog_title); + dialogTitle.setText(getResources().getString(R.string.wallet_max_priority_fee_title)); + gasPriceLayout.setVisibility(View.GONE); + gasLimitLayout.setVisibility(View.GONE); + mEditGasDialog.findViewById(R.id.max_priority_fee_msg).setVisibility(View.VISIBLE); + mEditGasDialog.findViewById(R.id.max_priority_radio_group).setVisibility(View.VISIBLE); + RadioGroup radioGroup = mEditGasDialog.findViewById(R.id.max_priority_radio_group); + radioGroup.clearCheck(); + radioGroup.setOnCheckedChangeListener( + (group, checkedId) -> { + EthTxManagerProxy ethTxManagerProxy = getEthTxManagerProxy(); + assert ethTxManagerProxy != null; + mCheckedPriorityId = checkedId; + ethTxManagerProxy.getGasEstimation1559( + mTxInfo.chainId, + estimation -> { + mEstimation = estimation; + applyEip1559GasEstimation(); + }); + }); + if (mCheckedPriorityId == -1) { + mCheckedPriorityId = R.id.radio_optimal; + } + radioGroup.check(mCheckedPriorityId); + mEditGasDialog.findViewById(R.id.maximum_fee_msg).setVisibility(View.VISIBLE); + } + + Button cancel = mEditGasDialog.findViewById(R.id.cancel); + cancel.setOnClickListener( + v1 -> { + mCheckedPriorityId = mPreviousCheckedPriorityId; + dismissEditGasDialog(); + }); + Button ok = mEditGasDialog.findViewById(R.id.ok); + ok.setOnClickListener(v2 -> onEditGasDialogOkClicked(view)); + } + + private void applyEip1559GasEstimation() { + if (mEditGasDialog == null) return; + if (mEstimation == null) return; + + String maxPriorityFeePerGas = mParsedTx.getMaxPriorityFeePerGas(); + String maxFeePerGas = mParsedTx.getMaxFeePerGas(); + TextView currentBaseFeeMsg = mEditGasDialog.findViewById(R.id.current_base_fee_msg); + currentBaseFeeMsg.setVisibility(View.GONE); + LinearLayout gasAmountLimitLayout = + mEditGasDialog.findViewById(R.id.gas_amount_limit_layout); + gasAmountLimitLayout.setVisibility(View.GONE); + LinearLayout perGasTipLimitLayout = + mEditGasDialog.findViewById(R.id.per_gas_tip_limit_layout); + perGasTipLimitLayout.setVisibility(View.GONE); + LinearLayout perGasPriceLimitLayout = + mEditGasDialog.findViewById(R.id.per_gas_price_limit_layout); + perGasPriceLimitLayout.setVisibility(View.GONE); + if (mCheckedPriorityId == R.id.radio_low) { + maxFeePerGas = mEstimation.slowMaxFeePerGas; + } else if (mCheckedPriorityId == R.id.radio_optimal) { + maxFeePerGas = mEstimation.avgMaxFeePerGas; + } else if (mCheckedPriorityId == R.id.radio_high) { + maxFeePerGas = mEstimation.fastMaxFeePerGas; + } else if (mCheckedPriorityId == R.id.radio_custom) { + currentBaseFeeMsg.setVisibility(View.VISIBLE); + currentBaseFeeMsg.setText( + String.format( + getResources().getString(R.string.wallet_current_base_fee), + String.format( + Locale.getDefault(), + "%.0f", + Utils.fromHexWei(mEstimation.baseFeePerGas, 9)))); + gasAmountLimitLayout.setVisibility(View.VISIBLE); + EditText gasAmountLimitEdit = mEditGasDialog.findViewById(R.id.gas_amount_limit_edit); + gasAmountLimitEdit.setText( + String.format( + Locale.getDefault(), + "%.0f", + Utils.fromHexGWeiToGWEI(mParsedTx.getGasLimit()))); + perGasTipLimitLayout.setVisibility(View.VISIBLE); + EditText perGasTipLimitEdit = mEditGasDialog.findViewById(R.id.per_gas_tip_limit_edit); + perGasTipLimitEdit.setText( + String.format( + Locale.getDefault(), + "%.0f", + Utils.fromHexWei(maxPriorityFeePerGas, 9))); + perGasPriceLimitLayout.setVisibility(View.VISIBLE); + EditText perGasPriceLimitEdit = + mEditGasDialog.findViewById(R.id.per_gas_price_limit_edit); + perGasPriceLimitEdit.setText( + String.format(Locale.getDefault(), "%.0f", Utils.fromHexWei(maxFeePerGas, 9))); + mFilterEIP1559TextWatcher.setDialog( + mEditGasDialog, + String.format( + Locale.getDefault(), + "%.0f", + Utils.fromHexWei(mEstimation.baseFeePerGas, 9))); + gasAmountLimitEdit.addTextChangedListener(mFilterEIP1559TextWatcher); + perGasTipLimitEdit.addTextChangedListener(mFilterEIP1559TextWatcher); + perGasPriceLimitEdit.addTextChangedListener(mFilterEIP1559TextWatcher); + } + fillMaxFee( + mEditGasDialog.findViewById(R.id.maximum_fee_msg), + mParsedTx.getGasLimit(), + maxFeePerGas); + } + + private void onEditGasDialogOkClicked(View view) { + if (mEditGasDialog == null) return; + + mPreviousCheckedPriorityId = mCheckedPriorityId; + EthTxManagerProxy ethTxManagerProxy = getEthTxManagerProxy(); + assert ethTxManagerProxy != null; + if (!mParsedTx.getIsEIP1559Transaction()) { + EditText gasLimitEdit = mEditGasDialog.findViewById(R.id.gas_limit_edit); + mTxInfo.txDataUnion.getEthTxData1559().baseData.gasLimit = + Utils.toHexGWeiFromGWEI(gasLimitEdit.getText().toString()); + EditText gasFeeEdit = mEditGasDialog.findViewById(R.id.gas_fee_edit); + mTxInfo.txDataUnion.getEthTxData1559().baseData.gasPrice = + Utils.toHexWei(gasFeeEdit.getText().toString(), 9); + ethTxManagerProxy.setGasPriceAndLimitForUnapprovedTransaction( + mTxInfo.chainId, + mTxInfo.id, + mTxInfo.txDataUnion.getEthTxData1559().baseData.gasPrice, + mTxInfo.txDataUnion.getEthTxData1559().baseData.gasLimit, + success -> { + if (!success) { + return; + } + if (mUpdateTxObjectManually) { + setupView(view); + } + if (mEditGasDialog != null) { + mEditGasDialog.dismiss(); + } + }); + } else { + if (mEstimation == null) { + return; + } + String gasLimit = mParsedTx.getGasLimit(); + String maxPriorityFeePerGas = mParsedTx.getMaxPriorityFeePerGas(); + String maxFeePerGas = mParsedTx.getMaxFeePerGas(); + if (mCheckedPriorityId == R.id.radio_low) { + maxPriorityFeePerGas = mEstimation.slowMaxPriorityFeePerGas; + maxFeePerGas = mEstimation.slowMaxFeePerGas; + } else if (mCheckedPriorityId == R.id.radio_optimal) { + maxPriorityFeePerGas = mEstimation.avgMaxPriorityFeePerGas; + maxFeePerGas = mEstimation.avgMaxFeePerGas; + } else if (mCheckedPriorityId == R.id.radio_high) { + maxPriorityFeePerGas = mEstimation.fastMaxPriorityFeePerGas; + maxFeePerGas = mEstimation.fastMaxFeePerGas; + } else if (mCheckedPriorityId == R.id.radio_custom) { + EditText gasAmountLimitEdit = + mEditGasDialog.findViewById(R.id.gas_amount_limit_edit); + EditText perGasTipLimitEdit = + mEditGasDialog.findViewById(R.id.per_gas_tip_limit_edit); + EditText perGasPriceLimitEdit = + mEditGasDialog.findViewById(R.id.per_gas_price_limit_edit); + gasLimit = Utils.toHexGWeiFromGWEI(gasAmountLimitEdit.getText().toString()); + maxPriorityFeePerGas = Utils.toHexWei(perGasTipLimitEdit.getText().toString(), 9); + maxFeePerGas = Utils.toHexWei(perGasPriceLimitEdit.getText().toString(), 9); + } + mTxInfo.txDataUnion.getEthTxData1559().baseData.gasLimit = gasLimit; + mTxInfo.txDataUnion.getEthTxData1559().maxPriorityFeePerGas = maxPriorityFeePerGas; + mTxInfo.txDataUnion.getEthTxData1559().maxFeePerGas = maxFeePerGas; + ethTxManagerProxy.setGasFeeAndLimitForUnapprovedTransaction( + mTxInfo.chainId, + mTxInfo.id, + maxPriorityFeePerGas, + maxFeePerGas, + gasLimit, + success -> { + if (mEditGasDialog == null) return; + if (!success) return; + + if (mUpdateTxObjectManually) { + setupView(view); + } + mEditGasDialog.dismiss(); + }); + } + } + private void fillMaxFee(TextView textView, String gasLimit, String maxFeePerGas) { final double[] gasFeeArr = ParsedTransactionFees.calcGasFee( diff --git a/android/javatests/org/chromium/chrome/browser/brave_wallet/BraveWalletUtilsTest.java b/android/javatests/org/chromium/chrome/browser/brave_wallet/BraveWalletUtilsTest.java index b3b9905870e..5c0b66ec3d9 100644 --- a/android/javatests/org/chromium/chrome/browser/brave_wallet/BraveWalletUtilsTest.java +++ b/android/javatests/org/chromium/chrome/browser/brave_wallet/BraveWalletUtilsTest.java @@ -431,9 +431,10 @@ public class BraveWalletUtilsTest { java.lang.Object v = f.get(testStruct); if (!t.isPrimitive()) { String varName = f.getName(); - if (varName.equals("baseData") || varName.equals("chainId") + if (varName.equals("baseData") + || varName.equals("chainId") || varName.equals("maxPriorityFeePerGas") - || varName.equals("maxFeePerGas") || varName.equals("gasEstimation")) { + || varName.equals("maxFeePerGas")) { continue; } if (v == null) { @@ -463,14 +464,6 @@ public class BraveWalletUtilsTest { testStruct.chainId = ""; testStruct.maxPriorityFeePerGas = ""; testStruct.maxFeePerGas = ""; - testStruct.gasEstimation = new GasEstimation1559(); - testStruct.gasEstimation.slowMaxPriorityFeePerGas = ""; - testStruct.gasEstimation.slowMaxFeePerGas = ""; - testStruct.gasEstimation.avgMaxPriorityFeePerGas = ""; - testStruct.gasEstimation.avgMaxFeePerGas = ""; - testStruct.gasEstimation.fastMaxPriorityFeePerGas = ""; - testStruct.gasEstimation.fastMaxFeePerGas = ""; - testStruct.gasEstimation.baseFeePerGas = ""; try { java.nio.ByteBuffer byteBuffer = testStruct.serialize(); TxData1559 testStructDeserialized = TxData1559.deserialize(byteBuffer); diff --git a/components/brave_wallet/browser/eip1559_transaction.cc b/components/brave_wallet/browser/eip1559_transaction.cc index 37d8dfe44f5..62edc206ada 100644 --- a/components/brave_wallet/browser/eip1559_transaction.cc +++ b/components/brave_wallet/browser/eip1559_transaction.cc @@ -5,7 +5,6 @@ #include "brave/components/brave_wallet/browser/eip1559_transaction.h" -#include #include #include @@ -18,83 +17,6 @@ namespace brave_wallet { -// static -std::optional -Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - mojom::GasEstimation1559Ptr gas_estimation) { - if (!gas_estimation) { - return std::nullopt; - } - - GasEstimation estimation; - if (!HexValueToUint256(gas_estimation->slow_max_priority_fee_per_gas, - &estimation.slow_max_priority_fee_per_gas)) { - return std::nullopt; - } - if (!HexValueToUint256(gas_estimation->avg_max_priority_fee_per_gas, - &estimation.avg_max_priority_fee_per_gas)) { - return std::nullopt; - } - if (!HexValueToUint256(gas_estimation->fast_max_priority_fee_per_gas, - &estimation.fast_max_priority_fee_per_gas)) { - return std::nullopt; - } - if (!HexValueToUint256(gas_estimation->slow_max_fee_per_gas, - &estimation.slow_max_fee_per_gas)) { - return std::nullopt; - } - if (!HexValueToUint256(gas_estimation->avg_max_fee_per_gas, - &estimation.avg_max_fee_per_gas)) { - return std::nullopt; - } - if (!HexValueToUint256(gas_estimation->fast_max_fee_per_gas, - &estimation.fast_max_fee_per_gas)) { - return std::nullopt; - } - if (!HexValueToUint256(gas_estimation->base_fee_per_gas, - &estimation.base_fee_per_gas)) { - return std::nullopt; - } - - return estimation; -} - -// static -mojom::GasEstimation1559Ptr -Eip1559Transaction::GasEstimation::ToMojomGasEstimation1559( - Eip1559Transaction::GasEstimation gas_estimation) { - mojom::GasEstimation1559Ptr estimation = mojom::GasEstimation1559::New(); - estimation->slow_max_priority_fee_per_gas = - Uint256ValueToHex(gas_estimation.slow_max_priority_fee_per_gas); - estimation->avg_max_priority_fee_per_gas = - Uint256ValueToHex(gas_estimation.avg_max_priority_fee_per_gas); - estimation->fast_max_priority_fee_per_gas = - Uint256ValueToHex(gas_estimation.fast_max_priority_fee_per_gas); - estimation->slow_max_fee_per_gas = - Uint256ValueToHex(gas_estimation.slow_max_fee_per_gas); - estimation->avg_max_fee_per_gas = - Uint256ValueToHex(gas_estimation.avg_max_fee_per_gas); - estimation->fast_max_fee_per_gas = - Uint256ValueToHex(gas_estimation.fast_max_fee_per_gas); - estimation->base_fee_per_gas = - Uint256ValueToHex(gas_estimation.base_fee_per_gas); - return estimation; -} - -bool Eip1559Transaction::GasEstimation::operator==( - const Eip1559Transaction::GasEstimation& estimation) const { - return slow_max_priority_fee_per_gas == - estimation.slow_max_priority_fee_per_gas && - avg_max_priority_fee_per_gas == - estimation.avg_max_priority_fee_per_gas && - fast_max_priority_fee_per_gas == - estimation.fast_max_priority_fee_per_gas && - slow_max_fee_per_gas == estimation.slow_max_fee_per_gas && - avg_max_fee_per_gas == estimation.avg_max_fee_per_gas && - fast_max_fee_per_gas == estimation.fast_max_fee_per_gas && - base_fee_per_gas == estimation.base_fee_per_gas; -} - Eip1559Transaction::Eip1559Transaction() : max_priority_fee_per_gas_(0), max_fee_per_gas_(0) { type_ = 2; @@ -109,8 +31,7 @@ Eip1559Transaction::Eip1559Transaction( const std::vector& data, uint256_t chain_id, uint256_t max_priority_fee_per_gas, - uint256_t max_fee_per_gas, - GasEstimation gas_estimation) + uint256_t max_fee_per_gas) : Eip2930Transaction(nonce, gas_price, gas_limit, @@ -119,8 +40,7 @@ Eip1559Transaction::Eip1559Transaction( data, chain_id), max_priority_fee_per_gas_(max_priority_fee_per_gas), - max_fee_per_gas_(max_fee_per_gas), - gas_estimation_(gas_estimation) { + max_fee_per_gas_(max_fee_per_gas) { type_ = 2; } Eip1559Transaction::Eip1559Transaction(const Eip1559Transaction&) = default; @@ -159,18 +79,10 @@ std::optional Eip1559Transaction::FromTxData( return std::nullopt; } - GasEstimation gas_estimation; - auto estimation = GasEstimation::FromMojomGasEstimation1559( - std::move(tx_data1559->gas_estimation)); - if (estimation) { - gas_estimation = estimation.value(); - } - - Eip1559Transaction tx( + return Eip1559Transaction( tx_2930->nonce(), tx_2930->gas_price(), tx_2930->gas_limit(), tx_2930->to(), tx_2930->value(), tx_2930->data(), tx_2930->chain_id(), - max_priority_fee_per_gas, max_fee_per_gas, gas_estimation); - return tx; + max_priority_fee_per_gas, max_fee_per_gas); } // static @@ -202,70 +114,10 @@ std::optional Eip1559Transaction::FromValue( return std::nullopt; } - GasEstimation estimation; - const base::DictValue* estimation_dict = value.FindDict("gas_estimation"); - if (estimation_dict) { - const std::string* tx_slow_max_priority_fee_per_gas = - estimation_dict->FindString("slow_max_priority_fee_per_gas"); - if (!tx_slow_max_priority_fee_per_gas || - !HexValueToUint256(*tx_slow_max_priority_fee_per_gas, - &estimation.slow_max_priority_fee_per_gas)) { - return std::nullopt; - } - - const std::string* tx_avg_max_priority_fee_per_gas = - estimation_dict->FindString("avg_max_priority_fee_per_gas"); - if (!tx_avg_max_priority_fee_per_gas || - !HexValueToUint256(*tx_avg_max_priority_fee_per_gas, - &estimation.avg_max_priority_fee_per_gas)) { - return std::nullopt; - } - - const std::string* tx_fast_max_priority_fee_per_gas = - estimation_dict->FindString("fast_max_priority_fee_per_gas"); - if (!tx_fast_max_priority_fee_per_gas || - !HexValueToUint256(*tx_fast_max_priority_fee_per_gas, - &estimation.fast_max_priority_fee_per_gas)) { - return std::nullopt; - } - - const std::string* tx_slow_max_fee_per_gas = - estimation_dict->FindString("slow_max_fee_per_gas"); - if (!tx_slow_max_fee_per_gas || - !HexValueToUint256(*tx_slow_max_fee_per_gas, - &estimation.slow_max_fee_per_gas)) { - return std::nullopt; - } - - const std::string* tx_avg_max_fee_per_gas = - estimation_dict->FindString("avg_max_fee_per_gas"); - if (!tx_avg_max_fee_per_gas || - !HexValueToUint256(*tx_avg_max_fee_per_gas, - &estimation.avg_max_fee_per_gas)) { - return std::nullopt; - } - - const std::string* tx_fast_max_fee_per_gas = - estimation_dict->FindString("fast_max_fee_per_gas"); - if (!tx_fast_max_fee_per_gas || - !HexValueToUint256(*tx_fast_max_fee_per_gas, - &estimation.fast_max_fee_per_gas)) { - return std::nullopt; - } - - const std::string* tx_base_fee_per_gas = - estimation_dict->FindString("base_fee_per_gas"); - if (!tx_base_fee_per_gas || - !HexValueToUint256(*tx_base_fee_per_gas, - &estimation.base_fee_per_gas)) { - return std::nullopt; - } - } - Eip1559Transaction tx(tx_2930->nonce(), tx_2930->gas_price(), tx_2930->gas_limit(), tx_2930->to(), tx_2930->value(), tx_2930->data(), tx_2930->chain_id(), - max_priority_fee_per_gas, max_fee_per_gas, estimation); + max_priority_fee_per_gas, max_fee_per_gas); tx.v_ = tx_2930->v(); tx.r_ = tx_2930->r(); tx.s_ = tx_2930->s(); @@ -317,26 +169,6 @@ base::DictValue Eip1559Transaction::ToValue() const { Uint256ValueToHex(max_priority_fee_per_gas_)); tx.Set("max_fee_per_gas", Uint256ValueToHex(max_fee_per_gas_)); - base::DictValue& estimation = - tx.Set("gas_estimation", base::DictValue())->GetDict(); - estimation.Set( - "slow_max_priority_fee_per_gas", - Uint256ValueToHex(gas_estimation_.slow_max_priority_fee_per_gas)); - estimation.Set( - "avg_max_priority_fee_per_gas", - Uint256ValueToHex(gas_estimation_.avg_max_priority_fee_per_gas)); - estimation.Set( - "fast_max_priority_fee_per_gas", - Uint256ValueToHex(gas_estimation_.fast_max_priority_fee_per_gas)); - estimation.Set("slow_max_fee_per_gas", - Uint256ValueToHex(gas_estimation_.slow_max_fee_per_gas)); - estimation.Set("avg_max_fee_per_gas", - Uint256ValueToHex(gas_estimation_.avg_max_fee_per_gas)); - estimation.Set("fast_max_fee_per_gas", - Uint256ValueToHex(gas_estimation_.fast_max_fee_per_gas)); - estimation.Set("base_fee_per_gas", - Uint256ValueToHex(gas_estimation_.base_fee_per_gas)); - return tx; } diff --git a/components/brave_wallet/browser/eip1559_transaction.h b/components/brave_wallet/browser/eip1559_transaction.h index 7bf02d46010..6b1a109c2f0 100644 --- a/components/brave_wallet/browser/eip1559_transaction.h +++ b/components/brave_wallet/browser/eip1559_transaction.h @@ -16,26 +16,6 @@ namespace brave_wallet { class Eip1559Transaction : public Eip2930Transaction { public: - struct GasEstimation { - GasEstimation() = default; - ~GasEstimation() = default; - GasEstimation(const GasEstimation&) = default; - bool operator==(const GasEstimation&) const; - - static std::optional FromMojomGasEstimation1559( - mojom::GasEstimation1559Ptr gas_estimation); - static mojom::GasEstimation1559Ptr ToMojomGasEstimation1559( - GasEstimation gas_estimation); - - uint256_t slow_max_priority_fee_per_gas = 0; - uint256_t avg_max_priority_fee_per_gas = 0; - uint256_t fast_max_priority_fee_per_gas = 0; - uint256_t slow_max_fee_per_gas = 0; - uint256_t avg_max_fee_per_gas = 0; - uint256_t fast_max_fee_per_gas = 0; - uint256_t base_fee_per_gas = 0; - }; - Eip1559Transaction(); Eip1559Transaction(const Eip1559Transaction&); ~Eip1559Transaction() override; @@ -51,7 +31,6 @@ class Eip1559Transaction : public Eip2930Transaction { return max_priority_fee_per_gas_; } uint256_t max_fee_per_gas() const { return max_fee_per_gas_; } - GasEstimation gas_estimation() const { return gas_estimation_; } void set_max_fee_per_gas(uint256_t max_fee_per_gas) { max_fee_per_gas_ = max_fee_per_gas; @@ -59,9 +38,6 @@ class Eip1559Transaction : public Eip2930Transaction { void set_max_priority_fee_per_gas(uint256_t max_priority_fee_per_gas) { max_priority_fee_per_gas_ = max_priority_fee_per_gas; } - void set_gas_estimation(GasEstimation estimation) { - gas_estimation_ = estimation; - } // 0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, // gasLimit, destination, value, data, access_list]) @@ -89,15 +65,11 @@ class Eip1559Transaction : public Eip2930Transaction { const std::vector& data, uint256_t chain_id, uint256_t max_priority_fee_per_gas, - uint256_t max_fee_per_gas, - GasEstimation gas_estimation); + uint256_t max_fee_per_gas); uint256_t max_priority_fee_per_gas_; uint256_t max_fee_per_gas_; - // Gas estimation result - GasEstimation gas_estimation_; - bool VIsRecid() const override; private: diff --git a/components/brave_wallet/browser/eip1559_transaction_unittest.cc b/components/brave_wallet/browser/eip1559_transaction_unittest.cc index 2d0b6b7d63c..025da91cf91 100644 --- a/components/brave_wallet/browser/eip1559_transaction_unittest.cc +++ b/components/brave_wallet/browser/eip1559_transaction_unittest.cc @@ -18,18 +18,6 @@ namespace brave_wallet { -namespace { - -mojom::GasEstimation1559Ptr GetMojomGasEstimation() { - return mojom::GasEstimation1559::New( - "0x3b9aca00" /* Hex of 1 * 1e9 */, "0xaf16b1600" /* Hex of 47 * 1e9 */, - "0x77359400" /* Hex of 2 * 1e9 */, "0xb2d05e000" /* Hex of 48 * 1e9 */, - "0xb2d05e00" /* Hex of 3 * 1e9 */, "0xb68a0aa00" /* Hex of 49 * 1e9 */, - "0xad8075b7a" /* Hex of 46574033786 */); -} - -} // namespace - TEST(Eip1559TransactionUnitTest, GetMessageToSign) { std::vector data; EXPECT_TRUE(base::HexStringToBytes("010200", &data)); @@ -38,7 +26,7 @@ TEST(Eip1559TransactionUnitTest, GetMessageToSign) { mojom::TxData::New("0x00", "0x00", "0x00", "0x0101010101010101010101010101010101010101", "0x00", data, false, std::nullopt), - "0x04", "0x0", "0x0", nullptr)); + "0x04", "0x0", "0x0")); ASSERT_EQ(tx.type(), 2); auto* access_list = tx.access_list(); Eip2930Transaction::AccessListItem item; @@ -139,8 +127,7 @@ TEST(Eip1559TransactionUnitTest, GetSignedTransactionAndHash) { "0x000000000000000000000000000000000000aaaa", entry.value, std::vector(), false, std::nullopt), - "0x04", entry.max_priority_fee_per_gas, entry.max_fee_per_gas, - nullptr)); + "0x04", entry.max_priority_fee_per_gas, entry.max_fee_per_gas)); auto signature = *key->SignCompact(tx.GetHashedMessageToSign(0)); tx.ProcessSignature(signature, 0); @@ -156,7 +143,7 @@ TEST(Eip1559TransactionUnitTest, Serialization) { "0x3535353535353535353535353535353535353535", "0xde0b6b3a7640000", std::vector(), false, std::nullopt), - "0x15BE", "0x7B", "0x1C8", GetMojomGasEstimation())); + "0x15BE", "0x7B", "0x1C8")); auto* access_list = tx.access_list(); @@ -178,7 +165,7 @@ TEST(Eip1559TransactionUnitTest, FromTxData) { mojom::TxData::New("0x01", "0x3E8", "0x989680", "0x3535353535353535353535353535353535353535", "0x2A", std::vector{1}, false, std::nullopt), - "0x15BE", "0x7B", "0x1C8", GetMojomGasEstimation())); + "0x15BE", "0x7B", "0x1C8")); ASSERT_TRUE(tx); EXPECT_EQ(tx->nonce().value(), uint256_t(1)); EXPECT_EQ(tx->gas_price(), uint256_t(1000)); @@ -189,25 +176,13 @@ TEST(Eip1559TransactionUnitTest, FromTxData) { EXPECT_EQ(tx->chain_id(), uint256_t(5566)); EXPECT_EQ(tx->max_priority_fee_per_gas(), uint256_t(123)); EXPECT_EQ(tx->max_fee_per_gas(), uint256_t(456)); - EXPECT_EQ(tx->gas_estimation().slow_max_priority_fee_per_gas, uint256_t(1e9)); - EXPECT_EQ(tx->gas_estimation().avg_max_priority_fee_per_gas, - uint256_t(2) * uint256_t(1e9)); - EXPECT_EQ(tx->gas_estimation().fast_max_priority_fee_per_gas, - uint256_t(3) * uint256_t(1e9)); - EXPECT_EQ(tx->gas_estimation().slow_max_fee_per_gas, - uint256_t(47) * uint256_t(1e9)); - EXPECT_EQ(tx->gas_estimation().avg_max_fee_per_gas, - uint256_t(48) * uint256_t(1e9)); - EXPECT_EQ(tx->gas_estimation().fast_max_fee_per_gas, - uint256_t(49) * uint256_t(1e9)); - EXPECT_EQ(tx->gas_estimation().base_fee_per_gas, uint256_t(46574033786ULL)); // Empty nonce should succeed. tx = Eip1559Transaction::FromTxData(mojom::TxData1559::New( mojom::TxData::New("", "0x3E8", "0x989680", "0x3535353535353535353535353535353535353535", "0x2A", std::vector{1}, false, std::nullopt), - "0x15BE", "0x7B", "0x1C8", nullptr)); + "0x15BE", "0x7B", "0x1C8")); ASSERT_TRUE(tx); EXPECT_FALSE(tx->nonce()); @@ -216,7 +191,7 @@ TEST(Eip1559TransactionUnitTest, FromTxData) { mojom::TxData::New("123", "0x3E8", "0x989680", "0x3535353535353535353535353535353535353535", "0x2A", std::vector{1}, false, std::nullopt), - "0x15BE", "0x7B", "0x1C8", nullptr))); + "0x15BE", "0x7B", "0x1C8"))); // Make sure chain id, and the max priority fee fields must all have // fields when strict is true @@ -224,17 +199,17 @@ TEST(Eip1559TransactionUnitTest, FromTxData) { mojom::TxData::New("0x1", "0x3E8", "0x989680", "0x3535353535353535353535353535353535353535", "0x2A", std::vector{1}, false, std::nullopt), - "", "0x7B", "0x1C8", nullptr))); + "", "0x7B", "0x1C8"))); EXPECT_FALSE(Eip1559Transaction::FromTxData(mojom::TxData1559::New( mojom::TxData::New("0x1", "0x3E8", "0x989680", "0x3535353535353535353535353535353535353535", "0x2A", std::vector{1}, false, std::nullopt), - "0x15BE", "", "0x1C8", nullptr))); + "0x15BE", "", "0x1C8"))); EXPECT_FALSE(Eip1559Transaction::FromTxData(mojom::TxData1559::New( mojom::TxData::New("0x1", "0x3E8", "0x989680", "0x3535353535353535353535353535353535353535", "0x2A", std::vector{1}, false, std::nullopt), - "0x15BE", "0x7B", "", nullptr))); + "0x15BE", "0x7B", ""))); // But missing data is allowed when strict is false tx = Eip1559Transaction::FromTxData( @@ -242,7 +217,7 @@ TEST(Eip1559TransactionUnitTest, FromTxData) { mojom::TxData::New("", "0x3E8", "", "0x3535353535353535353535353535353535353535", "", std::vector{1}, false, std::nullopt), - "", "0x7B", "0x1C8", nullptr), + "", "0x7B", "0x1C8"), false); ASSERT_TRUE(tx); // Empty nonce will be std::nullopt @@ -251,9 +226,6 @@ TEST(Eip1559TransactionUnitTest, FromTxData) { EXPECT_EQ(tx->gas_limit(), uint256_t(0)); EXPECT_EQ(tx->value(), uint256_t(0)); - // Unspecified gas estimation will be default values. - EXPECT_EQ(tx->gas_estimation(), Eip1559Transaction::GasEstimation()); - // you can still get at other data that is specified EXPECT_EQ(tx->gas_price(), uint256_t(1000)); EXPECT_EQ(tx->chain_id(), uint256_t(0)); @@ -266,7 +238,7 @@ TEST(Eip1559TransactionUnitTest, FromTxData) { mojom::TxData::New("", "0x3E8", "", "0x3535353535353535353535353535353535353535", "", std::vector{1}, false, std::nullopt), - "0x15BE", "", "", nullptr), + "0x15BE", "", ""), false); ASSERT_TRUE(tx); // Empty nonce will be std::nullopt @@ -279,68 +251,6 @@ TEST(Eip1559TransactionUnitTest, FromTxData) { // you can still get at other data that is specified EXPECT_EQ(tx->gas_price(), uint256_t(1000)); EXPECT_EQ(tx->chain_id(), uint256_t(5566)); - - // Default gas estimation values (0) will be used if any fields in gas - // estimation struct is missing regardless of the value of strict. - auto missing_fields_gas_estimation = GetMojomGasEstimation(); - missing_fields_gas_estimation->avg_max_priority_fee_per_gas = ""; - - tx = Eip1559Transaction::FromTxData(mojom::TxData1559::New( - mojom::TxData::New("0x01", "0x3E8", "0x989680", - "0x3535353535353535353535353535353535353535", "0x2A", - std::vector{1}, false, std::nullopt), - "0x15BE", "0x7B", "0x1C8", missing_fields_gas_estimation.Clone())); - EXPECT_EQ(tx->gas_estimation(), Eip1559Transaction::GasEstimation()); - - tx = Eip1559Transaction::FromTxData( - mojom::TxData1559::New( - mojom::TxData::New("0x01", "0x3E8", "0x989680", - "0x3535353535353535353535353535353535353535", - "0x2A", std::vector{1}, false, - std::nullopt), - "0x15BE", "0x7B", "0x1C8", missing_fields_gas_estimation.Clone()), - false); - EXPECT_EQ(tx->gas_estimation(), Eip1559Transaction::GasEstimation()); -} - -TEST(Eip1559TransactionUnitTest, GasEstimationFromMojomGasEstimation1559) { - auto estimation = - Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - GetMojomGasEstimation()); - EXPECT_TRUE(estimation); - EXPECT_EQ(estimation->slow_max_priority_fee_per_gas, uint256_t(1e9)); - EXPECT_EQ(estimation->avg_max_priority_fee_per_gas, - uint256_t(2) * uint256_t(1e9)); - EXPECT_EQ(estimation->fast_max_priority_fee_per_gas, - uint256_t(3) * uint256_t(1e9)); - EXPECT_EQ(estimation->slow_max_fee_per_gas, uint256_t(47) * uint256_t(1e9)); - EXPECT_EQ(estimation->avg_max_fee_per_gas, uint256_t(48) * uint256_t(1e9)); - EXPECT_EQ(estimation->fast_max_fee_per_gas, uint256_t(49) * uint256_t(1e9)); - EXPECT_EQ(estimation->base_fee_per_gas, uint256_t(46574033786ULL)); - - auto mojom_gas_estimation = GetMojomGasEstimation(); - mojom_gas_estimation->slow_max_priority_fee_per_gas = "123"; - EXPECT_FALSE(Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - std::move(mojom_gas_estimation))); - - mojom_gas_estimation = GetMojomGasEstimation(); - mojom_gas_estimation->avg_max_priority_fee_per_gas = ""; - EXPECT_FALSE(Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - std::move(mojom_gas_estimation))); -} - -TEST(Eip1559TransactionUnitTest, GasEstimationToMojomGasEstimation1559) { - Eip1559Transaction::GasEstimation estimation; - estimation.slow_max_priority_fee_per_gas = uint256_t(1e9); - estimation.avg_max_priority_fee_per_gas = uint256_t(2) * uint256_t(1e9); - estimation.fast_max_priority_fee_per_gas = uint256_t(3) * uint256_t(1e9); - estimation.slow_max_fee_per_gas = uint256_t(47) * uint256_t(1e9); - estimation.avg_max_fee_per_gas = uint256_t(48) * uint256_t(1e9); - estimation.fast_max_fee_per_gas = uint256_t(49) * uint256_t(1e9); - estimation.base_fee_per_gas = uint256_t(46574033786ULL); - EXPECT_EQ( - Eip1559Transaction::GasEstimation::ToMojomGasEstimation1559(estimation), - GetMojomGasEstimation()); } } // namespace brave_wallet diff --git a/components/brave_wallet/browser/eth_tx_manager.cc b/components/brave_wallet/browser/eth_tx_manager.cc index 29d0a96bc72..34f2ef5fa81 100644 --- a/components/brave_wallet/browser/eth_tx_manager.cc +++ b/components/brave_wallet/browser/eth_tx_manager.cc @@ -15,6 +15,7 @@ #include "base/check.h" #include "base/functional/bind.h" +#include "base/numerics/checked_math.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "brave/components/brave_wallet/browser/account_resolver_delegate.h" @@ -37,6 +38,21 @@ namespace brave_wallet { +namespace { + +std::optional IncreaseBy10Percent(uint256_t val) { + base::CheckedNumeric checked_val(val); + checked_val *= 11ULL; + checked_val /= 10ULL; + + if (checked_val.IsValid()) { + return checked_val.ValueOrDie(); + } + return std::nullopt; +} + +} // namespace + // static bool EthTxManager::ValidateTxData(const mojom::TxDataPtr& tx_data, std::string* error) { @@ -174,8 +190,8 @@ void EthTxManager::AddUnapprovedEvmTransaction( std::move(origin_val), std::move(params->swap_info), std::move(callback)); } else { - auto tx_data_1559 = mojom::TxData1559::New( - std::move(tx_data), params->chain_id, "", "", nullptr); + auto tx_data_1559 = + mojom::TxData1559::New(std::move(tx_data), params->chain_id, "", ""); AddUnapproved1559Transaction(params->chain_id, std::move(tx_data_1559), params->from, std::move(origin_val), std::move(params->swap_info), @@ -393,19 +409,22 @@ void EthTxManager::OnGetGasOracleForUnapprovedTransaction( bool sign_only, mojom::SwapInfoPtr swap_info, mojom::GasEstimation1559Ptr gas_estimation) { - auto estimation = - Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - std::move(gas_estimation)); - if (!estimation) { + uint256_t estimation_avg_max_fee_per_gas = 0; + uint256_t estimation_avg_max_priority_fee_per_gas = 0; + if (!gas_estimation || + !HexValueToUint256(gas_estimation->avg_max_fee_per_gas, + &estimation_avg_max_fee_per_gas) || + !HexValueToUint256(gas_estimation->avg_max_priority_fee_per_gas, + &estimation_avg_max_priority_fee_per_gas)) { std::move(callback).Run( false, "", l10n_util::GetStringUTF8( IDS_WALLET_ETH_SEND_TRANSACTION_GET_GAS_FEES_FAILED)); return; } - tx->set_gas_estimation(estimation.value()); - tx->set_max_fee_per_gas(estimation->avg_max_fee_per_gas); - tx->set_max_priority_fee_per_gas(estimation->avg_max_priority_fee_per_gas); + + tx->set_max_fee_per_gas(estimation_avg_max_fee_per_gas); + tx->set_max_priority_fee_per_gas(estimation_avg_max_priority_fee_per_gas); if (gas_limit.empty()) { json_rpc_service_->GetEstimateGas( @@ -1120,10 +1139,24 @@ void EthTxManager::ContinueSpeedupOrCancel1559Transaction( std::unique_ptr tx, SpeedupOrCancelTransactionCallback callback, mojom::GasEstimation1559Ptr gas_estimation) { - auto estimation = - Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - std::move(gas_estimation)); - if (!estimation) { + if (!gas_estimation) { + std::move(callback).Run( + false, "", + l10n_util::GetStringUTF8( + IDS_WALLET_ETH_SEND_TRANSACTION_GET_GAS_FEES_FAILED)); + return; + } + + auto estimation_avg_max_fee_per_gas = + HexValueToUint256(gas_estimation->avg_max_fee_per_gas); + auto estimation_avg_max_priority_fee_per_gas = + HexValueToUint256(gas_estimation->avg_max_priority_fee_per_gas); + auto increased_max_priority_fee_per_gas = + IncreaseBy10Percent(tx->max_priority_fee_per_gas()); + auto increased_max_fee_per_gas = IncreaseBy10Percent(tx->max_fee_per_gas()); + if (!increased_max_priority_fee_per_gas || !increased_max_fee_per_gas || + !estimation_avg_max_fee_per_gas || + !estimation_avg_max_priority_fee_per_gas) { std::move(callback).Run( false, "", l10n_util::GetStringUTF8( @@ -1132,27 +1165,11 @@ void EthTxManager::ContinueSpeedupOrCancel1559Transaction( } // Update gas fees to max(latest_estimate, original_gas_fee + 10%). - // Original_gas_fee * 11 / 10 is done using uint64_t because uint256_t does - // not support division. It's fairly safe to do so because it's unlikely the - // gas fees will be larger than that, they are usually around 10^12 wei. - if (tx->max_priority_fee_per_gas() > std::numeric_limits::max() || - tx->max_fee_per_gas() > std::numeric_limits::max()) { - std::move(callback).Run( - false, "", - l10n_util::GetStringUTF8( - IDS_WALLET_ETH_SEND_TRANSACTION_GET_GAS_FEES_FAILED)); - return; - } - - uint256_t increased_max_priority_fee_per_gas = - static_cast(tx->max_priority_fee_per_gas()) * 11ULL / 10ULL; - uint256_t increased_max_fee_per_gas = - static_cast(tx->max_fee_per_gas()) * 11ULL / 10ULL; tx->set_max_fee_per_gas( - std::max(estimation->avg_max_fee_per_gas, increased_max_fee_per_gas)); + std::max(*estimation_avg_max_fee_per_gas, *increased_max_fee_per_gas)); tx->set_max_priority_fee_per_gas( - std::max(estimation->avg_max_priority_fee_per_gas, - increased_max_priority_fee_per_gas)); + std::max(*estimation_avg_max_priority_fee_per_gas, + *increased_max_priority_fee_per_gas)); ContinueAddUnapprovedTransaction( chain_id, from, origin, std::move(tx), std::move(callback), false, diff --git a/components/brave_wallet/browser/eth_tx_manager_unittest.cc b/components/brave_wallet/browser/eth_tx_manager_unittest.cc index bc32dddaeb4..b93c26bccca 100644 --- a/components/brave_wallet/browser/eth_tx_manager_unittest.cc +++ b/components/brave_wallet/browser/eth_tx_manager_unittest.cc @@ -83,14 +83,6 @@ void AddUnapprovedTransactionFailureCallback(bool* callback_called, *callback_called = true; } -mojom::GasEstimation1559Ptr GetMojomGasEstimation() { - return mojom::GasEstimation1559::New( - "0x3b9aca00" /* Hex of 1 * 1e9 */, "0xaf16b1600" /* Hex of 47 * 1e9 */, - "0x77359400" /* Hex of 2 * 1e9 */, "0xb2d05e000" /* Hex of 48 * 1e9 */, - "0xb2d05e00" /* Hex of 3 * 1e9 */, "0xb68a0aa00" /* Hex of 49 * 1e9 */, - "0xab5d04c00" /* Hex of 4600000000 */); -} - void MakeERC721TransferFromDataCallback(base::RunLoop* run_loop, bool expected_success, mojom::TransactionType expected_type, @@ -354,8 +346,7 @@ class EthTxManagerUnitTest : public testing::Test { mojom::TxData::New(nonce, "", "0x0974", "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", data, false, std::nullopt), - - "0x539", max_priority_fee_per_gas, max_fee_per_gas, nullptr); + "0x539", max_priority_fee_per_gas, max_fee_per_gas); auto tx1559 = Eip1559Transaction::FromTxData(tx_data1559, false); ASSERT_TRUE(tx1559); @@ -1088,7 +1079,7 @@ TEST_F(EthTxManagerUnitTest, ValidateTxData1559) { mojom::TxData::New( "0x00", "", "0x00", "0x0101010101010101010101010101010101010101", "0x00", std::vector(), false, std::nullopt), - "0x04", "0x0", "0x1", nullptr), + "0x04", "0x0", "0x1"), &error_message)); // Can't specify both gas price and max fee per gas @@ -1098,8 +1089,7 @@ TEST_F(EthTxManagerUnitTest, ValidateTxData1559) { "0x0101010101010101010101010101010101010101", "0x00", std::vector(), false, std::nullopt), - - "0x04", "0x0", "0x1", nullptr), + "0x04", "0x0", "0x1"), &error_message)); } @@ -1270,7 +1260,7 @@ TEST_F(EthTxManagerUnitTest, GetNonceForHardwareTransaction1559) { mojom::TxData::New("0x00", "", "0x01", "0x0101010101010101010101010101010101010101", "0x00", std::vector(), false, std::nullopt), - "0x04", "0x1", "0x1", nullptr); + "0x04", "0x1", "0x1"); bool callback_called = false; std::string tx_meta_id; @@ -1347,7 +1337,7 @@ TEST_F(EthTxManagerUnitTest, AddUnapproved1559TransactionWithGasFeeAndLimit) { mojom::TxData::New("0x1", "", gas_limit, "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", data_, false, std::nullopt), - "0x04", "0x77359400" /* 2 Gwei */, "0xb2d05e000" /* 48 Gwei */, nullptr); + "0x04", "0x77359400" /* 2 Gwei */, "0xb2d05e000" /* 48 Gwei */); bool callback_called = false; std::string tx_meta_id; @@ -1368,7 +1358,6 @@ TEST_F(EthTxManagerUnitTest, AddUnapproved1559TransactionWithGasFeeAndLimit) { auto* tx1559 = static_cast(tx_meta->tx()); EXPECT_EQ(tx1559->max_priority_fee_per_gas(), uint256_t(2) * uint256_t(1e9)); EXPECT_EQ(tx1559->max_fee_per_gas(), uint256_t(48) * uint256_t(1e9)); - EXPECT_EQ(tx1559->gas_estimation(), Eip1559Transaction::GasEstimation()); } TEST_F(EthTxManagerUnitTest, AddUnapproved1559TransactionWithoutGasLimit) { @@ -1376,7 +1365,7 @@ TEST_F(EthTxManagerUnitTest, AddUnapproved1559TransactionWithoutGasLimit) { mojom::TxData::New("0x1", "", "", "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", data_, false, std::nullopt), - "0x04", "0x77359400" /* 2 Gwei */, "0xb2d05e000" /* 48 Gwei */, nullptr); + "0x04", "0x77359400" /* 2 Gwei */, "0xb2d05e000" /* 48 Gwei */); bool callback_called = false; std::string tx_meta_id; @@ -1397,7 +1386,6 @@ TEST_F(EthTxManagerUnitTest, AddUnapproved1559TransactionWithoutGasLimit) { auto* tx1559 = static_cast(tx_meta->tx()); EXPECT_EQ(tx1559->max_priority_fee_per_gas(), uint256_t(2) * uint256_t(1e9)); EXPECT_EQ(tx1559->max_fee_per_gas(), uint256_t(48) * uint256_t(1e9)); - EXPECT_EQ(tx1559->gas_estimation(), Eip1559Transaction::GasEstimation()); } TEST_F(EthTxManagerUnitTest, AddUnapproved1559TransactionWithoutGasFee) { @@ -1406,7 +1394,7 @@ TEST_F(EthTxManagerUnitTest, AddUnapproved1559TransactionWithoutGasFee) { mojom::TxData::New("0x1", "", gas_limit, "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", data_, false, std::nullopt), - "0x04", "", "", nullptr); + "0x04", "", ""); bool callback_called = false; std::string tx_meta_id; @@ -1427,9 +1415,6 @@ TEST_F(EthTxManagerUnitTest, AddUnapproved1559TransactionWithoutGasFee) { auto* tx1559 = static_cast(tx_meta->tx()); EXPECT_EQ(tx1559->max_priority_fee_per_gas(), uint256_t(2) * uint256_t(1e9)); EXPECT_EQ(tx1559->max_fee_per_gas(), uint256_t(48) * uint256_t(1e9)); - EXPECT_EQ(tx1559->gas_estimation(), - Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - GetMojomGasEstimation())); } TEST_F(EthTxManagerUnitTest, @@ -1438,7 +1423,7 @@ TEST_F(EthTxManagerUnitTest, mojom::TxData::New("0x1", "", "", "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", data_, false, std::nullopt), - "0x04", "", "", nullptr); + "0x04", "", ""); bool callback_called = false; std::string tx_meta_id; @@ -1459,9 +1444,6 @@ TEST_F(EthTxManagerUnitTest, auto* tx1559 = static_cast(tx_meta->tx()); EXPECT_EQ(tx1559->max_priority_fee_per_gas(), uint256_t(2) * uint256_t(1e9)); EXPECT_EQ(tx1559->max_fee_per_gas(), uint256_t(48) * uint256_t(1e9)); - EXPECT_EQ(tx1559->gas_estimation(), - Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - GetMojomGasEstimation())); } TEST_F(EthTxManagerUnitTest, @@ -1499,7 +1481,7 @@ TEST_F(EthTxManagerUnitTest, mojom::TxData::New("0x1", "", gas_limit, "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", data_, false, std::nullopt), - "0x04", "", "", nullptr); + "0x04", "", ""); bool callback_called = false; std::string tx_meta_id; @@ -1518,18 +1500,6 @@ TEST_F(EthTxManagerUnitTest, auto* tx1559 = static_cast(tx_meta->tx()); EXPECT_EQ(tx1559->max_priority_fee_per_gas(), 0ULL); EXPECT_EQ(tx1559->max_fee_per_gas(), 133ULL); // 0x64 x 1.33 - - auto estimation = - mojom::GasEstimation1559::New("0x0", // slow_max_priority_fee_per_gas - "0x85", // slow_max_fee_per_gas - "0x0", // avg_max_priority_fee_per_gas - "0x85", // avg_max_fee_per_gas - "0x0", // fast_max_priority_fee_per_gas - "0x85", // fast_max_fee_per_gas - "0x85"); // base_fee_per_gas (0x64 x 1.33) - EXPECT_EQ(tx1559->gas_estimation(), - Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - std::move(estimation))); } TEST_F(EthTxManagerUnitTest, @@ -1573,7 +1543,7 @@ TEST_F(EthTxManagerUnitTest, mojom::TxData::New("0x1", "", "", "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", data_, false, std::nullopt), - "0x04", "", "", nullptr); + "0x04", "", ""); bool callback_called = false; std::string tx_meta_id; @@ -1592,18 +1562,6 @@ TEST_F(EthTxManagerUnitTest, auto* tx1559 = static_cast(tx_meta->tx()); EXPECT_EQ(tx1559->max_priority_fee_per_gas(), 0ULL); EXPECT_EQ(tx1559->max_fee_per_gas(), 133ULL); // 0x64 x 1.33 - - auto estimation = - mojom::GasEstimation1559::New("0x0", // slow_max_priority_fee_per_gas - "0x85", // slow_max_fee_per_gas - "0x0", // avg_max_priority_fee_per_gas - "0x85", // avg_max_fee_per_gas - "0x0", // fast_max_priority_fee_per_gas - "0x85", // fast_max_fee_per_gas - "0x85"); // base_fee_per_gas (0x64 x 1.33) - EXPECT_EQ(tx1559->gas_estimation(), - Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - std::move(estimation))); } TEST_F(EthTxManagerUnitTest, AddUnapproved1559TransactionFeeHistoryFailed) { @@ -1630,7 +1588,7 @@ TEST_F(EthTxManagerUnitTest, AddUnapproved1559TransactionFeeHistoryFailed) { mojom::TxData::New("0x1", "", "0x9604", "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", data_, false, std::nullopt), - "0x04", "", "", nullptr); + "0x04", "", ""); bool callback_called = false; AddUnapproved1559Transaction( @@ -1648,7 +1606,7 @@ TEST_F(EthTxManagerUnitTest, mojom::TxData::New( "0x1", "", "", "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", std::vector(), false, std::nullopt), - "0x04", "", "", nullptr); + "0x04", "", ""); bool callback_called = false; std::string tx_meta_id; @@ -1666,24 +1624,20 @@ TEST_F(EthTxManagerUnitTest, // Gas limit obtained by querying eth_estimateGas. EXPECT_EQ(tx_meta->tx()->gas_limit(), 38404ULL); - // Gas fee and estimation should be filled by gas oracle. + // Gas fee should be filled by gas oracle. auto* tx1559 = static_cast(tx_meta->tx()); EXPECT_EQ(tx1559->max_priority_fee_per_gas(), uint256_t(2) * uint256_t(1e9)); EXPECT_EQ(tx1559->max_fee_per_gas(), uint256_t(48) * uint256_t(1e9)); - EXPECT_EQ(tx1559->gas_estimation(), - Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - GetMojomGasEstimation())); } TEST_F(EthTxManagerUnitTest, AddUnapproved1559TransactionWithGasFeeAndLimitForEthSend) { const std::string gas_limit = "0x0974"; - auto tx_data = mojom::TxData1559::New( mojom::TxData::New( "0x1", "", gas_limit, "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", std::vector(), false, std::nullopt), - "0x04", "0x77359400" /* 2 Gwei */, "0xb2d05e000" /* 48 Gwei */, nullptr); + "0x04", "0x77359400" /* 2 Gwei */, "0xb2d05e000" /* 48 Gwei */); bool callback_called = false; std::string tx_meta_id; @@ -1704,7 +1658,6 @@ TEST_F(EthTxManagerUnitTest, auto* tx1559 = static_cast(tx_meta->tx()); EXPECT_EQ(tx1559->max_priority_fee_per_gas(), uint256_t(2) * uint256_t(1e9)); EXPECT_EQ(tx1559->max_fee_per_gas(), uint256_t(48) * uint256_t(1e9)); - EXPECT_EQ(tx1559->gas_estimation(), Eip1559Transaction::GasEstimation()); } TEST_F(EthTxManagerUnitTest, @@ -1713,7 +1666,7 @@ TEST_F(EthTxManagerUnitTest, mojom::TxData::New( "0x1", "", "", "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", std::vector(), false, std::nullopt), - "0x04", "0x77359400" /* 2 Gwei */, "0xb2d05e000" /* 48 Gwei */, nullptr); + "0x04", "0x77359400" /* 2 Gwei */, "0xb2d05e000" /* 48 Gwei */); bool callback_called = false; std::string tx_meta_id; @@ -1733,7 +1686,6 @@ TEST_F(EthTxManagerUnitTest, auto* tx1559 = static_cast(tx_meta->tx()); EXPECT_EQ(tx1559->max_priority_fee_per_gas(), uint256_t(2) * uint256_t(1e9)); EXPECT_EQ(tx1559->max_fee_per_gas(), uint256_t(48) * uint256_t(1e9)); - EXPECT_EQ(tx1559->gas_estimation(), Eip1559Transaction::GasEstimation()); } TEST_F(EthTxManagerUnitTest, @@ -1743,7 +1695,7 @@ TEST_F(EthTxManagerUnitTest, mojom::TxData::New( "0x1", "", gas_limit, "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", std::vector(), false, std::nullopt), - "0x04", "", "", nullptr); + "0x04", "", ""); bool callback_called = false; std::string tx_meta_id; @@ -1766,9 +1718,6 @@ TEST_F(EthTxManagerUnitTest, auto* tx1559 = static_cast(tx_meta->tx()); EXPECT_EQ(tx1559->max_priority_fee_per_gas(), uint256_t(2) * uint256_t(1e9)); EXPECT_EQ(tx1559->max_fee_per_gas(), uint256_t(48) * uint256_t(1e9)); - EXPECT_EQ(tx1559->gas_estimation(), - Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - GetMojomGasEstimation())); } TEST_F(EthTxManagerUnitTest, SetGasFeeAndLimitForUnapprovedTransaction) { @@ -1776,7 +1725,7 @@ TEST_F(EthTxManagerUnitTest, SetGasFeeAndLimitForUnapprovedTransaction) { mojom::TxData::New("0x1", "", "", "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", data_, false, std::nullopt), - "0x04", "", "", nullptr); + "0x04", "", ""); bool callback_called = false; std::string tx_meta_id; @@ -1799,9 +1748,6 @@ TEST_F(EthTxManagerUnitTest, SetGasFeeAndLimitForUnapprovedTransaction) { auto* tx1559 = static_cast(tx_meta->tx()); EXPECT_EQ(tx1559->max_priority_fee_per_gas(), uint256_t(2) * uint256_t(1e9)); EXPECT_EQ(tx1559->max_fee_per_gas(), uint256_t(48) * uint256_t(1e9)); - EXPECT_EQ(tx1559->gas_estimation(), - Eip1559Transaction::GasEstimation::FromMojomGasEstimation1559( - GetMojomGasEstimation())); // Fail if transaction is not found. callback_called = false; @@ -2242,7 +2188,7 @@ TEST_F(EthTxManagerUnitTest, RetryTransaction) { mojom::TxData::New("0x08", "", "0x0974", "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", "0x016345785d8a0000", data_, false, std::nullopt), - "0x539", "0x77359400" /* 2 Gwei */, "0xb2d05e000" /* 48 Gwei */, nullptr); + "0x539", "0x77359400" /* 2 Gwei */, "0xb2d05e000" /* 48 Gwei */); auto tx1559 = Eip1559Transaction::FromTxData(tx_data1559, false); ASSERT_TRUE(tx1559); diff --git a/components/brave_wallet/browser/eth_tx_meta.cc b/components/brave_wallet/browser/eth_tx_meta.cc index 282da889caa..180798a5df8 100644 --- a/components/brave_wallet/browser/eth_tx_meta.cc +++ b/components/brave_wallet/browser/eth_tx_meta.cc @@ -96,7 +96,6 @@ mojom::TransactionInfoPtr EthTxMeta::ToTransactionInfo() const { std::string chain_id; std::string max_priority_fee_per_gas; std::string max_fee_per_gas; - mojom::GasEstimation1559Ptr gas_estimation_1559_ptr = nullptr; if (tx_->type() == 1) { // When type is 1 it's always Eip2930Transaction auto* tx2930 = static_cast(tx_.get()); @@ -108,9 +107,6 @@ mojom::TransactionInfoPtr EthTxMeta::ToTransactionInfo() const { max_priority_fee_per_gas = Uint256ValueToHex(tx1559->max_priority_fee_per_gas()); max_fee_per_gas = Uint256ValueToHex(tx1559->max_fee_per_gas()); - gas_estimation_1559_ptr = - Eip1559Transaction::GasEstimation::ToMojomGasEstimation1559( - tx1559->gas_estimation()); } mojom::TransactionType tx_type; std::vector tx_params; @@ -170,8 +166,7 @@ mojom::TransactionInfoPtr EthTxMeta::ToTransactionInfo() const { Uint256ValueToHex(tx_->gas_limit()), tx_->GetToChecksumAddress(), Uint256ValueToHex(tx_->value()), tx_->data(), sign_only_, signed_transaction), - chain_id, max_priority_fee_per_gas, max_fee_per_gas, - std::move(gas_estimation_1559_ptr))), + chain_id, max_priority_fee_per_gas, max_fee_per_gas)), status_, tx_type, tx_params, tx_args, base::Milliseconds(created_time_.InMillisecondsSinceUnixEpoch()), base::Milliseconds(submitted_time_.InMillisecondsSinceUnixEpoch()), diff --git a/components/brave_wallet/browser/eth_tx_meta_unittest.cc b/components/brave_wallet/browser/eth_tx_meta_unittest.cc index 4cefa54befb..31d686111dc 100644 --- a/components/brave_wallet/browser/eth_tx_meta_unittest.cc +++ b/components/brave_wallet/browser/eth_tx_meta_unittest.cc @@ -62,7 +62,6 @@ TEST(EthTxMetaUnitTest, ToTransactionInfo) { EXPECT_EQ(ti->tx_data_union->get_eth_tx_data_1559()->max_priority_fee_per_gas, ""); EXPECT_EQ(ti->tx_data_union->get_eth_tx_data_1559()->max_fee_per_gas, ""); - EXPECT_FALSE(ti->tx_data_union->get_eth_tx_data_1559()->gas_estimation); EXPECT_EQ(meta.created_time().InMillisecondsSinceUnixEpoch(), ti->created_time.InMilliseconds()); EXPECT_EQ(meta.submitted_time().InMillisecondsSinceUnixEpoch(), @@ -111,7 +110,6 @@ TEST(EthTxMetaUnitTest, ToTransactionInfo) { EXPECT_EQ( ti1->tx_data_union->get_eth_tx_data_1559()->max_priority_fee_per_gas, ""); EXPECT_EQ(ti1->tx_data_union->get_eth_tx_data_1559()->max_fee_per_gas, ""); - EXPECT_FALSE(ti1->tx_data_union->get_eth_tx_data_1559()->gas_estimation); // type2 std::unique_ptr tx2 = @@ -121,15 +119,7 @@ TEST(EthTxMetaUnitTest, ToTransactionInfo) { "0x3535353535353535353535353535353535353535", "0x0de0b6b3a7640000", std::vector(), false, std::nullopt), - "0x3", "0x1E", "0x32", - mojom::GasEstimation1559::New( - "0x3b9aca00" /* Hex of 1 * 1e9 */, - "0xaf16b1600" /* Hex of 47 * 1e9 */, - "0x77359400" /* Hex of 2 * 1e9 */, - "0xb2d05e000" /* Hex of 48 * 1e9 */, - "0xb2d05e00" /* Hex of 3 * 1e9 */, - "0xb68a0aa00" /* Hex of 49 * 1e9 */, - "0xad8075b7a" /* Hex of 46574033786 */)))); + "0x3", "0x1E", "0x32"))); EthTxMeta meta2(eth_account_id, std::move(tx2)); mojom::TransactionInfoPtr ti2 = meta2.ToTransactionInfo(); EXPECT_EQ(ti2->id, meta2.id()); @@ -157,31 +147,6 @@ TEST(EthTxMetaUnitTest, ToTransactionInfo) { Uint256ValueToHex(tx1559->max_priority_fee_per_gas())); EXPECT_EQ(ti2->tx_data_union->get_eth_tx_data_1559()->max_fee_per_gas, Uint256ValueToHex(tx1559->max_fee_per_gas())); - ASSERT_TRUE(ti2->tx_data_union->get_eth_tx_data_1559()->gas_estimation); - EXPECT_EQ(ti2->tx_data_union->get_eth_tx_data_1559() - ->gas_estimation->slow_max_priority_fee_per_gas, - Uint256ValueToHex( - tx1559->gas_estimation().slow_max_priority_fee_per_gas)); - EXPECT_EQ( - ti2->tx_data_union->get_eth_tx_data_1559() - ->gas_estimation->avg_max_priority_fee_per_gas, - Uint256ValueToHex(tx1559->gas_estimation().avg_max_priority_fee_per_gas)); - EXPECT_EQ(ti2->tx_data_union->get_eth_tx_data_1559() - ->gas_estimation->fast_max_priority_fee_per_gas, - Uint256ValueToHex( - tx1559->gas_estimation().fast_max_priority_fee_per_gas)); - EXPECT_EQ(ti2->tx_data_union->get_eth_tx_data_1559() - ->gas_estimation->slow_max_fee_per_gas, - Uint256ValueToHex(tx1559->gas_estimation().slow_max_fee_per_gas)); - EXPECT_EQ(ti2->tx_data_union->get_eth_tx_data_1559() - ->gas_estimation->avg_max_fee_per_gas, - Uint256ValueToHex(tx1559->gas_estimation().avg_max_fee_per_gas)); - EXPECT_EQ(ti2->tx_data_union->get_eth_tx_data_1559() - ->gas_estimation->fast_max_fee_per_gas, - Uint256ValueToHex(tx1559->gas_estimation().fast_max_fee_per_gas)); - EXPECT_EQ(ti2->tx_data_union->get_eth_tx_data_1559() - ->gas_estimation->base_fee_per_gas, - Uint256ValueToHex(tx1559->gas_estimation().base_fee_per_gas)); } TEST(EthTxMetaUnitTest, ToTransactionInfo_FinalRecipientTest) { @@ -204,15 +169,7 @@ TEST(EthTxMetaUnitTest, ToTransactionInfo_FinalRecipientTest) { "0x3535353535353535353535353535353535353535", "0x0de0b6b3a7640000", data, false, std::nullopt), - mojom::kFilecoinEthereumMainnetChainId, "0x1E", "0x32", - mojom::GasEstimation1559::New( - "0x3b9aca00" /* Hex of 1 * 1e9 */, - "0xaf16b1600" /* Hex of 47 * 1e9 */, - "0x77359400" /* Hex of 2 * 1e9 */, - "0xb2d05e000" /* Hex of 48 * 1e9 */, - "0xb2d05e00" /* Hex of 3 * 1e9 */, - "0xb68a0aa00" /* Hex of 49 * 1e9 */, - "0xad8075b7a" /* Hex of 46574033786 */)))); + mojom::kFilecoinEthereumMainnetChainId, "0x1E", "0x32"))); EthTxMeta meta(eth_account_id, std::move(tx)); ASSERT_EQ(meta.ToTransactionInfo()->effective_recipient.value(), @@ -234,15 +191,7 @@ TEST(EthTxMetaUnitTest, ToTransactionInfo_FinalRecipientTest) { "0x3535353535353535353535353535353535353535", "0x0de0b6b3a7640000", encoded_data, false, std::nullopt), - mojom::kSepoliaChainId, "0x1E", "0x32", - mojom::GasEstimation1559::New( - "0x3b9aca00" /* Hex of 1 * 1e9 */, - "0xaf16b1600" /* Hex of 47 * 1e9 */, - "0x77359400" /* Hex of 2 * 1e9 */, - "0xb2d05e000" /* Hex of 48 * 1e9 */, - "0xb2d05e00" /* Hex of 3 * 1e9 */, - "0xb68a0aa00" /* Hex of 49 * 1e9 */, - "0xad8075b7a" /* Hex of 46574033786 */)))); + mojom::kSepoliaChainId, "0x1E", "0x32"))); EthTxMeta meta(eth_account_id, std::move(tx)); ASSERT_EQ(meta.ToTransactionInfo()->effective_recipient.value(), @@ -265,15 +214,7 @@ TEST(EthTxMetaUnitTest, ToTransactionInfo_FinalRecipientTest) { "0x3535353535353535353535353535353535353535", "0x0de0b6b3a7640000", encoded_data, false, std::nullopt), - mojom::kSepoliaChainId, "0x1E", "0x32", - mojom::GasEstimation1559::New( - "0x3b9aca00" /* Hex of 1 * 1e9 */, - "0xaf16b1600" /* Hex of 47 * 1e9 */, - "0x77359400" /* Hex of 2 * 1e9 */, - "0xb2d05e000" /* Hex of 48 * 1e9 */, - "0xb2d05e00" /* Hex of 3 * 1e9 */, - "0xb68a0aa00" /* Hex of 49 * 1e9 */, - "0xad8075b7a" /* Hex of 46574033786 */)))); + mojom::kSepoliaChainId, "0x1E", "0x32"))); EthTxMeta meta(eth_account_id, std::move(tx)); ASSERT_EQ(meta.ToTransactionInfo()->effective_recipient.value(), @@ -296,15 +237,7 @@ TEST(EthTxMetaUnitTest, ToTransactionInfo_FinalRecipientTest) { "0x3535353535353535353535353535353535353535", "0x0de0b6b3a7640000", encoded_data, false, std::nullopt), - mojom::kSepoliaChainId, "0x1E", "0x32", - mojom::GasEstimation1559::New( - "0x3b9aca00" /* Hex of 1 * 1e9 */, - "0xaf16b1600" /* Hex of 47 * 1e9 */, - "0x77359400" /* Hex of 2 * 1e9 */, - "0xb2d05e000" /* Hex of 48 * 1e9 */, - "0xb2d05e00" /* Hex of 3 * 1e9 */, - "0xb68a0aa00" /* Hex of 49 * 1e9 */, - "0xad8075b7a" /* Hex of 46574033786 */)))); + mojom::kSepoliaChainId, "0x1E", "0x32"))); EthTxMeta meta(eth_account_id, std::move(tx)); ASSERT_EQ(meta.ToTransactionInfo()->effective_recipient.value(), @@ -320,15 +253,7 @@ TEST(EthTxMetaUnitTest, ToTransactionInfo_FinalRecipientTest) { "0x3535353535353535353535353535353535353535", "0x0de0b6b3a7640000", std::vector(), false, std::nullopt), - mojom::kSepoliaChainId, "0x1E", "0x32", - mojom::GasEstimation1559::New( - "0x3b9aca00" /* Hex of 1 * 1e9 */, - "0xaf16b1600" /* Hex of 47 * 1e9 */, - "0x77359400" /* Hex of 2 * 1e9 */, - "0xb2d05e000" /* Hex of 48 * 1e9 */, - "0xb2d05e00" /* Hex of 3 * 1e9 */, - "0xb68a0aa00" /* Hex of 49 * 1e9 */, - "0xad8075b7a" /* Hex of 46574033786 */)))); + mojom::kSepoliaChainId, "0x1E", "0x32"))); EthTxMeta meta(eth_account_id, std::move(tx)); ASSERT_EQ(meta.ToTransactionInfo()->effective_recipient.value(), diff --git a/components/brave_wallet/browser/eth_tx_state_manager_unittest.cc b/components/brave_wallet/browser/eth_tx_state_manager_unittest.cc index 94d3695596c..cbb7c8733dd 100644 --- a/components/brave_wallet/browser/eth_tx_state_manager_unittest.cc +++ b/components/brave_wallet/browser/eth_tx_state_manager_unittest.cc @@ -154,15 +154,7 @@ TEST_F(EthTxStateManagerUnitTest, TxMetaAndValue) { "0x3535353535353535353535353535353535353535", "0x0de0b6b3a7640000", std::vector(), false, std::nullopt), - "0x3", "0x1E", "0x32", - mojom::GasEstimation1559::New( - "0x3b9aca00" /* Hex of 1 * 1e9 */, - "0xaf16b1600" /* Hex of 47 * 1e9 */, - "0x77359400" /* Hex of 2 * 1e9 */, - "0xb2d05e000" /* Hex of 48 * 1e9 */, - "0xb2d05e00" /* Hex of 3 * 1e9 */, - "0xb68a0aa00" /* Hex of 49 * 1e9 */, - "0xad8075b7a" /* Hex of 46574033786 */)))); + "0x3", "0x1E", "0x32"))); EthTxMeta meta2(eth_account_id, std::move(tx2)); base::DictValue value2 = meta2.ToValue(); auto meta_from_value2 = eth_tx_state_manager_->ValueToEthTxMeta(value2); diff --git a/components/brave_wallet/browser/simulation_request_helper_unittest.cc b/components/brave_wallet/browser/simulation_request_helper_unittest.cc index 7a86e95540a..3df1e380d9c 100644 --- a/components/brave_wallet/browser/simulation_request_helper_unittest.cc +++ b/components/brave_wallet/browser/simulation_request_helper_unittest.cc @@ -45,13 +45,12 @@ mojom::TransactionInfoPtr GetCannedScanEVMTransactionParams( is_eth_send ? std::vector() : std::vector(1, 10u), false, std::nullopt); - auto tx = - eip1559 - ? std::make_unique( - *Eip1559Transaction::FromTxData(mojom::TxData1559::New( - std::move(base_tx_data), "0x3", "0x1E", "0x32", nullptr))) - : std::make_unique( - *EthTransaction::FromTxData(std::move(base_tx_data))); + auto tx = eip1559 + ? std::make_unique( + *Eip1559Transaction::FromTxData(mojom::TxData1559::New( + std::move(base_tx_data), "0x3", "0x1E", "0x32"))) + : std::make_unique( + *EthTransaction::FromTxData(std::move(base_tx_data))); auto eth_account = MakeAccountId(mojom::CoinType::ETH, mojom::KeyringId::kDefault, diff --git a/components/brave_wallet/browser/simulation_service_unittest.cc b/components/brave_wallet/browser/simulation_service_unittest.cc index a7eb0bdd78d..b0b4673cfbf 100644 --- a/components/brave_wallet/browser/simulation_service_unittest.cc +++ b/components/brave_wallet/browser/simulation_service_unittest.cc @@ -137,7 +137,7 @@ class SimulationServiceUnitTest : public testing::Test { std::unique_ptr tx = std::make_unique( *Eip1559Transaction::FromTxData(mojom::TxData1559::New( - std::move(base_tx_data), "0x3", "0x1E", "0x32", nullptr))); + std::move(base_tx_data), "0x3", "0x1E", "0x32"))); EthTxMeta meta(EthAccountId(0), std::move(tx)); meta.set_chain_id(chain_id); return meta.ToTransactionInfo(); diff --git a/components/brave_wallet/common/brave_wallet.mojom b/components/brave_wallet/common/brave_wallet.mojom index 41aea687253..60bc396c29c 100644 --- a/components/brave_wallet/common/brave_wallet.mojom +++ b/components/brave_wallet/common/brave_wallet.mojom @@ -1652,7 +1652,6 @@ struct TxData1559 { string chain_id; string max_priority_fee_per_gas; string max_fee_per_gas; - GasEstimation1559? gas_estimation; }; const string kSolanaSystemProgramId = "11111111111111111111111111111111"; diff --git a/components/brave_wallet/common/hex_utils.cc b/components/brave_wallet/common/hex_utils.cc index 5d68e579f45..b32332e3b6a 100644 --- a/components/brave_wallet/common/hex_utils.cc +++ b/components/brave_wallet/common/hex_utils.cc @@ -138,6 +138,14 @@ bool HexValueToUint256(std::string_view hex_input, uint256_t* out) { return true; } +std::optional HexValueToUint256(std::string_view hex_input) { + uint256_t result = 0; + if (!HexValueToUint256(hex_input, &result)) { + return std::nullopt; + } + return result; +} + bool HexValueToInt256(std::string_view hex_input, int256_t* out) { if (!out) { return false; @@ -153,6 +161,14 @@ bool HexValueToInt256(std::string_view hex_input, int256_t* out) { return true; } +std::optional HexValueToInt256(std::string_view hex_input) { + int256_t result = 0; + if (!HexValueToInt256(hex_input, &result)) { + return std::nullopt; + } + return result; +} + std::string Uint256ValueToHex(uint256_t input) { if (input == 0) { return "0x0"; // Special case for zero. diff --git a/components/brave_wallet/common/hex_utils.h b/components/brave_wallet/common/hex_utils.h index 1809f42dbd7..b4c893d0c1c 100644 --- a/components/brave_wallet/common/hex_utils.h +++ b/components/brave_wallet/common/hex_utils.h @@ -52,8 +52,10 @@ bool ConcatHexStrings(const std::vector& hex_inputs, // Takes a hex string as input and converts it to a uint256_t bool HexValueToUint256(std::string_view hex_input, uint256_t* out); +std::optional HexValueToUint256(std::string_view hex_input); // Takes a hex string as input and converts it to a int256_t bool HexValueToInt256(std::string_view hex_input, int256_t* out); +std::optional HexValueToInt256(std::string_view hex_input); // TODO(apamyshev): this call is misused in many places(like in conjuction with // `PadHexEncodedParameter`). All call sites need review. Also needs better diff --git a/components/brave_wallet/common/hex_utils_unittest.cc b/components/brave_wallet/common/hex_utils_unittest.cc index b6feb4199e7..5656e356652 100644 --- a/components/brave_wallet/common/hex_utils_unittest.cc +++ b/components/brave_wallet/common/hex_utils_unittest.cc @@ -115,29 +115,44 @@ TEST(HexUtilsUnitTest, HexValueToUint256) { "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", &out)); ASSERT_TRUE(out == (uint256_t)expected_val); + ASSERT_EQ(expected_val, + HexValueToUint256("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + "FFFFFFFFFFFFFFFFFF")); // Should return false when out of bounds ASSERT_FALSE(HexValueToUint256( "0x10000000000000000000000000000000000000000000000000000000000000000", &out)); + ASSERT_FALSE(HexValueToUint256( + "0x10000000000000000000000000000000000000000000000000000000000000000")); // Check padded values too ASSERT_TRUE(HexValueToUint256("0x00000000000000000000000F0", &out)); ASSERT_EQ(out, (uint256_t)240); + ASSERT_EQ(HexValueToUint256("0x00000000000000000000000F0"), out); } TEST(HexUtilsUnitTest, HexValueToInt256) { int256_t out; ASSERT_TRUE(HexValueToInt256("0x", &out)); EXPECT_EQ(out, int256_t(0)); + ASSERT_EQ(HexValueToInt256("0x"), int256_t(0)); + ASSERT_TRUE(HexValueToInt256("0x0", &out)); EXPECT_EQ(out, int256_t(0)); + ASSERT_EQ(HexValueToInt256("0x0"), int256_t(0)); + ASSERT_TRUE(HexValueToInt256("0x1", &out)); EXPECT_EQ(out, int256_t(1)); + ASSERT_EQ(HexValueToInt256("0x1"), int256_t(1)); + ASSERT_TRUE(HexValueToInt256("0x1234", &out)); EXPECT_EQ(out, (int256_t)4660); + ASSERT_EQ(HexValueToInt256("0x1234"), (int256_t)4660); + ASSERT_TRUE(HexValueToInt256("0xB", &out)); EXPECT_EQ(out, (int256_t)11); + ASSERT_EQ(HexValueToInt256("0xB"), (int256_t)11); // Max int256 value can be represented int256_t expected_val = kMax256BitInt; @@ -145,6 +160,10 @@ TEST(HexUtilsUnitTest, HexValueToInt256) { "0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", &out)); EXPECT_EQ(out, expected_val); + ASSERT_EQ( + HexValueToInt256( + "0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), + expected_val); // Min int256 value can be represented expected_val = kMin256BitInt; @@ -152,6 +171,10 @@ TEST(HexUtilsUnitTest, HexValueToInt256) { "0x8000000000000000000000000000000000000000000000000000000000000000", &out)); EXPECT_EQ(out, expected_val); + ASSERT_EQ( + HexValueToInt256( + "0x8000000000000000000000000000000000000000000000000000000000000000"), + expected_val); // Biggest int256 negative value can be represented expected_val = int256_t(-1); @@ -159,15 +182,22 @@ TEST(HexUtilsUnitTest, HexValueToInt256) { "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", &out)); EXPECT_EQ(out, expected_val); + ASSERT_EQ( + HexValueToInt256( + "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), + expected_val); // Should return false when out of bounds ASSERT_FALSE(HexValueToInt256( "0x10000000000000000000000000000000000000000000000000000000000000000", &out)); + ASSERT_FALSE(HexValueToInt256( + "0x10000000000000000000000000000000000000000000000000000000000000000")); // Check padded values too ASSERT_TRUE(HexValueToInt256("0x00000000000000000000000F0", &out)); EXPECT_EQ(out, int256_t(240)); + ASSERT_EQ(HexValueToInt256("0x00000000000000000000000F0"), int256_t(240)); } TEST(HexUtilsUnitTest, Uint256ValueToHex) { diff --git a/components/brave_wallet_ui/common/constants/mocks.ts b/components/brave_wallet_ui/common/constants/mocks.ts index bb3c972a82b..4662606767d 100644 --- a/components/brave_wallet_ui/common/constants/mocks.ts +++ b/components/brave_wallet_ui/common/constants/mocks.ts @@ -69,7 +69,6 @@ export const getMockedTransactionInfo = chainId: BraveWallet.LOCALHOST_CHAIN_ID, maxPriorityFeePerGas: '', maxFeePerGas: '', - gasEstimation: undefined, }, ethTxData: {} as any, filTxData: undefined, diff --git a/components/brave_wallet_ui/components/extension/pending_transaction_details/pending_transaction_details.test.tsx b/components/brave_wallet_ui/components/extension/pending_transaction_details/pending_transaction_details.test.tsx index b9dc252a2e5..53928c78f9b 100644 --- a/components/brave_wallet_ui/components/extension/pending_transaction_details/pending_transaction_details.test.tsx +++ b/components/brave_wallet_ui/components/extension/pending_transaction_details/pending_transaction_details.test.tsx @@ -108,7 +108,6 @@ describe('PendingTransactionDetails', () => { chainId: '0x1', maxPriorityFeePerGas: '1000000000', maxFeePerGas: '2000000000', - gasEstimation: undefined, baseData: { nonce: '0x1', gasPrice: '1000000000', diff --git a/components/brave_wallet_ui/stories/mock-data/mock-account-transactions.ts b/components/brave_wallet_ui/stories/mock-data/mock-account-transactions.ts index 90fe75bdcf7..50372c38579 100644 --- a/components/brave_wallet_ui/stories/mock-data/mock-account-transactions.ts +++ b/components/brave_wallet_ui/stories/mock-data/mock-account-transactions.ts @@ -22,7 +22,6 @@ export const transactionDummyData = { chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -60,7 +59,6 @@ export const transactionDummyData = { chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -92,7 +90,6 @@ export const transactionDummyData = { chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -124,7 +121,6 @@ export const transactionDummyData = { chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -156,7 +152,6 @@ export const transactionDummyData = { chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -190,7 +185,6 @@ export const transactionDummyData = { chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -222,7 +216,6 @@ export const transactionDummyData = { chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, diff --git a/components/brave_wallet_ui/stories/mock-data/mock-transaction-info.ts b/components/brave_wallet_ui/stories/mock-data/mock-transaction-info.ts index eb1e9ccae59..a79b834db36 100644 --- a/components/brave_wallet_ui/stories/mock-data/mock-transaction-info.ts +++ b/components/brave_wallet_ui/stories/mock-data/mock-transaction-info.ts @@ -57,7 +57,6 @@ export const mockTransactionInfo: SerializableTransactionInfo = { chainId: '0x0', maxPriorityFeePerGas: '80410000', // (0.08041 gwei) maxFeePerGas: '3600000000', // (3.6 gwei) - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -384,15 +383,6 @@ export const mockEthSendTransaction = { chainId: '0xaa36a7', maxPriorityFeePerGas: '0x2faf080', maxFeePerGas: '0x2faf092', - gasEstimation: { - slowMaxPriorityFeePerGas: '0x2', - slowMaxFeePerGas: '0x14', - avgMaxPriorityFeePerGas: '0x2faf080', - avgMaxFeePerGas: '0x2faf092', - fastMaxPriorityFeePerGas: '0x59682f00', - fastMaxFeePerGas: '0x59682f12', - baseFeePerGas: '0x12', - }, }, }, txStatus: 4, @@ -546,15 +536,6 @@ export const mockERC20TransferTransaction: SerializableTransactionInfo = { chainId: BraveWallet.MAINNET_CHAIN_ID, maxPriorityFeePerGas: '0x2faf080', maxFeePerGas: '0x2faf092', - gasEstimation: { - slowMaxPriorityFeePerGas: '0x2', - slowMaxFeePerGas: '0x14', - avgMaxPriorityFeePerGas: '0x2faf080', - avgMaxFeePerGas: '0x2faf092', - fastMaxPriorityFeePerGas: '0x59682f00', - fastMaxFeePerGas: '0x59682f12', - baseFeePerGas: '0x12', - }, baseData: { nonce: '0xb', gasPrice: '0x0', @@ -657,15 +638,6 @@ export const createMockTransactionInfo = (arg: { chainId, maxPriorityFeePerGas: '0x2faf080', maxFeePerGas: '0x2faf092', - gasEstimation: { - slowMaxPriorityFeePerGas: '0x2', - slowMaxFeePerGas: '0x14', - avgMaxPriorityFeePerGas: '0x2faf080', - avgMaxFeePerGas: '0x2faf092', - fastMaxPriorityFeePerGas: '0x59682f00', - fastMaxFeePerGas: '0x59682f12', - baseFeePerGas: '0x12', - }, baseData: { ...txBase.txDataUnion.ethTxData1559?.baseData, data: [], @@ -928,7 +900,6 @@ export const mockETHNativeTokenSendTransaction = { chainId: '', maxPriorityFeePerGas: '', maxFeePerGas: '', - gasEstimation: undefined, }, }, } diff --git a/components/brave_wallet_ui/stories/wallet-extension-panels.tsx b/components/brave_wallet_ui/stories/wallet-extension-panels.tsx index 58068e4e79b..83bb15a1594 100644 --- a/components/brave_wallet_ui/stories/wallet-extension-panels.tsx +++ b/components/brave_wallet_ui/stories/wallet-extension-panels.tsx @@ -75,7 +75,6 @@ const transactionDummyData: SerializableTransactionInfo[][] = [ chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -115,7 +114,6 @@ const transactionDummyData: SerializableTransactionInfo[][] = [ chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -155,7 +153,6 @@ const transactionDummyData: SerializableTransactionInfo[][] = [ chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -195,7 +192,6 @@ const transactionDummyData: SerializableTransactionInfo[][] = [ chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -235,7 +231,6 @@ const transactionDummyData: SerializableTransactionInfo[][] = [ chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -277,7 +272,6 @@ const transactionDummyData: SerializableTransactionInfo[][] = [ chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, @@ -317,7 +311,6 @@ const transactionDummyData: SerializableTransactionInfo[][] = [ chainId: '', maxFeePerGas: '', maxPriorityFeePerGas: '', - gasEstimation: undefined, }, ethTxData: undefined, solanaTxData: undefined, diff --git a/components/brave_wallet_ui/utils/tx-utils.test.ts b/components/brave_wallet_ui/utils/tx-utils.test.ts index c36ec9b99dd..4e8e34dae62 100644 --- a/components/brave_wallet_ui/utils/tx-utils.test.ts +++ b/components/brave_wallet_ui/utils/tx-utils.test.ts @@ -1167,7 +1167,6 @@ describe('isCancelTransaction', () => { chainId: '0x1', maxPriorityFeePerGas: '0x0', maxFeePerGas: '0x0', - gasEstimation: undefined, }, }, } @@ -1188,7 +1187,6 @@ describe('isCancelTransaction', () => { chainId: '0x1', maxPriorityFeePerGas: '0x0', maxFeePerGas: '0x0', - gasEstimation: undefined, }, }, txStatus: BraveWallet.TransactionStatus.Submitted, @@ -1236,7 +1234,6 @@ describe('isCancelTransaction', () => { chainId: '0x1', maxPriorityFeePerGas: '0x0', maxFeePerGas: '0x0', - gasEstimation: undefined, }, }, } diff --git a/ios/brave-ios/Sources/BraveWallet/Crypto/Stores/TransactionConfirmationStore.swift b/ios/brave-ios/Sources/BraveWallet/Crypto/Stores/TransactionConfirmationStore.swift index 3b09539f66d..1bb4eb558fa 100644 --- a/ios/brave-ios/Sources/BraveWallet/Crypto/Stores/TransactionConfirmationStore.swift +++ b/ios/brave-ios/Sources/BraveWallet/Crypto/Stores/TransactionConfirmationStore.swift @@ -369,7 +369,7 @@ public class TransactionConfirmationStore: ObservableObject, WalletObserverStore let solEstimatedTxFee: UInt64? = solEstimatedTxFeeCache[transaction.id] if transaction.isEIP1559Transaction { - eip1559GasEstimation = transaction.txDataUnion.ethTxData1559?.gasEstimation + eip1559GasEstimation = await ethTxManagerProxy.gasEstimation1559(chainId: network.chainId) } guard diff --git a/ios/brave-ios/Sources/BraveWallet/PreviewContent/MockContent.swift b/ios/brave-ios/Sources/BraveWallet/PreviewContent/MockContent.swift index fb576022519..6adc50449cd 100644 --- a/ios/brave-ios/Sources/BraveWallet/PreviewContent/MockContent.swift +++ b/ios/brave-ios/Sources/BraveWallet/PreviewContent/MockContent.swift @@ -281,8 +281,7 @@ extension BraveWallet.TransactionInfo { ), chainId: BraveWallet.MainnetChainId, maxPriorityFeePerGas: "0x2540be400", - maxFeePerGas: "0x25b7f3d400", - gasEstimation: nil + maxFeePerGas: "0x25b7f3d400" ) ), txStatus: .confirmed, @@ -322,8 +321,7 @@ extension BraveWallet.TransactionInfo { ), chainId: BraveWallet.MainnetChainId, maxPriorityFeePerGas: "0x77359400", - maxFeePerGas: "0x39bdf3b000", - gasEstimation: nil + maxFeePerGas: "0x39bdf3b000" ) ), txStatus: .confirmed, @@ -374,8 +372,7 @@ extension BraveWallet.TransactionInfo { ), chainId: BraveWallet.MainnetChainId, maxPriorityFeePerGas: "0x77359400", - maxFeePerGas: "0x39bdf3b000", - gasEstimation: nil + maxFeePerGas: "0x39bdf3b000" ) ), txStatus: .confirmed, @@ -418,8 +415,7 @@ extension BraveWallet.TransactionInfo { ), chainId: BraveWallet.MainnetChainId, maxPriorityFeePerGas: "", - maxFeePerGas: "", - gasEstimation: nil + maxFeePerGas: "" ) ), txStatus: .confirmed, diff --git a/ios/brave-ios/Tests/BraveWalletTests/TransactionParserTests.swift b/ios/brave-ios/Tests/BraveWalletTests/TransactionParserTests.swift index 1a895bc486e..3cb50d0f33d 100644 --- a/ios/brave-ios/Tests/BraveWalletTests/TransactionParserTests.swift +++ b/ios/brave-ios/Tests/BraveWalletTests/TransactionParserTests.swift @@ -177,15 +177,6 @@ class TransactionParserTests: XCTestCase { ), ] - let mockGasEstimation = BraveWallet.GasEstimation1559( - slowMaxPriorityFeePerGas: "0x0", - slowMaxFeePerGas: "0x9", - avgMaxPriorityFeePerGas: "0x59672ead", - avgMaxFeePerGas: "0x59672eb6", - fastMaxPriorityFeePerGas: "0x59682f00", - fastMaxFeePerGas: "0x59682f09", - baseFeePerGas: "0x9" - ) let mockSwapGasEstimation = BraveWallet.GasEstimation1559( slowMaxPriorityFeePerGas: "0x4ed3152b", slowMaxFeePerGas: "0x4ed31534", @@ -243,8 +234,7 @@ class TransactionParserTests: XCTestCase { ), chainId: network.chainId, maxPriorityFeePerGas: "0x59672ead", - maxFeePerGas: "0x59672eb6", - gasEstimation: mockGasEstimation + maxFeePerGas: "0x59672eb6" ) let transaction = mockTransaction( fromAccount: accountInfos[0], @@ -328,8 +318,7 @@ class TransactionParserTests: XCTestCase { ), chainId: network.chainId, maxPriorityFeePerGas: "0x59672ead", - maxFeePerGas: "0x59672eb6", - gasEstimation: mockGasEstimation + maxFeePerGas: "0x59672eb6" ) let transaction = mockTransaction( fromAccount: accountInfos[0], @@ -396,8 +385,7 @@ class TransactionParserTests: XCTestCase { ), chainId: network.chainId, maxPriorityFeePerGas: "0x59682f00", - maxFeePerGas: "0x59682f09", - gasEstimation: mockSwapGasEstimation + maxFeePerGas: "0x59682f09" ) let transaction = mockTransaction( fromAccount: accountInfos[0], @@ -482,8 +470,7 @@ class TransactionParserTests: XCTestCase { ), chainId: network.chainId, maxPriorityFeePerGas: "0x59682f00", - maxFeePerGas: "0x59682f09", - gasEstimation: mockSwapGasEstimation + maxFeePerGas: "0x59682f09" ) let transaction = mockTransaction( fromAccount: accountInfos[0], @@ -568,8 +555,7 @@ class TransactionParserTests: XCTestCase { ), chainId: network.chainId, maxPriorityFeePerGas: "0x59682f00", - maxFeePerGas: "0x59682f09", - gasEstimation: mockGasEstimation + maxFeePerGas: "0x59682f09" ) let transaction = mockTransaction( fromAccount: accountInfos[0], @@ -638,8 +624,7 @@ class TransactionParserTests: XCTestCase { ), chainId: network.chainId, maxPriorityFeePerGas: "0x59682f00", - maxFeePerGas: "0x59682f09", - gasEstimation: mockGasEstimation + maxFeePerGas: "0x59682f09" ) let transaction = mockTransaction( fromAccount: accountInfos[0], @@ -709,8 +694,7 @@ class TransactionParserTests: XCTestCase { ), chainId: network.chainId, maxPriorityFeePerGas: "0x59672ead", - maxFeePerGas: "0x59672eb6", - gasEstimation: mockGasEstimation + maxFeePerGas: "0x59672eb6" ) let transaction = mockTransaction( fromAccount: accountInfos[0],