1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Stop throwing an error when adding gas defaults for a simple send, that has data, to an address without a response code (#15424)

* Stop throwing an error when adding gas defaults for a simple send, that has data, to an address without a response code

* Lint fix

* fixup lint

Co-authored-by: brad-decker <bhdecker84@gmail.com>
This commit is contained in:
Dan J Miller 2022-08-02 22:14:21 -02:30
parent 109e46c95f
commit 50f8be1673

View File

@ -17,7 +17,6 @@ import {
addHexPrefix,
getChainType,
} from '../../lib/util';
import { TRANSACTION_NO_CONTRACT_ERROR_KEY } from '../../../../ui/helpers/constants/error-keys';
import { calcGasTotal } from '../../../../ui/pages/send/send.utils';
import { getSwapsTokensReceivedFromTxMeta } from '../../../../ui/pages/swaps/swaps.util';
import {
@ -1006,10 +1005,9 @@ export default class TransactionController extends EventEmitter {
* Gets default gas limit, or debug information about why gas estimate failed.
*
* @param {Object} txMeta - The txMeta object
* @param {string} getCodeResponse - The transaction category code response, used for debugging purposes
* @returns {Promise<Object>} Object containing the default gas limit, or the simulation failure object
*/
async _getDefaultGasLimit(txMeta, getCodeResponse) {
async _getDefaultGasLimit(txMeta) {
const chainId = this._getCurrentChainId();
const customNetworkGasBuffer = CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP[chainId];
const chainType = getChainType(chainId);
@ -1019,21 +1017,9 @@ export default class TransactionController extends EventEmitter {
} else if (
txMeta.txParams.to &&
txMeta.type === TRANSACTION_TYPES.SIMPLE_SEND &&
chainType !== 'custom'
chainType !== 'custom' &&
!txMeta.txParams.data
) {
// if there's data in the params, but there's no contract code, it's not a valid transaction
if (txMeta.txParams.data) {
const err = new Error(
'TxGasUtil - Trying to call a function on a non-contract address',
);
// set error key so ui can display localized error message
err.errorKey = TRANSACTION_NO_CONTRACT_ERROR_KEY;
// set the response on the error so that we can see in logs what the actual response was
err.getCodeResponse = getCodeResponse;
throw err;
}
// This is a standard ether simple send, gas requirement is exactly 21k
return { gasLimit: GAS_LIMITS.SIMPLE };
}