From f1ca3e56e7bcfe484968c3be23136833557a25b9 Mon Sep 17 00:00:00 2001 From: VSaric <92527393+VSaric@users.noreply.github.com> Date: Fri, 22 Jul 2022 19:45:04 +0200 Subject: [PATCH] Modify transaction type and add contract method data to metrics (#15175) --- app/scripts/controllers/transactions/index.js | 33 ++++++++++++++++++- .../controllers/transactions/index.test.js | 21 ++++++++---- shared/constants/transaction.js | 2 ++ .../confirm-transaction-base.component.js | 6 ++++ 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index 87d56c714..93937302d 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.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, }; diff --git a/app/scripts/controllers/transactions/index.test.js b/app/scripts/controllers/transactions/index.test.js index 76f8145e1..52cface7a 100644 --- a/app/scripts/controllers/transactions/index.test.js +++ b/app/scripts/controllers/transactions/index.test.js @@ -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', diff --git a/shared/constants/transaction.js b/shared/constants/transaction.js index 8afcdb0c8..845f769a0 100644 --- a/shared/constants/transaction.js +++ b/shared/constants/transaction.js @@ -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 diff --git a/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js b/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js index a5435e42b..571bc3524 100644 --- a/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js +++ b/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js @@ -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,