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 Metametrics for Activity Screen #20077

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 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 @@ -167,13 +170,28 @@ function TransactionListItemInner({
].includes(displayedStatusKey),
});

const toggleShowDetails = useCallback(() => {
if (isUnapproved) {
history.push(`${CONFIRM_TRANSACTION_ROUTE}/${id}`);
return;
}
setShowDetails((prev) => !prev);
}, [isUnapproved, history, id]);
const toggleShowDetails = useCallback(
(event) => {
event.stopPropagation();
vthomas13 marked this conversation as resolved.
Show resolved Hide resolved
if (isUnapproved) {
history.push(`${CONFIRM_TRANSACTION_ROUTE}/${id}`);
return;
}
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
Loading