add eip-1559 fields to event schema (#11408)

* add eip-1559 fields to event schema

* add gas_limit to all
feature/default_network_editable
Brad Decker 3 years ago committed by GitHub
parent 9e86a03afa
commit 8f371e4f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      app/scripts/controllers/transactions/index.js
  2. 63
      app/scripts/controllers/transactions/index.test.js

@ -29,6 +29,7 @@ import {
MAINNET,
NETWORK_TYPE_RPC,
} from '../../../../shared/constants/network';
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';
@ -689,10 +690,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);
}
/**
@ -1127,11 +1125,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',
@ -1142,8 +1149,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,
},
});

@ -482,6 +482,7 @@ describe('Transaction Controller', function () {
nonce: '0x4b',
},
type: 'sentEther',
transaction_envelope_type: 'legacy',
origin: 'metamask',
chainId: currentChainId,
time: 1624408066355,
@ -838,9 +839,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,
});
});
});
@ -1221,7 +1219,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',
@ -1264,7 +1264,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',
@ -1309,7 +1311,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',

Loading…
Cancel
Save