From 4e0bfbc463b8c3cd1a7073605dfdb428ddbce663 Mon Sep 17 00:00:00 2001 From: Brad Decker Date: Tue, 29 Jun 2021 16:54:42 -0500 Subject: [PATCH] add eip-1559 fields to event schema (#11408) * add eip-1559 fields to event schema * add gas_limit to all --- app/scripts/controllers/transactions/index.js | 23 +++++-- .../controllers/transactions/index.test.js | 63 ++++++++++++++++++- 2 files changed, 77 insertions(+), 9 deletions(-) diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index 49a895ad5..95d5e533d 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -24,6 +24,7 @@ import { } from '../../../../shared/constants/transaction'; import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller'; import { GAS_LIMITS } from '../../../../shared/constants/gas'; +import { isEIP1559Transaction } from '../../../../shared/modules/transaction.utils'; import TransactionStateManager from './tx-state-manager'; import TxGasUtil from './tx-gas-utils'; import PendingTransactionTracker from './pending-tx-tracker'; @@ -626,10 +627,7 @@ export default class TransactionController extends EventEmitter { this.txStateManager.setTxStatusSubmitted(txId); - const { gas } = txMeta.txParams; - this._trackTransactionMetricsEvent(txMeta, TRANSACTION_EVENTS.SUBMITTED, { - gas_limit: gas, - }); + this._trackTransactionMetricsEvent(txMeta, TRANSACTION_EVENTS.SUBMITTED); } /** @@ -1064,11 +1062,20 @@ export default class TransactionController extends EventEmitter { status, chainId, origin: referrer, - txParams: { gasPrice }, + txParams: { gasPrice, gas: gasLimit, maxFeePerGas, maxPriorityFeePerGas }, metamaskNetworkId: network, } = txMeta; const source = referrer === 'metamask' ? 'user' : 'dapp'; + const gasParams = {}; + + if (isEIP1559Transaction(txMeta)) { + gasParams.max_fee_per_gas = maxFeePerGas; + gasParams.max_priority_fee_per_gas = maxPriorityFeePerGas; + } else { + gasParams.gas_price = gasPrice; + } + this._trackMetaMetricsEvent({ event, category: 'Transactions', @@ -1079,8 +1086,12 @@ export default class TransactionController extends EventEmitter { source, network, chain_id: chainId, - gas_price: gasPrice, + transaction_envelope_type: isEIP1559Transaction(txMeta) + ? 'fee-market' + : 'legacy', first_seen: time, + gas_limit: gasLimit, + ...gasParams, ...extraParams, }, }); diff --git a/app/scripts/controllers/transactions/index.test.js b/app/scripts/controllers/transactions/index.test.js index ace6342a9..d016a80e2 100644 --- a/app/scripts/controllers/transactions/index.test.js +++ b/app/scripts/controllers/transactions/index.test.js @@ -478,6 +478,7 @@ describe('Transaction Controller', function () { nonce: '0x4b', }, type: 'sentEther', + transaction_envelope_type: 'legacy', origin: 'metamask', chainId: currentChainId, time: 1624408066355, @@ -834,9 +835,6 @@ describe('Transaction Controller', function () { trackTransactionMetricsEventSpy.getCall(0).args[1], TRANSACTION_EVENTS.SUBMITTED, ); - assert.deepEqual(trackTransactionMetricsEventSpy.getCall(0).args[2], { - gas_limit: txMeta.txParams.gas, - }); }); }); @@ -1217,7 +1215,9 @@ describe('Transaction Controller', function () { sensitiveProperties: { chain_id: '0x2a', gas_price: '0x77359400', + gas_limit: '0x7b0d', first_seen: 1624408066355, + transaction_envelope_type: 'legacy', network: '42', referrer: 'metamask', source: 'user', @@ -1260,7 +1260,9 @@ describe('Transaction Controller', function () { sensitiveProperties: { chain_id: '0x2a', gas_price: '0x77359400', + gas_limit: '0x7b0d', first_seen: 1624408066355, + transaction_envelope_type: 'legacy', network: '42', referrer: 'other', source: 'dapp', @@ -1305,7 +1307,62 @@ describe('Transaction Controller', function () { foo: 'bar', chain_id: '0x2a', gas_price: '0x77359400', + gas_limit: '0x7b0d', first_seen: 1624408066355, + transaction_envelope_type: 'legacy', + network: '42', + referrer: 'other', + source: 'dapp', + status: 'unapproved', + type: 'sentEther', + }, + }; + + txController._trackTransactionMetricsEvent( + txMeta, + TRANSACTION_EVENTS.ADDED, + { + baz: 3.0, + foo: 'bar', + }, + ); + assert.equal(trackMetaMetricsEventSpy.callCount, 1); + assert.deepEqual( + trackMetaMetricsEventSpy.getCall(0).args[0], + expectedPayload, + ); + }); + + it('should call _trackMetaMetricsEvent with the correct payload (EIP-1559)', function () { + const txMeta = { + id: 1, + status: TRANSACTION_STATUSES.UNAPPROVED, + txParams: { + from: fromAccount.address, + to: '0x1678a085c290ebd122dc42cba69373b5953b831d', + maxFeePerGas: '0x77359400', + maxPriorityFeePerGas: '0x77359400', + gas: '0x7b0d', + nonce: '0x4b', + }, + type: 'sentEther', + origin: 'other', + chainId: currentChainId, + time: 1624408066355, + metamaskNetworkId: currentNetworkId, + }; + const expectedPayload = { + event: 'Transaction Added', + category: 'Transactions', + sensitiveProperties: { + baz: 3.0, + foo: 'bar', + chain_id: '0x2a', + max_fee_per_gas: '0x77359400', + max_priority_fee_per_gas: '0x77359400', + gas_limit: '0x7b0d', + first_seen: 1624408066355, + transaction_envelope_type: 'fee-market', network: '42', referrer: 'other', source: 'dapp',