Modify transaction type and add contract method data to metrics (#15175)

feature/default_network_editable
VSaric 2 years ago committed by GitHub
parent 2bcc1c512c
commit f1ca3e56e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      app/scripts/controllers/transactions/index.js
  2. 21
      app/scripts/controllers/transactions/index.test.js
  3. 2
      shared/constants/transaction.js
  4. 6
      ui/pages/confirm-transaction-base/confirm-transaction-base.component.js

@ -1991,6 +1991,7 @@ export default class TransactionController extends EventEmitter {
async _buildEventFragmentProperties(txMeta, extraParams) {
const {
id,
type,
time,
status,
@ -2007,6 +2008,7 @@ export default class TransactionController extends EventEmitter {
defaultGasEstimates,
metamaskNetworkId: network,
} = txMeta;
const { transactions } = this.store.getState();
const source = referrer === ORIGIN_METAMASK ? 'user' : 'dapp';
const { assetType, tokenStandard } = await determineTransactionAssetType(
@ -2081,12 +2083,39 @@ export default class TransactionController extends EventEmitter {
eip1559Version = eip1559V2Enabled ? '2' : '1';
}
const contractInteractionTypes = [
TRANSACTION_TYPES.CONTRACT_INTERACTION,
TRANSACTION_TYPES.TOKEN_METHOD_APPROVE,
TRANSACTION_TYPES.TOKEN_METHOD_SAFE_TRANSFER_FROM,
TRANSACTION_TYPES.TOKEN_METHOD_SET_APPROVAL_FOR_ALL,
TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM,
TRANSACTION_TYPES.SMART,
TRANSACTION_TYPES.SWAP,
TRANSACTION_TYPES.SWAP_APPROVAL,
].includes(type);
let transactionType = TRANSACTION_TYPES.SIMPLE_SEND;
if (type === TRANSACTION_TYPES.CANCEL) {
transactionType = TRANSACTION_TYPES.CANCEL;
} else if (type === TRANSACTION_TYPES.RETRY) {
transactionType = TRANSACTION_TYPES.RETRY;
} else if (type === TRANSACTION_TYPES.DEPLOY_CONTRACT) {
transactionType = TRANSACTION_TYPES.DEPLOY_CONTRACT;
} else if (contractInteractionTypes) {
transactionType = TRANSACTION_TYPES.CONTRACT_INTERACTION;
}
let transactionContractMethod;
if (transactionType === TRANSACTION_TYPES.CONTRACT_INTERACTION) {
transactionContractMethod = transactions[id]?.contractMethodName;
}
const properties = {
chain_id: chainId,
referrer,
source,
network,
type,
eip_1559_version: eip1559Version,
gas_edit_type: 'none',
gas_edit_attempted: 'none',
@ -2094,6 +2123,7 @@ export default class TransactionController extends EventEmitter {
device_model: await this.getDeviceModel(this.getSelectedAddress()),
asset_type: assetType,
token_standard: tokenStandard,
transaction_type: transactionType,
};
const sensitiveProperties = {
@ -2103,6 +2133,7 @@ export default class TransactionController extends EventEmitter {
: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
first_seen: time,
gas_limit: gasLimit,
transaction_contract_method: transactionContractMethod,
...extraParams,
...gasParamsInGwei,
};

@ -1471,7 +1471,7 @@ describe('Transaction Controller', function () {
network: '42',
referrer: ORIGIN_METAMASK,
source: EVENT.SOURCE.TRANSACTION.USER,
type: TRANSACTION_TYPES.SIMPLE_SEND,
transaction_type: TRANSACTION_TYPES.SIMPLE_SEND,
account_type: 'MetaMask',
asset_type: ASSET_TYPES.NATIVE,
token_standard: TOKEN_STANDARDS.NONE,
@ -1482,6 +1482,7 @@ describe('Transaction Controller', function () {
default_gas_price: '2',
gas_price: '2',
gas_limit: '0x7b0d',
transaction_contract_method: undefined,
first_seen: 1624408066355,
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
status: 'unapproved',
@ -1550,7 +1551,7 @@ describe('Transaction Controller', function () {
network: '42',
referrer: ORIGIN_METAMASK,
source: EVENT.SOURCE.TRANSACTION.USER,
type: TRANSACTION_TYPES.SIMPLE_SEND,
transaction_type: TRANSACTION_TYPES.SIMPLE_SEND,
account_type: 'MetaMask',
asset_type: ASSET_TYPES.NATIVE,
token_standard: TOKEN_STANDARDS.NONE,
@ -1561,6 +1562,7 @@ describe('Transaction Controller', function () {
default_gas_price: '2',
gas_price: '2',
gas_limit: '0x7b0d',
transaction_contract_method: undefined,
first_seen: 1624408066355,
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
status: 'unapproved',
@ -1639,7 +1641,7 @@ describe('Transaction Controller', function () {
network: '42',
referrer: 'other',
source: EVENT.SOURCE.TRANSACTION.DAPP,
type: TRANSACTION_TYPES.SIMPLE_SEND,
transaction_type: TRANSACTION_TYPES.SIMPLE_SEND,
account_type: 'MetaMask',
asset_type: ASSET_TYPES.NATIVE,
token_standard: TOKEN_STANDARDS.NONE,
@ -1650,6 +1652,7 @@ describe('Transaction Controller', function () {
default_gas_price: '2',
gas_price: '2',
gas_limit: '0x7b0d',
transaction_contract_method: undefined,
first_seen: 1624408066355,
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
status: 'unapproved',
@ -1720,7 +1723,7 @@ describe('Transaction Controller', function () {
network: '42',
referrer: 'other',
source: EVENT.SOURCE.TRANSACTION.DAPP,
type: TRANSACTION_TYPES.SIMPLE_SEND,
transaction_type: TRANSACTION_TYPES.SIMPLE_SEND,
account_type: 'MetaMask',
asset_type: ASSET_TYPES.NATIVE,
token_standard: TOKEN_STANDARDS.NONE,
@ -1731,6 +1734,7 @@ describe('Transaction Controller', function () {
default_gas_price: '2',
gas_price: '2',
gas_limit: '0x7b0d',
transaction_contract_method: undefined,
first_seen: 1624408066355,
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
status: 'unapproved',
@ -1801,7 +1805,7 @@ describe('Transaction Controller', function () {
network: '42',
referrer: 'other',
source: EVENT.SOURCE.TRANSACTION.DAPP,
type: TRANSACTION_TYPES.SIMPLE_SEND,
transaction_type: TRANSACTION_TYPES.SIMPLE_SEND,
account_type: 'MetaMask',
asset_type: ASSET_TYPES.NATIVE,
token_standard: TOKEN_STANDARDS.NONE,
@ -1810,6 +1814,7 @@ describe('Transaction Controller', function () {
sensitiveProperties: {
gas_price: '2',
gas_limit: '0x7b0d',
transaction_contract_method: undefined,
first_seen: 1624408066355,
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
status: 'unapproved',
@ -1860,7 +1865,7 @@ describe('Transaction Controller', function () {
network: '42',
referrer: 'other',
source: EVENT.SOURCE.TRANSACTION.DAPP,
type: TRANSACTION_TYPES.SIMPLE_SEND,
transaction_type: TRANSACTION_TYPES.SIMPLE_SEND,
chain_id: '0x2a',
eip_1559_version: '0',
gas_edit_attempted: 'none',
@ -1875,6 +1880,7 @@ describe('Transaction Controller', function () {
foo: 'bar',
gas_price: '2',
gas_limit: '0x7b0d',
transaction_contract_method: undefined,
first_seen: 1624408066355,
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
status: 'unapproved',
@ -1937,7 +1943,7 @@ describe('Transaction Controller', function () {
network: '42',
referrer: 'other',
source: EVENT.SOURCE.TRANSACTION.DAPP,
type: TRANSACTION_TYPES.SIMPLE_SEND,
transaction_type: TRANSACTION_TYPES.SIMPLE_SEND,
account_type: 'MetaMask',
asset_type: ASSET_TYPES.NATIVE,
token_standard: TOKEN_STANDARDS.NONE,
@ -1949,6 +1955,7 @@ describe('Transaction Controller', function () {
max_fee_per_gas: '2',
max_priority_fee_per_gas: '2',
gas_limit: '0x7b0d',
transaction_contract_method: undefined,
first_seen: 1624408066355,
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.FEE_MARKET,
status: 'unapproved',

@ -252,6 +252,8 @@ export const TRANSACTION_GROUP_CATEGORIES = {
* @property {number} id - An internally unique tx identifier.
* @property {number} time - Time the transaction was first suggested, in unix
* epoch time (ms).
* @property {string} contractMethodName - A string representing a name of
* transaction contract method.
* @property {TransactionTypeString} type - The type of transaction this txMeta
* represents.
* @property {TransactionStatusString} status - The current status of the

@ -806,8 +806,10 @@ export default class ConfirmTransactionBase extends Component {
maxFeePerGas,
maxPriorityFeePerGas,
baseFeePerGas,
methodData,
} = this.props;
const { submitting } = this.state;
const { name } = methodData;
if (submitting) {
return;
@ -817,6 +819,10 @@ export default class ConfirmTransactionBase extends Component {
txData.estimatedBaseFee = baseFeePerGas;
}
if (name) {
txData.contractMethodName = name;
}
if (maxFeePerGas) {
txData.txParams = {
...txData.txParams,

Loading…
Cancel
Save