mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Ensure transaction controller correctly estimates gas for special custom networks (#11441)
This commit is contained in:
parent
8ca0d24f82
commit
932444c355
@ -16,6 +16,7 @@ import {
|
||||
bnToHex,
|
||||
BnMultiplyByFraction,
|
||||
addHexPrefix,
|
||||
getChainType,
|
||||
} from '../../lib/util';
|
||||
import { TRANSACTION_NO_CONTRACT_ERROR_KEY } from '../../../../ui/helpers/constants/error-keys';
|
||||
import { getSwapsTokensReceivedFromTxMeta } from '../../../../ui/pages/swaps/swaps.util';
|
||||
@ -29,6 +30,7 @@ import {
|
||||
HARDFORKS,
|
||||
MAINNET,
|
||||
NETWORK_TYPE_RPC,
|
||||
CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP,
|
||||
} from '../../../../shared/constants/network';
|
||||
import { isEIP1559Transaction } from '../../../../shared/modules/transaction.utils';
|
||||
import TransactionStateManager from './tx-state-manager';
|
||||
@ -423,11 +425,16 @@ export default class TransactionController extends EventEmitter {
|
||||
* @returns {Promise<Object>} Object containing the default gas limit, or the simulation failure object
|
||||
*/
|
||||
async _getDefaultGasLimit(txMeta, getCodeResponse) {
|
||||
const chainId = this._getCurrentChainId();
|
||||
const customNetworkGasBuffer = CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP[chainId];
|
||||
const chainType = getChainType(chainId);
|
||||
|
||||
if (txMeta.txParams.gas) {
|
||||
return {};
|
||||
} else if (
|
||||
txMeta.txParams.to &&
|
||||
txMeta.type === TRANSACTION_TYPES.SENT_ETHER
|
||||
txMeta.type === TRANSACTION_TYPES.SENT_ETHER &&
|
||||
chainType !== 'custom'
|
||||
) {
|
||||
// if there's data in the params, but there's no contract code, it's not a valid transaction
|
||||
if (txMeta.txParams.data) {
|
||||
@ -456,6 +463,7 @@ export default class TransactionController extends EventEmitter {
|
||||
const gasLimit = this.txGasUtil.addGasBuffer(
|
||||
addHexPrefix(estimatedGasHex),
|
||||
blockGasLimit,
|
||||
customNetworkGasBuffer,
|
||||
);
|
||||
return { gasLimit, simulationFails };
|
||||
}
|
||||
|
@ -2,6 +2,10 @@ import extension from 'extensionizer';
|
||||
import { stripHexPrefix } from 'ethereumjs-util';
|
||||
import BN from 'bn.js';
|
||||
import { memoize } from 'lodash';
|
||||
import {
|
||||
MAINNET_CHAIN_ID,
|
||||
TEST_CHAINS,
|
||||
} from '../../../shared/constants/network';
|
||||
|
||||
import {
|
||||
ENVIRONMENT_TYPE_POPUP,
|
||||
@ -146,6 +150,15 @@ function bnToHex(inputBn) {
|
||||
return addHexPrefix(inputBn.toString(16));
|
||||
}
|
||||
|
||||
function getChainType(chainId) {
|
||||
if (chainId === MAINNET_CHAIN_ID) {
|
||||
return 'mainnet';
|
||||
} else if (TEST_CHAINS.includes(chainId)) {
|
||||
return 'testnet';
|
||||
}
|
||||
return 'custom';
|
||||
}
|
||||
|
||||
export {
|
||||
getPlatform,
|
||||
getEnvironmentType,
|
||||
@ -154,4 +167,5 @@ export {
|
||||
checkForError,
|
||||
addHexPrefix,
|
||||
bnToHex,
|
||||
getChainType,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user