From 50f8be16738c4a6d852c62f481df8c43ec11741b Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Tue, 2 Aug 2022 22:14:21 -0230 Subject: [PATCH] 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 --- app/scripts/controllers/transactions/index.js | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index 87d56c714..e0023b22c 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -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 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 }; }