Skip to content

Commit

Permalink
Adding Metametrics for Activity Screen (#20077)
Browse files Browse the repository at this point in the history
* adding activity metrics and tests

* removing unnecessary stopPropagation
  • Loading branch information
vthomas13 authored Jul 25, 2023
1 parent 6914baa commit 3e6f1c3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
2 changes: 2 additions & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ export enum MetaMetricsEventName {
AccountPasswordCreated = 'Account Password Created',
AccountReset = 'Account Reset',
AccountRenamed = 'Account Renamed',
ActivityDetailsOpened = 'Activity Details Opened',
ActivityDetailsClosed = 'Activity Details Closed',
AppInstalled = 'App Installed',
AppUnlocked = 'App Unlocked',
AppUnlockedFailed = 'App Unlocked Failed',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ import {
import { IconColor } from '../../../helpers/constants/design-system';
import { Icon, IconName, IconSize } from '../../component-library';
///: END:ONLY_INCLUDE_IN
import { MetaMetricsEventCategory } from '../../../../shared/constants/metametrics';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import {
TransactionGroupCategory,
TransactionStatus,
Expand Down Expand Up @@ -172,8 +175,19 @@ function TransactionListItemInner({
history.push(`${CONFIRM_TRANSACTION_ROUTE}/${id}`);
return;
}
setShowDetails((prev) => !prev);
}, [isUnapproved, history, id]);
setShowDetails((prev) => {
trackEvent({
event: prev
? MetaMetricsEventName.ActivityDetailsClosed
: MetaMetricsEventName.ActivityDetailsOpened,
category: MetaMetricsEventCategory.Navigation,
properties: {
activity_type: category,
},
});
return !prev;
});
}, [isUnapproved, history, id, trackEvent, category]);

///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
const debugTransactionMeta = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import {
import { useGasFeeEstimates } from '../../../hooks/useGasFeeEstimates';
import { GasEstimateTypes } from '../../../../shared/constants/gas';
import { getTokens } from '../../../ducks/metamask/metamask';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import { MetaMetricsContext } from '../../../contexts/metametrics';

import TransactionListItem from '.';

const FEE_MARKET_ESTIMATE_RETURN_VALUE = {
Expand Down Expand Up @@ -115,6 +121,53 @@ const generateUseSelectorRouter = (opts) => (selector) => {
};

describe('TransactionListItem', () => {
describe('ActivityListItem interactions', () => {
beforeAll(() => {
useGasFeeEstimates.mockImplementation(
() => FEE_MARKET_ESTIMATE_RETURN_VALUE,
);
});

afterAll(() => {
useGasFeeEstimates.mockRestore();
});

it('should show the activity details popover and log metrics when the activity list item is clicked', () => {
useSelector.mockImplementation(
generateUseSelectorRouter({
balance: '0x3',
}),
);

const store = mockStore(mockState);
const mockTrackEvent = jest.fn();
const { queryByTestId } = renderWithProvider(
<MetaMetricsContext.Provider value={mockTrackEvent}>
<TransactionListItem transactionGroup={transactionGroup} />
</MetaMetricsContext.Provider>,
store,
);
const activityListItem = queryByTestId('activity-list-item');
fireEvent.click(activityListItem);
expect(mockTrackEvent).toHaveBeenCalledWith({
event: MetaMetricsEventName.ActivityDetailsOpened,
category: MetaMetricsEventCategory.Navigation,
properties: {
activity_type: 'send',
},
});
const popoverClose = queryByTestId('popover-close');
fireEvent.click(popoverClose);
expect(mockTrackEvent).toHaveBeenCalledWith({
event: MetaMetricsEventName.ActivityDetailsClosed,
category: MetaMetricsEventCategory.Navigation,
properties: {
activity_type: 'send',
},
});
});
});

describe('when account has insufficient balance to cover gas', () => {
beforeAll(() => {
useGasFeeEstimates.mockImplementation(
Expand Down

0 comments on commit 3e6f1c3

Please sign in to comment.