Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding metrics events for EIP-1559 V2 flow #13329

Merged
merged 34 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
921e33f
Capturing default gas estimates in txMeta and passing it to metrics
jpuri Jan 24, 2022
ea70667
Adding flag for V2 transactions in metrics
jpuri Jan 24, 2022
82468bc
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
jpuri Jan 24, 2022
3986a1b
Improvements
jpuri Jan 24, 2022
d075dac
Improvements
jpuri Jan 24, 2022
857065b
Improvements
jpuri Jan 24, 2022
bd89570
Improvements
jpuri Jan 24, 2022
dc13c98
Improvements
jpuri Jan 24, 2022
262ba46
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
jpuri Jan 25, 2022
4e2918e
fix
jpuri Jan 25, 2022
4cd7ae1
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
jpuri Jan 26, 2022
f405942
fix build
jpuri Jan 26, 2022
cac7841
fix build
jpuri Jan 26, 2022
91c6a7a
fix build
jpuri Jan 26, 2022
4b0f7a6
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
jpuri Jan 28, 2022
a2634dd
Adding metrics events for EIP-1559 V2 flow
jpuri Jan 17, 2022
c4a74f4
merge
jpuri Jan 24, 2022
28d6a71
fixes
jpuri Jan 24, 2022
f73e96b
fix
jpuri Jan 25, 2022
f1fbd45
Update app/scripts/controllers/transactions/index.js
jpuri Jan 24, 2022
fdbaeb4
Revert changes
jpuri Jan 27, 2022
6e29d04
Revert changes
jpuri Jan 27, 2022
0fe3280
fixes
jpuri Jan 27, 2022
547689f
fix
jpuri Jan 27, 2022
dfc5d46
fix
jpuri Jan 27, 2022
664e68a
fix
jpuri Jan 27, 2022
e326ca4
fix
jpuri Jan 27, 2022
05e5c15
fix
jpuri Jan 27, 2022
6196d5a
fixes
jpuri Jan 28, 2022
2bbcd62
fix build
jpuri Jan 28, 2022
0fa7ae5
merge
jpuri Jan 31, 2022
e8d554a
fix build
jpuri Jan 31, 2022
86ef58c
fix
jpuri Jan 31, 2022
bf06141
fix build
jpuri Feb 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/scripts/controllers/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,8 @@ export default class TransactionController extends EventEmitter {
network,
type,
eip_1559_version: eip1559Version,
gas_edit_type: 'none',
gas_edit_attempted: 'none',
brad-decker marked this conversation as resolved.
Show resolved Hide resolved
};

const sensitiveProperties = {
Expand Down
14 changes: 14 additions & 0 deletions app/scripts/controllers/transactions/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,8 @@ describe('Transaction Controller', function () {
properties: {
chain_id: '0x2a',
eip_1559_version: '0',
gas_edit_attempted: 'none',
gas_edit_type: 'none',
network: '42',
referrer: 'metamask',
source: 'user',
Expand Down Expand Up @@ -1683,6 +1685,8 @@ describe('Transaction Controller', function () {
properties: {
chain_id: '0x2a',
eip_1559_version: '0',
gas_edit_attempted: 'none',
gas_edit_type: 'none',
network: '42',
referrer: 'metamask',
source: 'user',
Expand Down Expand Up @@ -1766,6 +1770,8 @@ describe('Transaction Controller', function () {
properties: {
chain_id: '0x2a',
eip_1559_version: '0',
gas_edit_attempted: 'none',
gas_edit_type: 'none',
network: '42',
referrer: 'other',
source: 'dapp',
Expand Down Expand Up @@ -1841,6 +1847,8 @@ describe('Transaction Controller', function () {
properties: {
chain_id: '0x2a',
eip_1559_version: '0',
gas_edit_attempted: 'none',
gas_edit_type: 'none',
network: '42',
referrer: 'other',
source: 'dapp',
Expand Down Expand Up @@ -1916,6 +1924,8 @@ describe('Transaction Controller', function () {
properties: {
chain_id: '0x2a',
eip_1559_version: '0',
gas_edit_attempted: 'none',
gas_edit_type: 'none',
network: '42',
referrer: 'other',
source: 'dapp',
Expand Down Expand Up @@ -1977,6 +1987,8 @@ describe('Transaction Controller', function () {
type: TRANSACTION_TYPES.SIMPLE_SEND,
chain_id: '0x2a',
eip_1559_version: '0',
gas_edit_attempted: 'none',
gas_edit_type: 'none',
},
sensitiveProperties: {
baz: 3.0,
Expand Down Expand Up @@ -2040,6 +2052,8 @@ describe('Transaction Controller', function () {
properties: {
chain_id: '0x2a',
eip_1559_version: '1',
gas_edit_attempted: 'none',
gas_edit_type: 'none',
network: '42',
referrer: 'other',
source: 'dapp',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';

import { useTransactionEventFragment } from '../../../../hooks/useTransactionEventFragment';
import { EDIT_GAS_MODES } from '../../../../../shared/constants/gas';
import Box from '../../../ui/box';
import Typography from '../../../ui/typography';
Expand All @@ -27,8 +28,8 @@ const AdvancedGasFeeDefaults = () => {
maxPriorityFeePerGas,
} = useAdvancedGasFeePopoverContext();
const advancedGasFeeValues = useSelector(getAdvancedGasFeeValues);
const { updateTransactionEventFragment } = useTransactionEventFragment();
const { editGasMode } = useGasFeeContext();

const [isDefaultSettingsSelected, setDefaultSettingsSelected] = useState(
Boolean(advancedGasFeeValues) &&
advancedGasFeeValues.maxBaseFee === maxBaseFee &&
Expand All @@ -47,14 +48,25 @@ const AdvancedGasFeeDefaults = () => {
if (isDefaultSettingsSelected) {
dispatch(setAdvancedGasFee(null));
setDefaultSettingsSelected(false);
updateTransactionEventFragment({
properties: {
advanced_gas_defaults_updated_maxbasefee: null,
advanced_gas_defaults_updated_priorityfee: null,
},
});
} else {
dispatch(
setAdvancedGasFee({
maxBaseFee,
priorityFee: maxPriorityFeePerGas,
}),
);
setDefaultSettingsSelected(true);
updateTransactionEventFragment({
properties: {
advanced_gas_defaults_updated_maxbasefee: maxBaseFee,
advanced_gas_defaults_updated_priorityfee: maxPriorityFeePerGas,
},
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above takes care to add/remove parameter in transaction fragment for advance gas default updates. This is exactly not part of transaction flow but more of user settings. But I still added it to transaction, I also see it included in transaction metrics here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine for now, but as its a user level setting (or is it per account?) we'll want to migrate these to traits whenever we do the work to make that a thing. Sory for a future date.

I do think gas_default_max_base_fee is sufficient, the presence of it in the payload is good enough to track that it was updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These is user level and updated preference controller.

}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jest.mock('../../../../store/actions', () => ({
addPollingTokenToAppState: jest.fn(),
removePollingTokenFromAppState: jest.fn(),
setAdvancedGasFee: jest.fn(),
updateEventFragment: jest.fn(),
}));

const render = (defaultGasParams, contextParams) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React from 'react';

import { PRIORITY_LEVELS } from '../../../../../shared/constants/gas';
import { decGWEIToHexWEI } from '../../../../../shared/modules/conversion.utils';
import { useTransactionModalContext } from '../../../../contexts/transaction-modal';
import { useGasFeeContext } from '../../../../contexts/gasFee';
import { useTransactionEventFragment } from '../../../../hooks/useTransactionEventFragment';
import Button from '../../../ui/button';
import I18nValue from '../../../ui/i18n-value';

import { useAdvancedGasFeePopoverContext } from '../context';
import { decGWEIToHexWEI } from '../../../../../shared/modules/conversion.utils';

const AdvancedGasFeeSaveButton = () => {
const { closeAllModals } = useTransactionModalContext();
const { updateTransactionEventFragment } = useTransactionEventFragment();
const { updateTransaction } = useGasFeeContext();
const {
gasLimit,
Expand All @@ -26,6 +28,11 @@ const AdvancedGasFeeSaveButton = () => {
maxPriorityFeePerGas: decGWEIToHexWEI(maxPriorityFeePerGas),
gasLimit,
});
updateTransactionEventFragment({
properties: {
gas_edit_type: 'advanced',
},
});
closeAllModals();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const CancelSpeedupPopover = () => {
updateTransactionUsingEstimate(PRIORITY_LEVELS.MEDIUM);
return;
}
updateTransactionToTenPercentIncreasedGasFee();
updateTransactionToTenPercentIncreasedGasFee(true);
}, [
appIsLoading,
currentModal,
Expand Down
23 changes: 18 additions & 5 deletions ui/components/app/edit-gas-fee-button/edit-gas-fee-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { COLORS, TYPOGRAPHY } from '../../../helpers/constants/design-system';
import { PRIORITY_LEVEL_ICON_MAP } from '../../../helpers/constants/gas';
import { useGasFeeContext } from '../../../contexts/gasFee';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { useTransactionEventFragment } from '../../../hooks/useTransactionEventFragment';
import { useTransactionModalContext } from '../../../contexts/transaction-modal';
import InfoTooltip from '../../ui/info-tooltip/info-tooltip';
import Typography from '../../ui/typography/typography';
Expand All @@ -25,6 +26,7 @@ export default function EditGasFeeButton({ userAcknowledgedGasMissing }) {
supportsEIP1559V2,
transaction,
} = useGasFeeContext();
const { updateTransactionEventFragment } = useTransactionEventFragment();
const { openModal } = useTransactionModalContext();
const editEnabled =
!hasSimulationError || userAcknowledgedGasMissing === true;
Expand All @@ -46,12 +48,23 @@ export default function EditGasFeeButton({ userAcknowledgedGasMissing }) {
title = 'tenPercentIncreased';
}

const openEditGasFeeModal = () => {
updateTransactionEventFragment({
gas_edit_attempted: 'basic',
});
openModal('editGasFee');
};

const openAdvancedGasFeeModal = () => {
updateTransactionEventFragment({
gas_edit_attempted: 'advanced',
});
openModal('advancedGasFee');
};

return (
<div className="edit-gas-fee-button">
<button
onClick={() => openModal('editGasFee')}
data-testid="edit-gas-fee-button"
>
<button onClick={openEditGasFeeModal} data-testid="edit-gas-fee-button">
{icon && (
<span className="edit-gas-fee-button__icon">
{PRIORITY_LEVEL_ICON_MAP[icon]}
Expand All @@ -61,7 +74,7 @@ export default function EditGasFeeButton({ userAcknowledgedGasMissing }) {
<i className="fas fa-chevron-right asset-list-item__chevron-right" />
</button>
{estimateUsed === 'custom' && (
<button onClick={() => openModal('advancedGasFee')}>{t('edit')}</button>
<button onClick={openAdvancedGasFeeModal}>{t('edit')}</button>
)}
{estimateUsed === 'dappSuggested' && (
<InfoTooltip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import { PRIMARY } from '../../../../helpers/constants/common';
import { toHumanReadableTime } from '../../../../helpers/utils/util';
import { useGasFeeContext } from '../../../../contexts/gasFee';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import { useTransactionEventFragment } from '../../../../hooks/useTransactionEventFragment';
import { useTransactionModalContext } from '../../../../contexts/transaction-modal';
import EditGasToolTip from '../edit-gas-tooltip/edit-gas-tooltip';
import I18nValue from '../../../ui/i18n-value';
import InfoTooltip from '../../../ui/info-tooltip';
import LoadingHeartBeat from '../../../ui/loading-heartbeat';
import UserPreferencedCurrencyDisplay from '../../user-preferenced-currency-display';
import EditGasToolTip from '../edit-gas-tooltip/edit-gas-tooltip';

import { useGasItemFeeDetails } from './useGasItemFeeDetails';

Expand Down Expand Up @@ -48,6 +49,7 @@ const EditGasItem = ({ priorityLevel }) => {
updateTransactionUsingEstimate,
transaction,
} = useGasFeeContext();
const { updateTransactionEventFragment } = useTransactionEventFragment();
const t = useI18nContext();
const { closeModal, openModal } = useTransactionModalContext();
const { dappSuggestedGasFees } = transaction;
Expand All @@ -72,8 +74,19 @@ const EditGasItem = ({ priorityLevel }) => {

const onOptionSelect = () => {
if (priorityLevel === PRIORITY_LEVELS.CUSTOM) {
updateTransactionEventFragment({
properties: {
gas_edit_attempted: 'advanced',
},
});
openModal('advancedGasFee');
} else {
updateTransactionEventFragment({
properties: {
gas_edit_type: 'basic',
},
});

closeModal('editGasFee');

if (priorityLevel === PRIORITY_LEVELS.TEN_PERCENT_INCREASED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ const TransactionListItem = (props) => {
transaction={transactionGroup.primaryTransaction}
editGasMode={editGasMode}
>
<TransactionModalContextProvider captureEventEnabled={false}>
<TransactionModalContextProvider>
<TransactionListItemInner {...props} setEditGasMode={setEditGasMode} />
{supportsEIP1559V2 && (
<>
Expand Down
36 changes: 1 addition & 35 deletions ui/contexts/transaction-modal.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
import React, { createContext, useContext, useState } from 'react';
import PropTypes from 'prop-types';

import { TRANSACTION_TYPES } from '../../shared/constants/transaction';
import { getMethodName } from '../helpers/utils/metrics';
import { useGasFeeContext } from './gasFee';
import { MetaMetricsContext } from './metametrics';

export const TransactionModalContext = createContext({});

export const TransactionModalContextProvider = ({
actionKey,
children,
methodData,
captureEventEnabled = true,
}) => {
export const TransactionModalContextProvider = ({ children }) => {
const [openModals, setOpenModals] = useState([]);
const metricsEvent = useContext(MetaMetricsContext);
const { transaction: { origin } = {} } = useGasFeeContext();

const captureEvent = () => {
metricsEvent({
eventOpts: {
category: 'Transactions',
action: 'Confirm Screen',
name: 'User clicks "Edit" on gas',
},
customVariables: {
recipientKnown: null,
functionType:
actionKey ||
getMethodName(methodData?.name) ||
TRANSACTION_TYPES.CONTRACT_INTERACTION,
origin,
},
});
};

const closeModal = (modalName) => {
const index = openModals.indexOf(modalName);
Expand All @@ -54,7 +24,6 @@ export const TransactionModalContextProvider = ({
if (openModals.includes(modalName)) {
return;
}
captureEventEnabled && captureEvent();
const modals = [...openModals];
modals.push(modalName);
setOpenModals(modals);
Expand All @@ -80,8 +49,5 @@ export function useTransactionModalContext() {
}

TransactionModalContextProvider.propTypes = {
actionKey: PropTypes.string,
children: PropTypes.node.isRequired,
methodData: PropTypes.object,
captureEventEnabled: PropTypes.bool,
};
2 changes: 1 addition & 1 deletion ui/hooks/gasFeeInput/useTransactionFunction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('useMaxPriorityFeePerGasInput', () => {
expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalledWith({
txParams: {
estimateSuggested: 'medium',
estimateSuggested: 'tenPercentIncreased',
estimateUsed: 'tenPercentIncreased',
gas: '5208',
gasLimit: '5208',
Expand Down
36 changes: 24 additions & 12 deletions ui/hooks/gasFeeInput/useTransactionFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ export const useTransactionFunctions = ({
}, [editGasMode, transaction?.previousGas, transaction?.txParams]);

const updateTransaction = useCallback(
({ estimateUsed, gasLimit, maxFeePerGas, maxPriorityFeePerGas }) => {
({
estimateUsed,
gasLimit,
maxFeePerGas,
maxPriorityFeePerGas,
estimateSuggested,
}) => {
const newGasSettings = {
gas: decimalToHex(gasLimit || gasLimitValue),
gasLimit: decimalToHex(gasLimit || gasLimitValue),
estimateSuggested: defaultEstimateToUse,
estimateSuggested: estimateSuggested || defaultEstimateToUse,
estimateUsed,
};
if (maxFeePerGas) {
Expand Down Expand Up @@ -111,17 +117,23 @@ export const useTransactionFunctions = ({
);
}, [dispatch, estimatedBaseFee, transaction]);

const updateTransactionToTenPercentIncreasedGasFee = useCallback(() => {
const { gas: gasLimit, maxFeePerGas, maxPriorityFeePerGas } =
transaction.previousGas || transaction.txParams;
const updateTransactionToTenPercentIncreasedGasFee = useCallback(
(initTransaction = false) => {
const { gas: gasLimit, maxFeePerGas, maxPriorityFeePerGas } =
transaction.previousGas || transaction.txParams;

updateTransaction({
estimateUsed: PRIORITY_LEVELS.TEN_PERCENT_INCREASED,
gasLimit,
maxFeePerGas: addTenPercentAndRound(maxFeePerGas),
maxPriorityFeePerGas: addTenPercentAndRound(maxPriorityFeePerGas),
});
}, [transaction, updateTransaction]);
updateTransaction({
estimateSuggested: initTransaction
? defaultEstimateToUse
: PRIORITY_LEVELS.TEN_PERCENT_INCREASED,
estimateUsed: PRIORITY_LEVELS.TEN_PERCENT_INCREASED,
gasLimit,
maxFeePerGas: addTenPercentAndRound(maxFeePerGas),
maxPriorityFeePerGas: addTenPercentAndRound(maxPriorityFeePerGas),
});
},
[defaultEstimateToUse, transaction, updateTransaction],
);

const updateTransactionUsingEstimate = useCallback(
(gasFeeEstimateToUse) => {
Expand Down
Loading