From 3f9ec40107cb598f71b0ee73f208ebdb563a8efa Mon Sep 17 00:00:00 2001 From: David Walsh Date: Wed, 10 Nov 2021 13:50:43 -0600 Subject: [PATCH] Use gas estimate type constants (#12460) --- app/scripts/controllers/transactions/index.js | 5 +++-- app/scripts/controllers/transactions/index.test.js | 11 ++++++----- ui/helpers/constants/transactions.js | 5 +++++ ui/pages/swaps/fee-card/fee-card.test.js | 3 ++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index 74eacc396..0f1d15961 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -26,6 +26,7 @@ import { TRANSACTION_TYPES, TRANSACTION_ENVELOPE_TYPES, } from '../../../../shared/constants/transaction'; +import { TRANSACTION_ENVELOPE_TYPE_NAMES } from '../../../../ui/helpers/constants/transactions'; import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller'; import { GAS_LIMITS, @@ -1447,8 +1448,8 @@ export default class TransactionController extends EventEmitter { sensitiveProperties: { status, transaction_envelope_type: isEIP1559Transaction(txMeta) - ? 'fee-market' - : 'legacy', + ? TRANSACTION_ENVELOPE_TYPE_NAMES.FEE_MARKET + : TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY, first_seen: time, gas_limit: gasLimit, ...gasParamsInGwei, diff --git a/app/scripts/controllers/transactions/index.test.js b/app/scripts/controllers/transactions/index.test.js index dbf7ca9d8..c2f7a344b 100644 --- a/app/scripts/controllers/transactions/index.test.js +++ b/app/scripts/controllers/transactions/index.test.js @@ -20,6 +20,7 @@ import { GAS_ESTIMATE_TYPES, GAS_RECOMMENDATIONS, } from '../../../../shared/constants/gas'; +import { TRANSACTION_ENVELOPE_TYPE_NAMES } from '../../../../ui/helpers/constants/transactions'; import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller'; import TransactionController, { TRANSACTION_EVENTS } from '.'; @@ -774,7 +775,7 @@ describe('Transaction Controller', function () { nonce: '0x4b', }, type: TRANSACTION_TYPES.SIMPLE_SEND, - transaction_envelope_type: 'legacy', + transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY, origin: 'metamask', chainId: currentChainId, time: 1624408066355, @@ -1578,7 +1579,7 @@ describe('Transaction Controller', function () { gas_price: '2', gas_limit: '0x7b0d', first_seen: 1624408066355, - transaction_envelope_type: 'legacy', + transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY, status: 'unapproved', }, }; @@ -1625,7 +1626,7 @@ describe('Transaction Controller', function () { gas_price: '2', gas_limit: '0x7b0d', first_seen: 1624408066355, - transaction_envelope_type: 'legacy', + transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY, status: 'unapproved', }, }; @@ -1674,7 +1675,7 @@ describe('Transaction Controller', function () { gas_price: '2', gas_limit: '0x7b0d', first_seen: 1624408066355, - transaction_envelope_type: 'legacy', + transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY, status: 'unapproved', }, }; @@ -1731,7 +1732,7 @@ describe('Transaction Controller', function () { max_priority_fee_per_gas: '2', gas_limit: '0x7b0d', first_seen: 1624408066355, - transaction_envelope_type: 'fee-market', + transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.FEE_MARKET, status: 'unapproved', estimate_suggested: GAS_RECOMMENDATIONS.MEDIUM, estimate_used: GAS_RECOMMENDATIONS.HIGH, diff --git a/ui/helpers/constants/transactions.js b/ui/helpers/constants/transactions.js index 614f0329d..aeeda8bdf 100644 --- a/ui/helpers/constants/transactions.js +++ b/ui/helpers/constants/transactions.js @@ -19,3 +19,8 @@ export const TOKEN_CATEGORY_HASH = { [TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER]: true, [TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM]: true, }; + +export const TRANSACTION_ENVELOPE_TYPE_NAMES = { + FEE_MARKET: 'fee-market', + LEGACY: 'legacy', +}; diff --git a/ui/pages/swaps/fee-card/fee-card.test.js b/ui/pages/swaps/fee-card/fee-card.test.js index 9327ad69e..ffa54affe 100644 --- a/ui/pages/swaps/fee-card/fee-card.test.js +++ b/ui/pages/swaps/fee-card/fee-card.test.js @@ -17,6 +17,7 @@ import { MOCKS, } from '../../../../test/jest'; import { MAINNET_CHAIN_ID } from '../../../../shared/constants/network'; +import { TRANSACTION_ENVELOPE_TYPE_NAMES } from '../../../helpers/constants/transactions'; import FeeCard from '.'; const middleware = [thunk]; @@ -35,7 +36,7 @@ const generateUseSelectorRouter = () => (selector) => { return true; } if (selector === getGasEstimateType) { - return 'fee-market'; + return TRANSACTION_ENVELOPE_TYPE_NAMES.FEE_MARKET; } if (selector === getGasFeeEstimates) { return MOCKS.createGasFeeEstimatesForFeeMarket();