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

feat: add Signature Redesign "Account Details Opened" event #24095

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ export enum MetaMetricsEventName {
AccountAdded = 'Account Added',
AccountAddSelected = 'Account Add Selected',
AccountAddFailed = 'Account Add Failed',
AccountDetailsOpened = 'Account Details Opened',
AccountPasswordCreated = 'Account Password Created',
AccountReset = 'Account Reset',
AccountRenamed = 'Account Renamed',
Expand Down Expand Up @@ -539,7 +540,6 @@ export enum MetaMetricsEventName {
MetricsOptIn = 'Metrics Opt In',
MetricsOptOut = 'Metrics Opt Out',
NavAccountMenuOpened = 'Account Menu Opened',
NavAccountDetailsOpened = 'Account Details Opened',
NavConnectedSitesOpened = 'Connected Sites Opened',
NavMainMenuOpened = 'Main Menu Opened',
NavPermissionsOpened = 'Permissions Opened',
Expand Down Expand Up @@ -784,6 +784,7 @@ export enum MetaMetricsTransactionEventSource {
}

export enum MetaMetricsEventLocation {
SignatureConfirmation = 'signature_confirmation',
TokenDetails = 'token_details',
TokenDetection = 'token_detection',
TokenMenu = 'token_menu',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const AccountDetailsMenuItem = ({
onClick={() => {
dispatch(setAccountDetailsAddress(address));
trackEvent({
event: MetaMetricsEventName.NavAccountDetailsOpened,
event: MetaMetricsEventName.AccountDetailsOpened,
category: MetaMetricsEventCategory.Navigation,
properties: {
location: metricsLocation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@ import React from 'react';
import { fireEvent, waitFor } from '@testing-library/react';
import mockState from '../../../../../../test/data/mock-state.json';
import { renderWithProvider } from '../../../../../../test/jest';
import { MetaMetricsContext } from '../../../../../contexts/metametrics';
import configureStore from '../../../../../store/store';

import {
MetaMetricsEventCategory,
MetaMetricsEventLocation,
MetaMetricsEventName,
} from '../../../../../../shared/constants/metametrics';

import HeaderInfo from './header-info';

const render = () => {
const store = configureStore({
metamask: {
...mockState.metamask,
},
confirm: {
currentConfirmation: {
msgParams: {
from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
},
const mockStore = {
metamask: {
...mockState.metamask,
},
confirm: {
currentConfirmation: {
msgParams: {
from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
},
type: 'eth_signTypedData_v4',
},
});
},
};

const render = () => {
const store = configureStore(mockStore);
return renderWithProvider(<HeaderInfo />, store);
};

Expand All @@ -33,22 +42,38 @@ describe('Header', () => {
const { getByLabelText } = render();
expect(getByLabelText('Account details')).toBeInTheDocument();
});
it('shows modal when account info icon is clicked', async () => {
const { getByLabelText, queryByTestId } = render();
expect(queryByTestId('account-details-modal')).not.toBeInTheDocument();
const accountInfoIcon = getByLabelText('Account details');
fireEvent.click(accountInfoIcon);
await waitFor(() => {
expect(queryByTestId('account-details-modal')).toBeInTheDocument();

describe('when account info icon is clicked', () => {
it('shows account info modal with address', async () => {
const { getByLabelText, getByText, queryByTestId } = render();
const accountInfoIcon = getByLabelText('Account details');
fireEvent.click(accountInfoIcon);
await waitFor(() => {
expect(queryByTestId('account-details-modal')).toBeInTheDocument();
expect(getByText('0x0DCD5...3E7bc')).toBeInTheDocument();
});
});
});
it('shows account info modal with address', async () => {
const { getByLabelText, getByText, queryByTestId } = render();
const accountInfoIcon = getByLabelText('Account details');
fireEvent.click(accountInfoIcon);
await waitFor(() => {
expect(queryByTestId('account-details-modal')).toBeInTheDocument();
expect(getByText('0x0DCD5...3E7bc')).toBeInTheDocument();

it(`sends "${MetaMetricsEventName.AccountDetailsOpened}" metametric`, () => {
const mockTrackEvent = jest.fn();
const { getByLabelText } = renderWithProvider(
<MetaMetricsContext.Provider value={mockTrackEvent}>
<HeaderInfo />
</MetaMetricsContext.Provider>,
configureStore(mockStore),
);
const accountInfoIcon = getByLabelText('Account details');
fireEvent.click(accountInfoIcon);

expect(mockTrackEvent).toHaveBeenNthCalledWith(1, {
category: MetaMetricsEventCategory.Transactions,
event: MetaMetricsEventName.AccountDetailsOpened,
properties: {
action: 'Confirm Screen',
location: MetaMetricsEventLocation.SignatureConfirmation,
signature_type: 'eth_signTypedData_v4',
},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useContext } from 'react';
import { useSelector } from 'react-redux';
import {
AvatarAccount,
Expand Down Expand Up @@ -27,20 +27,45 @@ import { AddressCopyButton } from '../../../../../components/multichain';
import Tooltip from '../../../../../components/ui/tooltip/tooltip';
import { useI18nContext } from '../../../../../hooks/useI18nContext';
import useConfirmationRecipientInfo from '../../../hooks/useConfirmationRecipientInfo';
import { getUseBlockie } from '../../../../../selectors';

import {
currentConfirmationSelector,
getUseBlockie,
} from '../../../../../selectors';
import {
MetaMetricsEventCategory,
MetaMetricsEventLocation,
MetaMetricsEventName,
} from '../../../../../../shared/constants/metametrics';
import { MetaMetricsContext } from '../../../../../contexts/metametrics';
import { ConfirmInfoRowCurrency } from '../../../../../components/app/confirm/info/row/currency';
import { useBalance } from '../../../hooks/useBalance';

const HeaderInfo = () => {
const useBlockie = useSelector(getUseBlockie);
const [showAccountInfo, setShowAccountInfo] = React.useState(false);

const currentConfirmation = useSelector(currentConfirmationSelector);
const { recipientAddress: fromAddress, recipientName: fromName } =
useConfirmationRecipientInfo();

const t = useI18nContext();
const trackEvent = useContext(MetaMetricsContext);

const { balance: balanceToUse } = useBalance(fromAddress);

function trackAccountModalOpened() {
trackEvent({
category: MetaMetricsEventCategory.Transactions,
event: MetaMetricsEventName.AccountDetailsOpened,
properties: {
action: 'Confirm Screen',
location: MetaMetricsEventLocation.SignatureConfirmation,
signature_type: currentConfirmation?.type,
},
});
}

return (
<>
<Box
Expand All @@ -55,7 +80,10 @@ const HeaderInfo = () => {
ariaLabel={t('accountDetails')}
iconName={IconName.Info}
size={ButtonIconSize.Md}
onClick={() => setShowAccountInfo(true)}
onClick={() => {
trackAccountModalOpened();
setShowAccountInfo(true);
}}
/>
</Tooltip>
</Box>
Expand Down
Loading