mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Add gas constants (#11248)
This commit is contained in:
parent
64e6935558
commit
df9bc52e9f
@ -1,4 +1,5 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
|
import { GAS_LIMITS } from '../../../../shared/constants/gas';
|
||||||
import { txMetaStub } from '../../../../test/stub/tx-meta-stub';
|
import { txMetaStub } from '../../../../test/stub/tx-meta-stub';
|
||||||
import {
|
import {
|
||||||
createPendingNonceMiddleware,
|
createPendingNonceMiddleware,
|
||||||
@ -55,7 +56,7 @@ describe('PendingNonceMiddleware', function () {
|
|||||||
blockHash: null,
|
blockHash: null,
|
||||||
blockNumber: null,
|
blockNumber: null,
|
||||||
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x1e8480',
|
gasPrice: '0x1e8480',
|
||||||
hash:
|
hash:
|
||||||
'0x2cc5a25744486f7383edebbf32003e5a66e18135799593d6b5cdd2bb43674f09',
|
'0x2cc5a25744486f7383edebbf32003e5a66e18135799593d6b5cdd2bb43674f09',
|
||||||
|
@ -23,6 +23,7 @@ import {
|
|||||||
TRANSACTION_TYPES,
|
TRANSACTION_TYPES,
|
||||||
} from '../../../../shared/constants/transaction';
|
} from '../../../../shared/constants/transaction';
|
||||||
import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller';
|
import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller';
|
||||||
|
import { GAS_LIMITS } from '../../../../shared/constants/gas';
|
||||||
import TransactionStateManager from './tx-state-manager';
|
import TransactionStateManager from './tx-state-manager';
|
||||||
import TxGasUtil from './tx-gas-utils';
|
import TxGasUtil from './tx-gas-utils';
|
||||||
import PendingTransactionTracker from './pending-tx-tracker';
|
import PendingTransactionTracker from './pending-tx-tracker';
|
||||||
@ -30,7 +31,6 @@ import * as txUtils from './lib/util';
|
|||||||
|
|
||||||
const hstInterface = new ethers.utils.Interface(abi);
|
const hstInterface = new ethers.utils.Interface(abi);
|
||||||
|
|
||||||
const SIMPLE_GAS_COST = '0x5208'; // Hex for 21000, cost of a simple send.
|
|
||||||
const MAX_MEMSTORE_TX_LIST_SIZE = 100; // Number of transactions (by unique nonces) to keep in memory
|
const MAX_MEMSTORE_TX_LIST_SIZE = 100; // Number of transactions (by unique nonces) to keep in memory
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -366,7 +366,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This is a standard ether simple send, gas requirement is exactly 21k
|
// This is a standard ether simple send, gas requirement is exactly 21k
|
||||||
return { gasLimit: SIMPLE_GAS_COST };
|
return { gasLimit: GAS_LIMITS.SIMPLE };
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -404,7 +404,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
from,
|
from,
|
||||||
to: from,
|
to: from,
|
||||||
nonce,
|
nonce,
|
||||||
gas: customGasLimit || '0x5208',
|
gas: customGasLimit || GAS_LIMITS.SIMPLE,
|
||||||
value: '0x0',
|
value: '0x0',
|
||||||
gasPrice: newGasPrice,
|
gasPrice: newGasPrice,
|
||||||
},
|
},
|
||||||
|
9
shared/constants/gas.js
Normal file
9
shared/constants/gas.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { addHexPrefix } from 'ethereumjs-util';
|
||||||
|
import { decimalToHex } from '../../ui/helpers/utils/conversions.util';
|
||||||
|
|
||||||
|
export const GAS_LIMITS = {
|
||||||
|
// maximum gasLimit of a simple send
|
||||||
|
SIMPLE: addHexPrefix(decimalToHex(21_000)),
|
||||||
|
// a base estimate for token transfers.
|
||||||
|
BASE_TOKEN_ESTIMATE: addHexPrefix(decimalToHex(100_000)),
|
||||||
|
};
|
@ -1,3 +1,4 @@
|
|||||||
|
import { GAS_LIMITS } from '../../shared/constants/gas';
|
||||||
import {
|
import {
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
TRANSACTION_TYPES,
|
TRANSACTION_TYPES,
|
||||||
@ -16,7 +17,7 @@ export const txMetaStub = {
|
|||||||
type: TRANSACTION_TYPES.SENT_ETHER,
|
type: TRANSACTION_TYPES.SENT_ETHER,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x1e8480',
|
gasPrice: '0x1e8480',
|
||||||
to: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
to: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||||
value: '0x0',
|
value: '0x0',
|
||||||
@ -197,7 +198,7 @@ export const txMetaStub = {
|
|||||||
type: TRANSACTION_TYPES.SENT_ETHER,
|
type: TRANSACTION_TYPES.SENT_ETHER,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x1e8480',
|
gasPrice: '0x1e8480',
|
||||||
nonce: '0x4',
|
nonce: '0x4',
|
||||||
to: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
to: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||||
|
@ -56,6 +56,7 @@ import {
|
|||||||
import { MIN_GAS_LIMIT_DEC } from '../../../../pages/send/send.constants';
|
import { MIN_GAS_LIMIT_DEC } from '../../../../pages/send/send.constants';
|
||||||
import { calcMaxAmount } from '../../../../pages/send/send-content/send-amount-row/amount-max-button/amount-max-button.utils';
|
import { calcMaxAmount } from '../../../../pages/send/send-content/send-amount-row/amount-max-button/amount-max-button.utils';
|
||||||
import { TRANSACTION_STATUSES } from '../../../../../shared/constants/transaction';
|
import { TRANSACTION_STATUSES } from '../../../../../shared/constants/transaction';
|
||||||
|
import { GAS_LIMITS } from '../../../../../shared/constants/gas';
|
||||||
import GasModalPageContainer from './gas-modal-page-container.component';
|
import GasModalPageContainer from './gas-modal-page-container.component';
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => {
|
const mapStateToProps = (state, ownProps) => {
|
||||||
@ -73,7 +74,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
const txParams = selectedTransaction?.txParams
|
const txParams = selectedTransaction?.txParams
|
||||||
? selectedTransaction.txParams
|
? selectedTransaction.txParams
|
||||||
: {
|
: {
|
||||||
gas: send.gasLimit || '0x5208',
|
gas: send.gasLimit || GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: send.gasPrice || getAveragePriceEstimateInHexWEI(state, true),
|
gasPrice: send.gasPrice || getAveragePriceEstimateInHexWEI(state, true),
|
||||||
value: sendToken ? '0x0' : send.amount,
|
value: sendToken ? '0x0' : send.amount,
|
||||||
};
|
};
|
||||||
@ -82,7 +83,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
const value = ownProps.transaction?.txParams?.value || txParams.value;
|
const value = ownProps.transaction?.txParams?.value || txParams.value;
|
||||||
const customModalGasPriceInHex = getCustomGasPrice(state) || currentGasPrice;
|
const customModalGasPriceInHex = getCustomGasPrice(state) || currentGasPrice;
|
||||||
const customModalGasLimitInHex =
|
const customModalGasLimitInHex =
|
||||||
getCustomGasLimit(state) || currentGasLimit || '0x5208';
|
getCustomGasLimit(state) || currentGasLimit || GAS_LIMITS.SIMPLE;
|
||||||
const customGasTotal = calcGasTotal(
|
const customGasTotal = calcGasTotal(
|
||||||
customModalGasLimitInHex,
|
customModalGasLimitInHex,
|
||||||
customModalGasPriceInHex,
|
customModalGasPriceInHex,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { GAS_LIMITS } from '../../../../shared/constants/gas';
|
||||||
import {
|
import {
|
||||||
ROPSTEN_CHAIN_ID,
|
ROPSTEN_CHAIN_ID,
|
||||||
ROPSTEN_NETWORK_ID,
|
ROPSTEN_NETWORK_ID,
|
||||||
@ -34,7 +35,7 @@ describe('TransactionActivityLog utils', () => {
|
|||||||
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
|
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
|
||||||
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
||||||
value: '0x2386f26fc10000',
|
value: '0x2386f26fc10000',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
},
|
},
|
||||||
type: TRANSACTION_TYPES.STANDARD,
|
type: TRANSACTION_TYPES.STANDARD,
|
||||||
@ -82,7 +83,7 @@ describe('TransactionActivityLog utils', () => {
|
|||||||
time: 1543958845581,
|
time: 1543958845581,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
|
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
nonce: '0x32',
|
nonce: '0x32',
|
||||||
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
||||||
@ -105,7 +106,7 @@ describe('TransactionActivityLog utils', () => {
|
|||||||
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
|
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
|
||||||
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
||||||
value: '0x2386f26fc10000',
|
value: '0x2386f26fc10000',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
nonce: '0x32',
|
nonce: '0x32',
|
||||||
},
|
},
|
||||||
@ -176,7 +177,7 @@ describe('TransactionActivityLog utils', () => {
|
|||||||
time: 1543958857697,
|
time: 1543958857697,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
|
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x481f2280',
|
gasPrice: '0x481f2280',
|
||||||
nonce: '0x32',
|
nonce: '0x32',
|
||||||
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
||||||
@ -244,7 +245,7 @@ describe('TransactionActivityLog utils', () => {
|
|||||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0x1',
|
from: '0x1',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
nonce: '0xa4',
|
nonce: '0xa4',
|
||||||
to: '0x2',
|
to: '0x2',
|
||||||
@ -267,7 +268,7 @@ describe('TransactionActivityLog utils', () => {
|
|||||||
time: 1535507561452,
|
time: 1535507561452,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0x1',
|
from: '0x1',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
nonce: '0xa4',
|
nonce: '0xa4',
|
||||||
to: '0x2',
|
to: '0x2',
|
||||||
@ -395,7 +396,7 @@ describe('TransactionActivityLog utils', () => {
|
|||||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0x1',
|
from: '0x1',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
nonce: '0xa4',
|
nonce: '0xa4',
|
||||||
to: '0x2',
|
to: '0x2',
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction';
|
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction';
|
||||||
|
import { GAS_LIMITS } from '../../../../shared/constants/gas';
|
||||||
import TransactionBreakdown from './transaction-breakdown.component';
|
import TransactionBreakdown from './transaction-breakdown.component';
|
||||||
|
|
||||||
describe('TransactionBreakdown Component', () => {
|
describe('TransactionBreakdown Component', () => {
|
||||||
@ -11,7 +12,7 @@ describe('TransactionBreakdown Component', () => {
|
|||||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0x1',
|
from: '0x1',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
nonce: '0xa4',
|
nonce: '0xa4',
|
||||||
to: '0x2',
|
to: '0x2',
|
||||||
|
@ -5,6 +5,7 @@ import SenderToRecipient from '../../ui/sender-to-recipient';
|
|||||||
import TransactionBreakdown from '../transaction-breakdown';
|
import TransactionBreakdown from '../transaction-breakdown';
|
||||||
import TransactionActivityLog from '../transaction-activity-log';
|
import TransactionActivityLog from '../transaction-activity-log';
|
||||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction';
|
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction';
|
||||||
|
import { GAS_LIMITS } from '../../../../shared/constants/gas';
|
||||||
import TransactionListItemDetails from './transaction-list-item-details.component';
|
import TransactionListItemDetails from './transaction-list-item-details.component';
|
||||||
|
|
||||||
describe('TransactionListItemDetails Component', () => {
|
describe('TransactionListItemDetails Component', () => {
|
||||||
@ -15,7 +16,7 @@ describe('TransactionListItemDetails Component', () => {
|
|||||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0x1',
|
from: '0x1',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
nonce: '0xa4',
|
nonce: '0xa4',
|
||||||
to: '0x2',
|
to: '0x2',
|
||||||
@ -57,7 +58,7 @@ describe('TransactionListItemDetails Component', () => {
|
|||||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0x1',
|
from: '0x1',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
nonce: '0xa4',
|
nonce: '0xa4',
|
||||||
to: '0x2',
|
to: '0x2',
|
||||||
@ -102,7 +103,7 @@ describe('TransactionListItemDetails Component', () => {
|
|||||||
status: 'confirmed',
|
status: 'confirmed',
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0x1',
|
from: '0x1',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
nonce: '0xa4',
|
nonce: '0xa4',
|
||||||
to: '0x2',
|
to: '0x2',
|
||||||
@ -146,7 +147,7 @@ describe('TransactionListItemDetails Component', () => {
|
|||||||
hash: '0xaa',
|
hash: '0xaa',
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0x1',
|
from: '0x1',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
nonce: '0xa4',
|
nonce: '0xa4',
|
||||||
to: '0x2',
|
to: '0x2',
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { GAS_LIMITS } from '../../../shared/constants/gas';
|
||||||
import * as utils from './confirm-tx.util';
|
import * as utils from './confirm-tx.util';
|
||||||
|
|
||||||
describe('Confirm Transaction utils', () => {
|
describe('Confirm Transaction utils', () => {
|
||||||
@ -34,7 +35,10 @@ describe('Confirm Transaction utils', () => {
|
|||||||
describe('getHexGasTotal', () => {
|
describe('getHexGasTotal', () => {
|
||||||
it('should multiply the hex gasLimit and hex gasPrice values together', () => {
|
it('should multiply the hex gasLimit and hex gasPrice values together', () => {
|
||||||
expect(
|
expect(
|
||||||
utils.getHexGasTotal({ gasLimit: '0x5208', gasPrice: '0x3b9aca00' }),
|
utils.getHexGasTotal({
|
||||||
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
|
gasPrice: '0x3b9aca00',
|
||||||
|
}),
|
||||||
).toStrictEqual('0x1319718a5000');
|
).toStrictEqual('0x1319718a5000');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import {
|
|||||||
setCustomGasPriceForRetry,
|
setCustomGasPriceForRetry,
|
||||||
} from '../ducks/gas/gas.duck';
|
} from '../ducks/gas/gas.duck';
|
||||||
import { multiplyCurrencies } from '../helpers/utils/conversion-util';
|
import { multiplyCurrencies } from '../helpers/utils/conversion-util';
|
||||||
|
import { GAS_LIMITS } from '../../shared/constants/gas';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether a transaction can be cancelled and provide a method to
|
* Determine whether a transaction can be cancelled and provide a method to
|
||||||
@ -52,13 +53,13 @@ export function useCancelTransaction(transactionGroup) {
|
|||||||
const cancelTransaction = useCallback(
|
const cancelTransaction = useCallback(
|
||||||
(event) => {
|
(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
dispatch(setCustomGasLimit('0x5208'));
|
dispatch(setCustomGasLimit(GAS_LIMITS.SIMPLE));
|
||||||
dispatch(setCustomGasPriceForRetry(defaultNewGasPrice));
|
dispatch(setCustomGasPriceForRetry(defaultNewGasPrice));
|
||||||
const tx = {
|
const tx = {
|
||||||
...transaction,
|
...transaction,
|
||||||
txParams: {
|
txParams: {
|
||||||
...transaction.txParams,
|
...transaction.txParams,
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
value: '0x0',
|
value: '0x0',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,7 @@ import { getConversionRate, getSelectedAccount } from '../selectors';
|
|||||||
import { showModal } from '../store/actions';
|
import { showModal } from '../store/actions';
|
||||||
import { increaseLastGasPrice } from '../helpers/utils/confirm-tx.util';
|
import { increaseLastGasPrice } from '../helpers/utils/confirm-tx.util';
|
||||||
import * as actionConstants from '../store/actionConstants';
|
import * as actionConstants from '../store/actionConstants';
|
||||||
|
import { GAS_LIMITS } from '../../shared/constants/gas';
|
||||||
import { useCancelTransaction } from './useCancelTransaction';
|
import { useCancelTransaction } from './useCancelTransaction';
|
||||||
|
|
||||||
describe('useCancelTransaction', function () {
|
describe('useCancelTransaction', function () {
|
||||||
@ -77,7 +78,7 @@ describe('useCancelTransaction', function () {
|
|||||||
|
|
||||||
// call onSubmit myself
|
// call onSubmit myself
|
||||||
dispatchAction[dispatchAction.length - 1][0].value.props.onSubmit(
|
dispatchAction[dispatchAction.length - 1][0].value.props.onSubmit(
|
||||||
'0x5208',
|
GAS_LIMITS.SIMPLE,
|
||||||
'0x1',
|
'0x1',
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -86,9 +87,9 @@ describe('useCancelTransaction', function () {
|
|||||||
showModal({
|
showModal({
|
||||||
name: 'CANCEL_TRANSACTION',
|
name: 'CANCEL_TRANSACTION',
|
||||||
transactionId,
|
transactionId,
|
||||||
newGasFee: '0x5208',
|
newGasFee: GAS_LIMITS.SIMPLE,
|
||||||
defaultNewGasPrice: '0x1',
|
defaultNewGasPrice: '0x1',
|
||||||
gasLimit: '0x5208',
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
).toStrictEqual(true);
|
).toStrictEqual(true);
|
||||||
@ -147,7 +148,7 @@ describe('useCancelTransaction', function () {
|
|||||||
).toStrictEqual(transactionId);
|
).toStrictEqual(transactionId);
|
||||||
|
|
||||||
dispatchAction[dispatchAction.length - 1][0].value.props.onSubmit(
|
dispatchAction[dispatchAction.length - 1][0].value.props.onSubmit(
|
||||||
'0x5208',
|
GAS_LIMITS.SIMPLE,
|
||||||
'0x1',
|
'0x1',
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -156,9 +157,9 @@ describe('useCancelTransaction', function () {
|
|||||||
showModal({
|
showModal({
|
||||||
name: 'CANCEL_TRANSACTION',
|
name: 'CANCEL_TRANSACTION',
|
||||||
transactionId,
|
transactionId,
|
||||||
newGasFee: '0x5208',
|
newGasFee: GAS_LIMITS.SIMPLE,
|
||||||
defaultNewGasPrice: '0x1',
|
defaultNewGasPrice: '0x1',
|
||||||
gasLimit: '0x5208',
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
).toStrictEqual(true);
|
).toStrictEqual(true);
|
||||||
|
@ -38,9 +38,6 @@ const KNOWN_RECIPIENT_ADDRESS_ERROR = 'knownAddressRecipient';
|
|||||||
const CONTRACT_ADDRESS_ERROR = 'contractAddressError';
|
const CONTRACT_ADDRESS_ERROR = 'contractAddressError';
|
||||||
const CONFUSING_ENS_ERROR = 'confusingEnsDomain';
|
const CONFUSING_ENS_ERROR = 'confusingEnsDomain';
|
||||||
|
|
||||||
const SIMPLE_GAS_COST = '0x5208'; // Hex for 21000, cost of a simple send.
|
|
||||||
const BASE_TOKEN_GAS_COST = '0x186a0'; // Hex for 100000, a base estimate for token transfers.
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
INSUFFICIENT_FUNDS_ERROR,
|
INSUFFICIENT_FUNDS_ERROR,
|
||||||
INSUFFICIENT_TOKENS_ERROR,
|
INSUFFICIENT_TOKENS_ERROR,
|
||||||
@ -57,7 +54,5 @@ export {
|
|||||||
NEGATIVE_ETH_ERROR,
|
NEGATIVE_ETH_ERROR,
|
||||||
REQUIRED_ERROR,
|
REQUIRED_ERROR,
|
||||||
CONFUSING_ENS_ERROR,
|
CONFUSING_ENS_ERROR,
|
||||||
SIMPLE_GAS_COST,
|
|
||||||
TOKEN_TRANSFER_FUNCTION_SIGNATURE,
|
TOKEN_TRANSFER_FUNCTION_SIGNATURE,
|
||||||
BASE_TOKEN_GAS_COST,
|
|
||||||
};
|
};
|
||||||
|
@ -11,13 +11,12 @@ import {
|
|||||||
import { calcTokenAmount } from '../../helpers/utils/token-util';
|
import { calcTokenAmount } from '../../helpers/utils/token-util';
|
||||||
import { addHexPrefix } from '../../../app/scripts/lib/util';
|
import { addHexPrefix } from '../../../app/scripts/lib/util';
|
||||||
|
|
||||||
|
import { GAS_LIMITS } from '../../../shared/constants/gas';
|
||||||
import {
|
import {
|
||||||
BASE_TOKEN_GAS_COST,
|
|
||||||
INSUFFICIENT_FUNDS_ERROR,
|
INSUFFICIENT_FUNDS_ERROR,
|
||||||
INSUFFICIENT_TOKENS_ERROR,
|
INSUFFICIENT_TOKENS_ERROR,
|
||||||
MIN_GAS_LIMIT_HEX,
|
MIN_GAS_LIMIT_HEX,
|
||||||
NEGATIVE_ETH_ERROR,
|
NEGATIVE_ETH_ERROR,
|
||||||
SIMPLE_GAS_COST,
|
|
||||||
TOKEN_TRANSFER_FUNCTION_SIGNATURE,
|
TOKEN_TRANSFER_FUNCTION_SIGNATURE,
|
||||||
} from './send.constants';
|
} from './send.constants';
|
||||||
|
|
||||||
@ -208,10 +207,10 @@ async function estimateGasForSend({
|
|||||||
// Geth will return '0x', and ganache-core v2.2.1 will return '0x0'
|
// Geth will return '0x', and ganache-core v2.2.1 will return '0x0'
|
||||||
const codeIsEmpty = !code || code === '0x' || code === '0x0';
|
const codeIsEmpty = !code || code === '0x' || code === '0x0';
|
||||||
if (codeIsEmpty) {
|
if (codeIsEmpty) {
|
||||||
return SIMPLE_GAS_COST;
|
return GAS_LIMITS.SIMPLE;
|
||||||
}
|
}
|
||||||
} else if (sendToken && !to) {
|
} else if (sendToken && !to) {
|
||||||
return BASE_TOKEN_GAS_COST;
|
return GAS_LIMITS.BASE_TOKEN_ESTIMATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sendToken) {
|
if (sendToken) {
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
conversionUtil,
|
conversionUtil,
|
||||||
} from '../../helpers/utils/conversion-util';
|
} from '../../helpers/utils/conversion-util';
|
||||||
|
|
||||||
|
import { GAS_LIMITS } from '../../../shared/constants/gas';
|
||||||
import {
|
import {
|
||||||
calcGasTotal,
|
calcGasTotal,
|
||||||
estimateGasForSend,
|
estimateGasForSend,
|
||||||
@ -23,8 +24,6 @@ import {
|
|||||||
} from './send.utils';
|
} from './send.utils';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BASE_TOKEN_GAS_COST,
|
|
||||||
SIMPLE_GAS_COST,
|
|
||||||
INSUFFICIENT_FUNDS_ERROR,
|
INSUFFICIENT_FUNDS_ERROR,
|
||||||
INSUFFICIENT_TOKENS_ERROR,
|
INSUFFICIENT_TOKENS_ERROR,
|
||||||
} from './send.constants';
|
} from './send.constants';
|
||||||
@ -381,38 +380,38 @@ describe('send utils', () => {
|
|||||||
expect(result).toStrictEqual('0xabc16');
|
expect(result).toStrictEqual('0xabc16');
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return ${SIMPLE_GAS_COST} if ethQuery.getCode does not return '0x'`, async () => {
|
it(`should return ${GAS_LIMITS.SIMPLE} if ethQuery.getCode does not return '0x'`, async () => {
|
||||||
expect(baseMockParams.estimateGasMethod.callCount).toStrictEqual(0);
|
expect(baseMockParams.estimateGasMethod.callCount).toStrictEqual(0);
|
||||||
const result = await estimateGasForSend({
|
const result = await estimateGasForSend({
|
||||||
...baseMockParams,
|
...baseMockParams,
|
||||||
to: '0x123',
|
to: '0x123',
|
||||||
});
|
});
|
||||||
expect(result).toStrictEqual(SIMPLE_GAS_COST);
|
expect(result).toStrictEqual(GAS_LIMITS.SIMPLE);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return ${SIMPLE_GAS_COST} if not passed a sendToken or truthy to address`, async () => {
|
it(`should return ${GAS_LIMITS.SIMPLE} if not passed a sendToken or truthy to address`, async () => {
|
||||||
expect(baseMockParams.estimateGasMethod.callCount).toStrictEqual(0);
|
expect(baseMockParams.estimateGasMethod.callCount).toStrictEqual(0);
|
||||||
const result = await estimateGasForSend({ ...baseMockParams, to: null });
|
const result = await estimateGasForSend({ ...baseMockParams, to: null });
|
||||||
expect(result).toStrictEqual(SIMPLE_GAS_COST);
|
expect(result).toStrictEqual(GAS_LIMITS.SIMPLE);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should not return ${SIMPLE_GAS_COST} if passed a sendToken`, async () => {
|
it(`should not return ${GAS_LIMITS.SIMPLE} if passed a sendToken`, async () => {
|
||||||
expect(baseMockParams.estimateGasMethod.callCount).toStrictEqual(0);
|
expect(baseMockParams.estimateGasMethod.callCount).toStrictEqual(0);
|
||||||
const result = await estimateGasForSend({
|
const result = await estimateGasForSend({
|
||||||
...baseMockParams,
|
...baseMockParams,
|
||||||
to: '0x123',
|
to: '0x123',
|
||||||
sendToken: { address: '0x0' },
|
sendToken: { address: '0x0' },
|
||||||
});
|
});
|
||||||
expect(result).not.toStrictEqual(SIMPLE_GAS_COST);
|
expect(result).not.toStrictEqual(GAS_LIMITS.SIMPLE);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return ${BASE_TOKEN_GAS_COST} if passed a sendToken but no to address`, async () => {
|
it(`should return ${GAS_LIMITS.BASE_TOKEN_ESTIMATE} if passed a sendToken but no to address`, async () => {
|
||||||
const result = await estimateGasForSend({
|
const result = await estimateGasForSend({
|
||||||
...baseMockParams,
|
...baseMockParams,
|
||||||
to: null,
|
to: null,
|
||||||
sendToken: { address: '0x0' },
|
sendToken: { address: '0x0' },
|
||||||
});
|
});
|
||||||
expect(result).toStrictEqual(BASE_TOKEN_GAS_COST);
|
expect(result).toStrictEqual(GAS_LIMITS.BASE_TOKEN_ESTIMATE);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return the adjusted blockGasLimit if it fails with a 'Transaction execution error.'`, async () => {
|
it(`should return the adjusted blockGasLimit if it fails with a 'Transaction execution error.'`, async () => {
|
||||||
|
@ -10,6 +10,7 @@ import { calcGasTotal } from '../pages/send/send.utils';
|
|||||||
|
|
||||||
import { GAS_ESTIMATE_TYPES } from '../helpers/constants/common';
|
import { GAS_ESTIMATE_TYPES } from '../helpers/constants/common';
|
||||||
import { BASIC_ESTIMATE_STATES, GAS_SOURCE } from '../ducks/gas/gas.duck';
|
import { BASIC_ESTIMATE_STATES, GAS_SOURCE } from '../ducks/gas/gas.duck';
|
||||||
|
import { GAS_LIMITS } from '../../shared/constants/gas';
|
||||||
import {
|
import {
|
||||||
getCurrentCurrency,
|
getCurrentCurrency,
|
||||||
getIsMainnet,
|
getIsMainnet,
|
||||||
@ -295,7 +296,9 @@ export function getRenderableEstimateDataForSmallButtonsFromGWEI(state) {
|
|||||||
const isMainnet = getIsMainnet(state);
|
const isMainnet = getIsMainnet(state);
|
||||||
const showFiat = isMainnet || Boolean(showFiatInTestnets);
|
const showFiat = isMainnet || Boolean(showFiatInTestnets);
|
||||||
const gasLimit =
|
const gasLimit =
|
||||||
state.metamask.send.gasLimit || getCustomGasLimit(state) || '0x5208';
|
state.metamask.send.gasLimit ||
|
||||||
|
getCustomGasLimit(state) ||
|
||||||
|
GAS_LIMITS.SIMPLE;
|
||||||
const { conversionRate } = state.metamask;
|
const { conversionRate } = state.metamask;
|
||||||
const currentCurrency = getCurrentCurrency(state);
|
const currentCurrency = getCurrentCurrency(state);
|
||||||
const {
|
const {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { GAS_LIMITS } from '../../shared/constants/gas';
|
||||||
import {
|
import {
|
||||||
getCustomGasLimit,
|
getCustomGasLimit,
|
||||||
getCustomGasPrice,
|
getCustomGasPrice,
|
||||||
@ -221,7 +222,7 @@ describe('custom-gas selectors', () => {
|
|||||||
conversionRate: 2557.1,
|
conversionRate: 2557.1,
|
||||||
currentCurrency: 'usd',
|
currentCurrency: 'usd',
|
||||||
send: {
|
send: {
|
||||||
gasLimit: '0x5208',
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
},
|
},
|
||||||
preferences: {
|
preferences: {
|
||||||
showFiatInTestnets: false,
|
showFiatInTestnets: false,
|
||||||
@ -272,7 +273,7 @@ describe('custom-gas selectors', () => {
|
|||||||
conversionRate: 2557.1,
|
conversionRate: 2557.1,
|
||||||
currentCurrency: 'usd',
|
currentCurrency: 'usd',
|
||||||
send: {
|
send: {
|
||||||
gasLimit: '0x5208',
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
},
|
},
|
||||||
preferences: {
|
preferences: {
|
||||||
showFiatInTestnets: false,
|
showFiatInTestnets: false,
|
||||||
@ -323,7 +324,7 @@ describe('custom-gas selectors', () => {
|
|||||||
conversionRate: 2557.1,
|
conversionRate: 2557.1,
|
||||||
currentCurrency: 'usd',
|
currentCurrency: 'usd',
|
||||||
send: {
|
send: {
|
||||||
gasLimit: '0x5208',
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
},
|
},
|
||||||
preferences: {
|
preferences: {
|
||||||
showFiatInTestnets: true,
|
showFiatInTestnets: true,
|
||||||
@ -368,7 +369,7 @@ describe('custom-gas selectors', () => {
|
|||||||
conversionRate: 2557.1,
|
conversionRate: 2557.1,
|
||||||
currentCurrency: 'usd',
|
currentCurrency: 'usd',
|
||||||
send: {
|
send: {
|
||||||
gasLimit: '0x5208',
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
},
|
},
|
||||||
preferences: {
|
preferences: {
|
||||||
showFiatInTestnets: true,
|
showFiatInTestnets: true,
|
||||||
@ -393,7 +394,7 @@ describe('custom-gas selectors', () => {
|
|||||||
expect(
|
expect(
|
||||||
getRenderableBasicEstimateData(
|
getRenderableBasicEstimateData(
|
||||||
test.mockState,
|
test.mockState,
|
||||||
'0x5208',
|
GAS_LIMITS.SIMPLE,
|
||||||
test.useFastestButtons,
|
test.useFastestButtons,
|
||||||
),
|
),
|
||||||
).toStrictEqual(test.expectedResult);
|
).toStrictEqual(test.expectedResult);
|
||||||
@ -429,7 +430,7 @@ describe('custom-gas selectors', () => {
|
|||||||
conversionRate: 255.71,
|
conversionRate: 255.71,
|
||||||
currentCurrency: 'usd',
|
currentCurrency: 'usd',
|
||||||
send: {
|
send: {
|
||||||
gasLimit: '0x5208',
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
},
|
},
|
||||||
preferences: {
|
preferences: {
|
||||||
showFiatInTestnets: false,
|
showFiatInTestnets: false,
|
||||||
@ -474,7 +475,7 @@ describe('custom-gas selectors', () => {
|
|||||||
conversionRate: 2557.1,
|
conversionRate: 2557.1,
|
||||||
currentCurrency: 'usd',
|
currentCurrency: 'usd',
|
||||||
send: {
|
send: {
|
||||||
gasLimit: '0x5208',
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
},
|
},
|
||||||
preferences: {
|
preferences: {
|
||||||
showFiatInTestnets: false,
|
showFiatInTestnets: false,
|
||||||
@ -525,7 +526,7 @@ describe('custom-gas selectors', () => {
|
|||||||
conversionRate: 2557.1,
|
conversionRate: 2557.1,
|
||||||
currentCurrency: 'usd',
|
currentCurrency: 'usd',
|
||||||
send: {
|
send: {
|
||||||
gasLimit: '0x5208',
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
},
|
},
|
||||||
preferences: {
|
preferences: {
|
||||||
showFiatInTestnets: false,
|
showFiatInTestnets: false,
|
||||||
@ -576,7 +577,7 @@ describe('custom-gas selectors', () => {
|
|||||||
conversionRate: 2557.1,
|
conversionRate: 2557.1,
|
||||||
currentCurrency: 'usd',
|
currentCurrency: 'usd',
|
||||||
send: {
|
send: {
|
||||||
gasLimit: '0x5208',
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
},
|
},
|
||||||
preferences: {
|
preferences: {
|
||||||
showFiatInTestnets: true,
|
showFiatInTestnets: true,
|
||||||
@ -621,7 +622,7 @@ describe('custom-gas selectors', () => {
|
|||||||
conversionRate: 2557.1,
|
conversionRate: 2557.1,
|
||||||
currentCurrency: 'usd',
|
currentCurrency: 'usd',
|
||||||
send: {
|
send: {
|
||||||
gasLimit: '0x5208',
|
gasLimit: GAS_LIMITS.SIMPLE,
|
||||||
},
|
},
|
||||||
preferences: {
|
preferences: {
|
||||||
showFiatInTestnets: true,
|
showFiatInTestnets: true,
|
||||||
|
@ -5,6 +5,7 @@ import EthQuery from 'eth-query';
|
|||||||
import enLocale from '../../app/_locales/en/messages.json';
|
import enLocale from '../../app/_locales/en/messages.json';
|
||||||
import MetaMaskController from '../../app/scripts/metamask-controller';
|
import MetaMaskController from '../../app/scripts/metamask-controller';
|
||||||
import { TRANSACTION_STATUSES } from '../../shared/constants/transaction';
|
import { TRANSACTION_STATUSES } from '../../shared/constants/transaction';
|
||||||
|
import { GAS_LIMITS } from '../../shared/constants/gas';
|
||||||
import * as actions from './actions';
|
import * as actions from './actions';
|
||||||
|
|
||||||
const middleware = [thunk];
|
const middleware = [thunk];
|
||||||
@ -902,8 +903,8 @@ describe('Actions', () => {
|
|||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'GAS_LOADING_STARTED' },
|
{ type: 'GAS_LOADING_STARTED' },
|
||||||
{ type: 'UPDATE_GAS_LIMIT', value: '0x5208' },
|
{ type: 'UPDATE_GAS_LIMIT', value: GAS_LIMITS.SIMPLE },
|
||||||
{ type: 'metamask/gas/SET_CUSTOM_GAS_LIMIT', value: '0x5208' },
|
{ type: 'metamask/gas/SET_CUSTOM_GAS_LIMIT', value: GAS_LIMITS.SIMPLE },
|
||||||
{ type: 'UPDATE_SEND_ERRORS', value: { gasLoadingError: null } },
|
{ type: 'UPDATE_SEND_ERRORS', value: { gasLoadingError: null } },
|
||||||
{ type: 'GAS_LOADING_FINISHED' },
|
{ type: 'GAS_LOADING_FINISHED' },
|
||||||
];
|
];
|
||||||
@ -929,7 +930,7 @@ describe('Actions', () => {
|
|||||||
describe('#updateTransaction', () => {
|
describe('#updateTransaction', () => {
|
||||||
const txParams = {
|
const txParams = {
|
||||||
from: '0x1',
|
from: '0x1',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
to: '0x2',
|
to: '0x2',
|
||||||
value: '0x0',
|
value: '0x0',
|
||||||
@ -998,7 +999,7 @@ describe('Actions', () => {
|
|||||||
id: '1',
|
id: '1',
|
||||||
value: {
|
value: {
|
||||||
from: '0x1',
|
from: '0x1',
|
||||||
gas: '0x5208',
|
gas: GAS_LIMITS.SIMPLE,
|
||||||
gasPrice: '0x3b9aca00',
|
gasPrice: '0x3b9aca00',
|
||||||
to: '0x2',
|
to: '0x2',
|
||||||
value: '0x0',
|
value: '0x0',
|
||||||
|
Loading…
Reference in New Issue
Block a user