From 458aac4824eebde637c44c5999d9c09f78a77921 Mon Sep 17 00:00:00 2001 From: OGPoyraz Date: Mon, 13 Jan 2025 15:43:11 +0100 Subject: [PATCH 1/2] Add networkClientId to estimateGas function --- .../confirmations/ApproveView/Approve/index.js | 10 ++++++++-- .../confirmations/SendFlow/Amount/index.js | 17 ++++++++++++----- .../confirmations/SendFlow/Confirm/index.js | 3 ++- app/util/custom-gas/index.js | 8 ++++++-- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/components/Views/confirmations/ApproveView/Approve/index.js b/app/components/Views/confirmations/ApproveView/Approve/index.js index fb32c1182a0..61e2ceafcd3 100644 --- a/app/components/Views/confirmations/ApproveView/Approve/index.js +++ b/app/components/Views/confirmations/ApproveView/Approve/index.js @@ -282,7 +282,8 @@ class Approve extends PureComponent { }; setNetworkNonce = async () => { - const { networkClientId, setNonce, setProposedNonce, transaction } = this.props; + const { networkClientId, setNonce, setProposedNonce, transaction } = + this.props; const proposedNonce = await getNetworkNonce(transaction, networkClientId); setNonce(proposedNonce); setProposedNonce(proposedNonce); @@ -308,8 +309,13 @@ class Approve extends PureComponent { }; handleGetGasLimit = async () => { + const { networkClientId } = this.props; const { setTransactionObject, transaction } = this.props; - const estimation = await getGasLimit({ ...transaction, gas: undefined }); + const estimation = await getGasLimit( + { ...transaction, gas: undefined }, + false, + networkClientId, + ); setTransactionObject({ gas: estimation.gas }); }; diff --git a/app/components/Views/confirmations/SendFlow/Amount/index.js b/app/components/Views/confirmations/SendFlow/Amount/index.js index cf6319415fe..c7b6194b071 100644 --- a/app/components/Views/confirmations/SendFlow/Amount/index.js +++ b/app/components/Views/confirmations/SendFlow/Amount/index.js @@ -79,6 +79,7 @@ import Alert, { AlertType } from '../../../../Base/Alert'; import { selectChainId, + selectNetworkClientId, selectProviderType, selectTicker, } from '../../../../../selectors/networkController'; @@ -877,10 +878,15 @@ class Amount extends PureComponent { transaction: { from }, transactionTo, } = this.props.transactionState; - const { gas } = await getGasLimit({ - from, - to: transactionTo, - }); + const { networkClientId } = this.props; + const { gas } = await getGasLimit( + { + from, + to: transactionTo, + }, + false, + networkClientId, + ); return gas; }; @@ -940,7 +946,7 @@ class Amount extends PureComponent { } = this.props; const { internalPrimaryCurrencyIsCrypto } = this.state; - setMaxValueMode(useMax ?? false) + setMaxValueMode(useMax ?? false); let inputValueConversion, renderableInputValueConversion, @@ -1570,6 +1576,7 @@ const mapStateToProps = (state, ownProps) => ({ ), swapsIsLive: swapsLivenessSelector(state), chainId: selectChainId(state), + networkClientId: selectNetworkClientId(state), }); const mapDispatchToProps = (dispatch) => ({ diff --git a/app/components/Views/confirmations/SendFlow/Confirm/index.js b/app/components/Views/confirmations/SendFlow/Confirm/index.js index 3226eb5f79e..6153161ec83 100644 --- a/app/components/Views/confirmations/SendFlow/Confirm/index.js +++ b/app/components/Views/confirmations/SendFlow/Confirm/index.js @@ -718,7 +718,8 @@ class Confirm extends PureComponent { prepareTransaction, transactionState: { transaction }, } = this.props; - const estimation = await getGasLimit(transaction, true); + const { networkClientId } = this.props; + const estimation = await getGasLimit(transaction, true, networkClientId); prepareTransaction({ ...transaction, ...estimation }); }; diff --git a/app/util/custom-gas/index.js b/app/util/custom-gas/index.js index 3583b88fab3..72c4894a476 100644 --- a/app/util/custom-gas/index.js +++ b/app/util/custom-gas/index.js @@ -107,14 +107,18 @@ export function parseWaitTime(min) { return parsed.trim(); } -export async function getGasLimit(transaction, resetGas = false) { +export async function getGasLimit( + transaction, + resetGas = false, + networkClientId, +) { let estimation; try { const newTransactionObj = resetGas ? { ...transaction, gas: undefined, gasPrice: undefined } : transaction; - estimation = await estimateGas(newTransactionObj); + estimation = await estimateGas(newTransactionObj, networkClientId); } catch (error) { estimation = { gas: TransactionTypes.CUSTOM_GAS.DEFAULT_GAS_LIMIT, From cd0fdeb3cc655a79a14326542f7265a059b4b435 Mon Sep 17 00:00:00 2001 From: OGPoyraz Date: Mon, 13 Jan 2025 15:44:58 +0100 Subject: [PATCH 2/2] Fix lint --- app/components/Views/confirmations/SendFlow/Amount/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/components/Views/confirmations/SendFlow/Amount/index.js b/app/components/Views/confirmations/SendFlow/Amount/index.js index c7b6194b071..0479f7edf2d 100644 --- a/app/components/Views/confirmations/SendFlow/Amount/index.js +++ b/app/components/Views/confirmations/SendFlow/Amount/index.js @@ -491,6 +491,10 @@ class Amount extends PureComponent { * Function that sets the max value mode */ setMaxValueMode: PropTypes.func, + /** + * Network client id + */ + networkClientId: PropTypes.string, }; state = {