Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add networkClientId to estimateGas function #12958

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 });
};

Expand Down
21 changes: 16 additions & 5 deletions app/components/Views/confirmations/SendFlow/Amount/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import Alert, { AlertType } from '../../../../Base/Alert';

import {
selectChainId,
selectNetworkClientId,
selectProviderType,
selectTicker,
} from '../../../../../selectors/networkController';
Expand Down Expand Up @@ -490,6 +491,10 @@ class Amount extends PureComponent {
* Function that sets the max value mode
*/
setMaxValueMode: PropTypes.func,
/**
* Network client id
*/
networkClientId: PropTypes.string,
};

state = {
Expand Down Expand Up @@ -877,10 +882,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;
};
Expand Down Expand Up @@ -940,7 +950,7 @@ class Amount extends PureComponent {
} = this.props;
const { internalPrimaryCurrencyIsCrypto } = this.state;

setMaxValueMode(useMax ?? false)
setMaxValueMode(useMax ?? false);

let inputValueConversion,
renderableInputValueConversion,
Expand Down Expand Up @@ -1570,6 +1580,7 @@ const mapStateToProps = (state, ownProps) => ({
),
swapsIsLive: swapsLivenessSelector(state),
chainId: selectChainId(state),
networkClientId: selectNetworkClientId(state),
OGPoyraz marked this conversation as resolved.
Show resolved Hide resolved
});

const mapDispatchToProps = (dispatch) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
};

Expand Down
8 changes: 6 additions & 2 deletions app/util/custom-gas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading