Date: Thu, 11 Jul 2024 22:34:30 -0400
Subject: [PATCH 14/40] updating the background function call and fixing e2e
---
.../metrics/delete-metametrics-data.spec.ts | 46 +++++++++++--------
.../clear-metametrics-data.tsx | 25 +++-------
.../delete-metametrics-data-toggle.test.tsx | 2 +-
.../delete-metametrics-data-toggle.tsx | 6 +--
.../metametrics-toggle/metametrics-toggle.tsx | 5 +-
.../security-tab/security-tab.container.js | 2 +-
ui/selectors/selectors.js | 2 +-
7 files changed, 40 insertions(+), 48 deletions(-)
diff --git a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
index 632ce48d4d4d..3263d606a6f7 100644
--- a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
+++ b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
@@ -49,31 +49,31 @@ const mockSegment = async (mockServer: Mockttp) => {
};
}),
await mockServer
- .forPost(
- 'https://proxy.dev-api.cx.metamask.io/segment/v1/regulations/sources/wygFTooEUUtcckty9kaMc',
+ .forPost('https://metametrics.metamask.test/regulations/sources/test')
+ .withHeaders({ 'Content-Type': 'application/vnd.segment.v1+json' })
+ .withBodyIncluding(
+ JSON.stringify({
+ regulationType: 'DELETE_ONLY',
+ subjectType: 'USER_ID',
+ subjectIds: ['fake-metrics-id'],
+ }),
)
- .withJsonBodyIncluding({
- batch: [
- {
- regulationType: 'DELETE_ONLY',
- subjectType: 'USER_ID',
- subjectIds: ['fake-metrics-id'],
- },
- ],
- })
.thenCallback(() => ({
statusCode: 200,
- data: { regulateId: 'fake-delete-regulation-id' },
+ json: { data: { regulateId: 'fake-delete-regulation-id' } },
})),
await mockServer
.forGet(
- 'https://proxy.dev-api.cx.metamask.io/segment/v1/regulations/fake-delete-regulation-id',
+ 'https://metametrics.metamask.test/regulations/fake-delete-regulation-id',
)
+ .withHeaders({ 'Content-Type': 'application/vnd.segment.v1+json' })
.thenCallback(() => ({
statusCode: 200,
- data: {
- regulation: {
- overallStatus: 'FINISHED',
+ json: {
+ data: {
+ regulation: {
+ overallStatus: 'FINISHED',
+ },
},
},
})),
@@ -119,7 +119,10 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
const deleteMetaMetricsDataButton = await driver.findElement(
rowLocators.deleteMetaMetricsDataButton,
);
- await deleteMetaMetricsDataButton.waitForElementState('disabled');
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ await (deleteMetaMetricsDataButton as any).waitForElementState(
+ 'disabled',
+ );
assert.equal(
await deleteMetaMetricsDataButton.isEnabled(),
false,
@@ -127,7 +130,7 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
);
const events = await getEventPayloads(driver, mockedEndpoints);
- assert.equal(events.length, 1);
+ assert.equal(events.length, 3);
assert.deepStrictEqual(events[0].properties, {
category: 'Settings',
locale: 'en',
@@ -180,7 +183,10 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
const deleteMetaMetricsDataButton = await driver.findElement(
rowLocators.deleteMetaMetricsDataButton,
);
- await deleteMetaMetricsDataButton.waitForElementState('disabled');
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ await (deleteMetaMetricsDataButton as any).waitForElementState(
+ 'disabled',
+ );
assert.equal(
await deleteMetaMetricsDataButton.isEnabled(),
false,
@@ -188,7 +194,7 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
);
const events = await getEventPayloads(driver, mockedEndpoints);
- assert.equal(events.length, 0);
+ assert.equal(events.length, 2);
await driver.clickElement(rowLocators.experimentalSettings);
await driver.clickElement(rowLocators.securityAndPrivacySettings);
diff --git a/ui/components/app/clear-metametrics-data/clear-metametrics-data.tsx b/ui/components/app/clear-metametrics-data/clear-metametrics-data.tsx
index 26d4443a9e03..aa4df5086d06 100644
--- a/ui/components/app/clear-metametrics-data/clear-metametrics-data.tsx
+++ b/ui/components/app/clear-metametrics-data/clear-metametrics-data.tsx
@@ -1,5 +1,5 @@
import React, { useContext } from 'react';
-import { useDispatch, useSelector } from 'react-redux';
+import { useDispatch } from 'react-redux';
import {
hideDeleteMetaMetricsDataModal,
markingMetaMetricsDataDeletion,
@@ -26,11 +26,7 @@ import {
JustifyContent,
TextVariant,
} from '../../../helpers/constants/design-system';
-import {
- createMetaMetricsDataDeletionTask,
- setHasMetaMetricsDataRecorded,
-} from '../../../store/actions';
-import { getParticipateInMetaMetrics } from '../../../selectors';
+import { createMetaMetricsDataDeletionTask } from '../../../store/actions';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import {
MetaMetricsEventCategory,
@@ -42,25 +38,18 @@ export default function ClearMetaMetricsData() {
const dispatch = useDispatch();
const trackEvent = useContext(MetaMetricsContext);
- const participateInMetaMetrics = useSelector(getParticipateInMetaMetrics);
-
const closeModal = () => {
dispatch(hideDeleteMetaMetricsDataModal());
};
const deleteMetaMetricsData = async () => {
try {
- await dispatch(createMetaMetricsDataDeletionTask());
+ await createMetaMetricsDataDeletionTask();
dispatch(markingMetaMetricsDataDeletion());
- if (participateInMetaMetrics) {
- dispatch(setHasMetaMetricsDataRecorded(true));
- trackEvent({
- category: MetaMetricsEventCategory.Settings,
- event: MetaMetricsEventName.MetricsDataDeletionRequest,
- });
- } else {
- dispatch(setHasMetaMetricsDataRecorded(false));
- }
+ trackEvent({
+ category: MetaMetricsEventCategory.Settings,
+ event: MetaMetricsEventName.MetricsDataDeletionRequest,
+ });
} catch (error: unknown) {
dispatch(openDataDeletionErrorModal());
} finally {
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.test.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.test.tsx
index 9d36f3df4f82..dbe20a4932c2 100644
--- a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.test.tsx
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.test.tsx
@@ -36,7 +36,7 @@ describe('DeleteMetaMetricsDataToggle', () => {
return 'fake-metrics-id';
}
if (selector === hasRecordedMetricsSinceDeletion) {
- return undefined;
+ return null;
}
if (selector === getMetaMetricsDataDeletionStatus) {
return undefined;
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx
index 253bfa686a5b..f8bd65fe4363 100644
--- a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx
@@ -59,9 +59,9 @@ const DeleteMetaMetricsDataToggle = () => {
if (!dataDeletionButtonDisabled && metaMetricsDataDeletionStatus) {
dataDeletionButtonDisabled =
[
- DeleteRegulationStatus.INITIALIZED,
- DeleteRegulationStatus.RUNNING,
- DeleteRegulationStatus.FINISHED,
+ DeleteRegulationStatus.initialized,
+ DeleteRegulationStatus.running,
+ DeleteRegulationStatus.finished,
].includes(metaMetricsDataDeletionStatus) &&
!hasMetricsRecordedAfterDeletion;
}
diff --git a/ui/pages/settings/security-tab/metametrics-toggle/metametrics-toggle.tsx b/ui/pages/settings/security-tab/metametrics-toggle/metametrics-toggle.tsx
index 1182c7af8924..661dd7f974b4 100644
--- a/ui/pages/settings/security-tab/metametrics-toggle/metametrics-toggle.tsx
+++ b/ui/pages/settings/security-tab/metametrics-toggle/metametrics-toggle.tsx
@@ -1,5 +1,5 @@
import React, { useContext } from 'react';
-import { useDispatch, useSelector } from 'react-redux';
+import { useSelector } from 'react-redux';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import { MetaMetricsContext } from '../../../../contexts/metametrics';
import {
@@ -21,7 +21,6 @@ import {
TextColor,
TextVariant,
} from '../../../../helpers/constants/design-system';
-import { setHasMetaMetricsDataRecorded } from '../../../../store/actions';
const MetametricsToggle = ({
dataCollectionForMarketing,
@@ -31,7 +30,6 @@ const MetametricsToggle = ({
setDataCollectionForMarketing: (value: boolean) => void;
}) => {
const t = useI18nContext();
- const dispatch = useDispatch();
const trackEvent = useContext(MetaMetricsContext);
const { enableMetametrics, error: enableMetametricsError } =
useEnableMetametrics();
@@ -74,7 +72,6 @@ const MetametricsToggle = ({
participateInMetaMetrics,
},
});
- dispatch(setHasMetaMetricsDataRecorded(true));
}
if (dataCollectionForMarketing) {
diff --git a/ui/pages/settings/security-tab/security-tab.container.js b/ui/pages/settings/security-tab/security-tab.container.js
index 683d80e2ea33..917529651348 100644
--- a/ui/pages/settings/security-tab/security-tab.container.js
+++ b/ui/pages/settings/security-tab/security-tab.container.js
@@ -121,7 +121,7 @@ const mapDispatchToProps = (dispatch) => {
return dispatch(setUseTransactionSimulations(value));
},
updateDataDeletionTaskStatus: () => {
- return dispatch(updateDataDeletionTaskStatus());
+ return updateDataDeletionTaskStatus();
},
unMarkingMetaMetricsDataDeletion: () => {
return dispatch(unMarkingMetaMetricsDataDeletion());
diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js
index 4e6710074b84..0d9f91c63a59 100644
--- a/ui/selectors/selectors.js
+++ b/ui/selectors/selectors.js
@@ -2586,7 +2586,7 @@ export function isMetaMetricsDataDeletionMarked(state) {
}
export function hasRecordedMetricsSinceDeletion(state) {
- return state.metamask.hasMetaMetricsDataRecorded;
+ return state.metamask.participateInDuringDeletion;
}
/**
From a8c3c6999fd8a775251b7a08d889f61312e8bead Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Thu, 11 Jul 2024 22:36:33 -0400
Subject: [PATCH 15/40] reverting changes to privacy snapshot
---
privacy-snapshot.json | 1 -
1 file changed, 1 deletion(-)
diff --git a/privacy-snapshot.json b/privacy-snapshot.json
index 964e32f5baa5..b8920724a597 100644
--- a/privacy-snapshot.json
+++ b/privacy-snapshot.json
@@ -42,7 +42,6 @@
"portfolio.metamask.io",
"price.api.cx.metamask.io",
"proxy.api.cx.metamask.io",
- "proxy.dev-api.cx.metamask.io",
"raw.githubusercontent.com",
"registry.npmjs.org",
"responsive-rpc.test",
From 3f28e4ecb84d0199fb372a9e2eedfc6fcf4a3849 Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Fri, 12 Jul 2024 11:31:22 -0400
Subject: [PATCH 16/40] adding state to keep track of data being recorded
---
.../delete-metametrics-data-toggle.test.tsx | 12 ++++++------
.../delete-metametrics-data-toggle.tsx | 17 ++++++++++++-----
ui/selectors/selectors.js | 2 +-
3 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.test.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.test.tsx
index dbe20a4932c2..4e00dcccbe9d 100644
--- a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.test.tsx
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.test.tsx
@@ -9,7 +9,7 @@ import {
getMetaMetricsDataDeletionDate,
getMetaMetricsDataDeletionStatus,
getMetaMetricsId,
- hasRecordedMetricsSinceDeletion,
+ getParticipateInDuringDeletion,
isMetaMetricsDataDeletionMarked,
} from '../../../../selectors';
import { openDeleteMetaMetricsDataModal } from '../../../../ducks/app/app';
@@ -35,7 +35,7 @@ describe('DeleteMetaMetricsDataToggle', () => {
if (selector === getMetaMetricsId) {
return 'fake-metrics-id';
}
- if (selector === hasRecordedMetricsSinceDeletion) {
+ if (selector === getParticipateInDuringDeletion) {
return null;
}
if (selector === getMetaMetricsDataDeletionStatus) {
@@ -85,7 +85,7 @@ describe('DeleteMetaMetricsDataToggle', () => {
});
it('should enable the data deletion button when page mounts after a deletion task is performed and more data is recoded after the deletion', async () => {
useSelectorMock.mockImplementation((selector) => {
- if (selector === hasRecordedMetricsSinceDeletion) {
+ if (selector === getParticipateInDuringDeletion) {
return true;
}
if (selector === getMetaMetricsDataDeletionStatus) {
@@ -148,7 +148,7 @@ describe('DeleteMetaMetricsDataToggle', () => {
if (selector === getMetaMetricsId) {
return 'fake-metrics-id';
}
- if (selector === hasRecordedMetricsSinceDeletion) {
+ if (selector === getParticipateInDuringDeletion) {
return true;
}
if (selector === getMetaMetricsDataDeletionStatus) {
@@ -177,13 +177,13 @@ describe('DeleteMetaMetricsDataToggle', () => {
// particilapteInMetrics will be false before the deletion is performed, this way no further data will be recorded after deletion.
it('should disable the data deletion button after a deletion task is performed and no data is recoded after the deletion', async () => {
useSelectorMock.mockImplementation((selector) => {
- if (selector === hasRecordedMetricsSinceDeletion) {
+ if (selector === getParticipateInDuringDeletion) {
return false;
}
if (selector === getMetaMetricsId) {
return 'fake-metrics-id';
}
- if (selector === hasRecordedMetricsSinceDeletion) {
+ if (selector === getParticipateInDuringDeletion) {
return true;
}
if (selector === getMetaMetricsDataDeletionStatus) {
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx
index f8bd65fe4363..baaf0c51115f 100644
--- a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { CONSENSYS_PRIVACY_LINK } from '../../../../../shared/lib/ui-utils';
import ClearMetametricsData from '../../../../components/app/clear-metametrics-data';
@@ -22,8 +22,9 @@ import {
getMetaMetricsId,
getShowDataDeletionErrorModal,
getShowDeleteMetaMetricsDataModal,
- hasRecordedMetricsSinceDeletion,
+ getParticipateInDuringDeletion,
isMetaMetricsDataDeletionMarked,
+ getParticipateInMetaMetrics,
} from '../../../../selectors';
import { openDeleteMetaMetricsDataModal } from '../../../../ducks/app/app';
import DataDeletionErrorModal from '../../../../components/app/data-deletion-error-modal';
@@ -35,9 +36,6 @@ const DeleteMetaMetricsDataToggle = () => {
const dispatch = useDispatch();
const metaMetricsId = useSelector(getMetaMetricsId);
- const hasMetricsRecordedAfterDeletion = useSelector(
- hasRecordedMetricsSinceDeletion,
- );
const metaMetricsDataDeletionStatus = useSelector(
getMetaMetricsDataDeletionStatus,
);
@@ -53,6 +51,15 @@ const DeleteMetaMetricsDataToggle = () => {
getShowDeleteMetaMetricsDataModal,
);
const showDataDeletionErrorModal = useSelector(getShowDataDeletionErrorModal);
+ const participateInDuringDeletion: boolean = useSelector(
+ getParticipateInDuringDeletion,
+ );
+ const participateInMetaMetrics = useSelector(getParticipateInMetaMetrics);
+ const [hasMetricsRecordedAfterDeletion, setHasMetricsRecordedAfterDeletion] =
+ useState(participateInDuringDeletion);
+ if (!hasMetricsRecordedAfterDeletion && participateInMetaMetrics) {
+ setHasMetricsRecordedAfterDeletion(participateInMetaMetrics);
+ }
let dataDeletionButtonDisabled: boolean =
metaMetricsDataDeletionMarked || Boolean(!metaMetricsId);
diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js
index 0d9f91c63a59..416240211e58 100644
--- a/ui/selectors/selectors.js
+++ b/ui/selectors/selectors.js
@@ -2585,7 +2585,7 @@ export function isMetaMetricsDataDeletionMarked(state) {
return state.appState.metaMetricsDataDeletionMarked;
}
-export function hasRecordedMetricsSinceDeletion(state) {
+export function getParticipateInDuringDeletion(state) {
return state.metamask.participateInDuringDeletion;
}
From 382946f6526c7ee5c8c2254a5a6b061322eae47b Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Fri, 12 Jul 2024 12:07:12 -0400
Subject: [PATCH 17/40] renaming the toggle files
---
.../metrics/delete-metametrics-data.spec.ts | 2 +-
.../__snapshots__/security-tab.test.js.snap | 2 +-
.../delete-metametrics-data-toggle.test.tsx | 224 ------------------
.../delete-metametrics-data-toggle.tsx | 135 -----------
.../delete-metametrics-data-toggle/index.ts | 1 -
.../security-tab/security-tab.component.js | 4 +-
.../security-tab/security-tab.test.js | 2 +-
7 files changed, 5 insertions(+), 365 deletions(-)
delete mode 100644 ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.test.tsx
delete mode 100644 ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx
delete mode 100644 ui/pages/settings/security-tab/delete-metametrics-data-toggle/index.ts
diff --git a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
index 3263d606a6f7..246043ae3caa 100644
--- a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
+++ b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
@@ -15,7 +15,7 @@ const rowLocators = {
globalMenuSettingsButton: '[data-testid="global-menu-settings"]',
securityAndPrivacySettings: { text: 'Security & privacy', tag: 'div' },
experimentalSettings: { text: 'Experimental', tag: 'div' },
- deletMetaMetricsSettings: '[data-testid="delete-metametrics-data-toggle"]',
+ deletMetaMetricsSettings: '[data-testid="delete-metametrics-data-button"]',
deleteMetaMetricsDataButton: {
text: 'Delete MetaMetrics data',
tag: 'button',
diff --git a/ui/pages/settings/security-tab/__snapshots__/security-tab.test.js.snap b/ui/pages/settings/security-tab/__snapshots__/security-tab.test.js.snap
index 3c8094c817a4..82797e3b1589 100644
--- a/ui/pages/settings/security-tab/__snapshots__/security-tab.test.js.snap
+++ b/ui/pages/settings/security-tab/__snapshots__/security-tab.test.js.snap
@@ -1820,7 +1820,7 @@ exports[`Security Tab should match snapshot 1`] = `
({
- ...jest.requireActual('react-redux'),
- useSelector: jest.fn(),
- useDispatch: jest.fn(),
-}));
-
-describe('DeleteMetaMetricsDataToggle', () => {
- const useSelectorMock = useSelector as jest.Mock;
- const useDispatchMock = useDispatch as jest.Mock;
- const mockDispatch = jest.fn();
-
- beforeEach(() => {
- useDispatchMock.mockReturnValue(mockDispatch);
- useSelectorMock.mockImplementation((selector) => {
- if (selector === isMetaMetricsDataDeletionMarked) {
- return false;
- }
- if (selector === getMetaMetricsId) {
- return 'fake-metrics-id';
- }
- if (selector === getParticipateInDuringDeletion) {
- return null;
- }
- if (selector === getMetaMetricsDataDeletionStatus) {
- return undefined;
- }
- if (selector === getMetaMetricsDataDeletionDate) {
- return '';
- }
-
- return undefined;
- });
- });
-
- afterEach(() => {
- jest.clearAllMocks();
- });
-
- it('renders correctly', () => {
- const store = configureStore({});
- const { getByText, getByTestId, getAllByText } = renderWithProvider(
-
,
- store,
- );
- expect(getByTestId('delete-metametrics-data-toggle')).toBeInTheDocument();
- expect(getAllByText('Delete MetaMetrics data')).toHaveLength(2);
- expect(
- getByText(
- /This will delete historical MetaMetrics data associated with your use on this device. Your wallet and accounts will remain exactly as they are now after this data has been deleted. This process may take up to 30 days. View our/u,
- ),
- ).toBeInTheDocument();
- });
-
- it('should enable the data deletion button when metrics is opted in and metametrics id is available ', async () => {
- const store = configureStore({});
- const { getByRole, getByText } = renderWithProvider(
-
,
- store,
- );
- expect(
- getByRole('button', { name: 'Delete MetaMetrics data' }),
- ).toBeEnabled();
- expect(
- getByText(
- /This will delete historical MetaMetrics data associated with your use on this device. Your wallet and accounts will remain exactly as they are now after this data has been deleted. This process may take up to 30 days. View our/u,
- ),
- ).toBeInTheDocument();
- });
- it('should enable the data deletion button when page mounts after a deletion task is performed and more data is recoded after the deletion', async () => {
- useSelectorMock.mockImplementation((selector) => {
- if (selector === getParticipateInDuringDeletion) {
- return true;
- }
- if (selector === getMetaMetricsDataDeletionStatus) {
- return 'INITIALIZED';
- }
- if (selector === getMetaMetricsId) {
- return 'fake-metrics-id';
- }
- return undefined;
- });
- const store = configureStore({});
- const { getByRole, getByText } = renderWithProvider(
-
,
- store,
- );
- expect(
- getByRole('button', { name: 'Delete MetaMetrics data' }),
- ).toBeEnabled();
- expect(
- getByText(
- /This will delete historical MetaMetrics data associated with your use on this device. Your wallet and accounts will remain exactly as they are now after this data has been deleted. This process may take up to 30 days. View our/u,
- ),
- ).toBeInTheDocument();
- });
-
- // if user does not opt in to participate in metrics or for profile sync, metametricsId will not be created.
- it('should disable the data deletion button when there is metametrics id not available', async () => {
- useSelectorMock.mockImplementation((selector) => {
- if (selector === getMetaMetricsId) {
- return null;
- }
- return undefined;
- });
- const store = configureStore({});
- const { getByRole, getByText } = renderWithProvider(
-
,
- store,
- );
- expect(
- getByRole('button', { name: 'Delete MetaMetrics data' }),
- ).toBeDisabled();
- expect(
- getByText(
- /This will delete historical MetaMetrics data associated with your use on this device. Your wallet and accounts will remain exactly as they are now after this data has been deleted. This process may take up to 30 days. View our/u,
- ),
- ).toBeInTheDocument();
- expect(
- getByText(
- /Since you've never opted into MetaMetrics, there's no data to delete here./u,
- ),
- ).toBeInTheDocument();
- });
-
- // metaMetricsDataDeletionMarked is set to true right after the deletion is performed, it will rest to false when the page unmounts.
- it('should disable the data deletion button when metaMetricsDataDeletionMarked is true', async () => {
- useSelectorMock.mockImplementation((selector) => {
- if (selector === isMetaMetricsDataDeletionMarked) {
- return true;
- }
- if (selector === getMetaMetricsId) {
- return 'fake-metrics-id';
- }
- if (selector === getParticipateInDuringDeletion) {
- return true;
- }
- if (selector === getMetaMetricsDataDeletionStatus) {
- return 'INITIALIZED';
- }
- if (selector === getMetaMetricsDataDeletionDate) {
- return 1717779342113;
- }
- return undefined;
- });
- const store = configureStore({});
- const { getByRole, getByText } = renderWithProvider(
-
,
- store,
- );
- expect(
- getByRole('button', { name: 'Delete MetaMetrics data' }),
- ).toBeDisabled();
- expect(
- getByText(
- /You initiated this action on 7\/06\/2024. This process can take up to 30 days. View the/u,
- ),
- ).toBeInTheDocument();
- });
-
- // particilapteInMetrics will be false before the deletion is performed, this way no further data will be recorded after deletion.
- it('should disable the data deletion button after a deletion task is performed and no data is recoded after the deletion', async () => {
- useSelectorMock.mockImplementation((selector) => {
- if (selector === getParticipateInDuringDeletion) {
- return false;
- }
- if (selector === getMetaMetricsId) {
- return 'fake-metrics-id';
- }
- if (selector === getParticipateInDuringDeletion) {
- return true;
- }
- if (selector === getMetaMetricsDataDeletionStatus) {
- return 'INITIALIZED';
- }
- if (selector === getMetaMetricsDataDeletionDate) {
- return 1717779342113;
- }
- return undefined;
- });
- const store = configureStore({});
- const { getByRole, getByText } = renderWithProvider(
-
,
- store,
- );
- expect(
- getByRole('button', { name: 'Delete MetaMetrics data' }),
- ).toBeDisabled();
- expect(
- getByText(
- /You initiated this action on 7\/06\/2024. This process can take up to 30 days. View the/u,
- ),
- ).toBeInTheDocument();
- });
-
- it('should open the modal on the button click', () => {
- const store = configureStore({});
- const { getByRole } = renderWithProvider(
-
,
- store,
- );
- const deleteButton = getByRole('button', {
- name: 'Delete MetaMetrics data',
- });
- fireEvent.click(deleteButton);
- expect(mockDispatch).toHaveBeenCalledWith(openDeleteMetaMetricsDataModal());
- });
-});
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx
deleted file mode 100644
index baaf0c51115f..000000000000
--- a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/delete-metametrics-data-toggle.tsx
+++ /dev/null
@@ -1,135 +0,0 @@
-import React, { useState } from 'react';
-import { useDispatch, useSelector } from 'react-redux';
-import { CONSENSYS_PRIVACY_LINK } from '../../../../../shared/lib/ui-utils';
-import ClearMetametricsData from '../../../../components/app/clear-metametrics-data';
-import {
- Box,
- ButtonPrimary,
- Icon,
- IconName,
- IconSize,
- Text,
-} from '../../../../components/component-library';
-import {
- Display,
- FlexDirection,
- TextVariant,
-} from '../../../../helpers/constants/design-system';
-import { useI18nContext } from '../../../../hooks/useI18nContext';
-import {
- getMetaMetricsDataDeletionDate,
- getMetaMetricsDataDeletionStatus,
- getMetaMetricsId,
- getShowDataDeletionErrorModal,
- getShowDeleteMetaMetricsDataModal,
- getParticipateInDuringDeletion,
- isMetaMetricsDataDeletionMarked,
- getParticipateInMetaMetrics,
-} from '../../../../selectors';
-import { openDeleteMetaMetricsDataModal } from '../../../../ducks/app/app';
-import DataDeletionErrorModal from '../../../../components/app/data-deletion-error-modal';
-import { formatDate } from '../../../../helpers/utils/util';
-import { DeleteRegulationStatus } from '../../../../../shared/constants/metametrics';
-
-const DeleteMetaMetricsDataToggle = () => {
- const t = useI18nContext();
- const dispatch = useDispatch();
-
- const metaMetricsId = useSelector(getMetaMetricsId);
- const metaMetricsDataDeletionStatus = useSelector(
- getMetaMetricsDataDeletionStatus,
- );
- const metaMetricsDataDeletionDate = useSelector(
- getMetaMetricsDataDeletionDate,
- );
- const formatedDate = formatDate(metaMetricsDataDeletionDate, 'd/MM/y');
-
- const metaMetricsDataDeletionMarked = useSelector(
- isMetaMetricsDataDeletionMarked,
- );
- const showDeleteMetaMetricsDataModal = useSelector(
- getShowDeleteMetaMetricsDataModal,
- );
- const showDataDeletionErrorModal = useSelector(getShowDataDeletionErrorModal);
- const participateInDuringDeletion: boolean = useSelector(
- getParticipateInDuringDeletion,
- );
- const participateInMetaMetrics = useSelector(getParticipateInMetaMetrics);
- const [hasMetricsRecordedAfterDeletion, setHasMetricsRecordedAfterDeletion] =
- useState(participateInDuringDeletion);
- if (!hasMetricsRecordedAfterDeletion && participateInMetaMetrics) {
- setHasMetricsRecordedAfterDeletion(participateInMetaMetrics);
- }
-
- let dataDeletionButtonDisabled: boolean =
- metaMetricsDataDeletionMarked || Boolean(!metaMetricsId);
- if (!dataDeletionButtonDisabled && metaMetricsDataDeletionStatus) {
- dataDeletionButtonDisabled =
- [
- DeleteRegulationStatus.initialized,
- DeleteRegulationStatus.running,
- DeleteRegulationStatus.finished,
- ].includes(metaMetricsDataDeletionStatus) &&
- !hasMetricsRecordedAfterDeletion;
- }
- const privacyPolicyLink = (
-
- {t('privacyMsg')}
-
- );
- return (
- <>
-
-
-
{t('deleteMetaMetricsData')}
-
- {dataDeletionButtonDisabled && Boolean(metaMetricsId)
- ? t('deleteMetaMetricsDataRequestedDescription', [
- formatedDate,
- privacyPolicyLink,
- ])
- : t('deleteMetaMetricsDataDescription', [privacyPolicyLink])}
-
-
-
- {Boolean(!metaMetricsId) && (
-
-
-
- {t('metaMetricsIdNotAvailableError')}
-
-
- )}
- {
- dispatch(openDeleteMetaMetricsDataModal());
- }}
- disabled={dataDeletionButtonDisabled}
- >
- {t('deleteMetaMetricsData')}
-
-
-
- {showDeleteMetaMetricsDataModal &&
}
- {showDataDeletionErrorModal &&
}
- >
- );
-};
-
-export default DeleteMetaMetricsDataToggle;
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/index.ts b/ui/pages/settings/security-tab/delete-metametrics-data-toggle/index.ts
deleted file mode 100644
index 88bbefe41a5b..000000000000
--- a/ui/pages/settings/security-tab/delete-metametrics-data-toggle/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default } from './delete-metametrics-data-toggle';
diff --git a/ui/pages/settings/security-tab/security-tab.component.js b/ui/pages/settings/security-tab/security-tab.component.js
index c37a7bc9a971..7364033d2224 100644
--- a/ui/pages/settings/security-tab/security-tab.component.js
+++ b/ui/pages/settings/security-tab/security-tab.component.js
@@ -55,7 +55,7 @@ import IncomingTransactionToggle from '../../../components/app/incoming-trasacti
import { updateDataDeletionTaskStatus } from '../../../store/actions';
import MetametricsToggle from './metametrics-toggle';
import ProfileSyncToggle from './profile-sync-toggle';
-import DeleteMetametricsDataToggle from './delete-metametrics-data-toggle';
+import DeleteMetametricsDataButton from './delete-metametrics-data-button';
export default class SecurityTab extends PureComponent {
static contextTypes = {
@@ -1230,7 +1230,7 @@ export default class SecurityTab extends PureComponent {
setDataCollectionForMarketing={setDataCollectionForMarketing}
/>
{this.renderDataCollectionForMarketing()}
-
+
);
diff --git a/ui/pages/settings/security-tab/security-tab.test.js b/ui/pages/settings/security-tab/security-tab.test.js
index 89a82c079e76..ef962b56c641 100644
--- a/ui/pages/settings/security-tab/security-tab.test.js
+++ b/ui/pages/settings/security-tab/security-tab.test.js
@@ -235,7 +235,7 @@ describe('Security Tab', () => {
renderWithProvider(
, localMockStore);
expect(
- screen.queryByTestId(`delete-metametrics-data-toggle`),
+ screen.queryByTestId(`delete-metametrics-data-button`),
).toBeInTheDocument();
fireEvent.click(
From f6a354cfe649329f4d9b2607e250fe605b91a273 Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Fri, 12 Jul 2024 12:07:24 -0400
Subject: [PATCH 18/40] renaming the toggle files
---
.../delete-metametrics-data-button.test.tsx | 224 ++++++++++++++++++
.../delete-metametrics-data-button.tsx | 135 +++++++++++
.../delete-metametrics-data-button/index.ts | 1 +
3 files changed, 360 insertions(+)
create mode 100644 ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx
create mode 100644 ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
create mode 100644 ui/pages/settings/security-tab/delete-metametrics-data-button/index.ts
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx
new file mode 100644
index 000000000000..ba78272adbaa
--- /dev/null
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx
@@ -0,0 +1,224 @@
+import * as React from 'react';
+import { useDispatch, useSelector } from 'react-redux';
+import { fireEvent } from '@testing-library/react';
+import configureStore from '../../../../store/store';
+// import mockState from '../../../../../test/data/mock-state.json';
+import { renderWithProvider } from '../../../../../test/lib/render-helpers';
+
+import {
+ getMetaMetricsDataDeletionDate,
+ getMetaMetricsDataDeletionStatus,
+ getMetaMetricsId,
+ getParticipateInDuringDeletion,
+ isMetaMetricsDataDeletionMarked,
+} from '../../../../selectors';
+import { openDeleteMetaMetricsDataModal } from '../../../../ducks/app/app';
+import DeleteMetaMetricsDataButton from './delete-metametrics-data-button';
+
+jest.mock('react-redux', () => ({
+ ...jest.requireActual('react-redux'),
+ useSelector: jest.fn(),
+ useDispatch: jest.fn(),
+}));
+
+describe('DeleteMetaMetricsDataButton', () => {
+ const useSelectorMock = useSelector as jest.Mock;
+ const useDispatchMock = useDispatch as jest.Mock;
+ const mockDispatch = jest.fn();
+
+ beforeEach(() => {
+ useDispatchMock.mockReturnValue(mockDispatch);
+ useSelectorMock.mockImplementation((selector) => {
+ if (selector === isMetaMetricsDataDeletionMarked) {
+ return false;
+ }
+ if (selector === getMetaMetricsId) {
+ return 'fake-metrics-id';
+ }
+ if (selector === getParticipateInDuringDeletion) {
+ return null;
+ }
+ if (selector === getMetaMetricsDataDeletionStatus) {
+ return undefined;
+ }
+ if (selector === getMetaMetricsDataDeletionDate) {
+ return '';
+ }
+
+ return undefined;
+ });
+ });
+
+ afterEach(() => {
+ jest.clearAllMocks();
+ });
+
+ it('renders correctly', () => {
+ const store = configureStore({});
+ const { getByText, getByTestId, getAllByText } = renderWithProvider(
+
,
+ store,
+ );
+ expect(getByTestId('delete-metametrics-data-button')).toBeInTheDocument();
+ expect(getAllByText('Delete MetaMetrics data')).toHaveLength(2);
+ expect(
+ getByText(
+ /This will delete historical MetaMetrics data associated with your use on this device. Your wallet and accounts will remain exactly as they are now after this data has been deleted. This process may take up to 30 days. View our/u,
+ ),
+ ).toBeInTheDocument();
+ });
+
+ it('should enable the data deletion button when metrics is opted in and metametrics id is available ', async () => {
+ const store = configureStore({});
+ const { getByRole, getByText } = renderWithProvider(
+
,
+ store,
+ );
+ expect(
+ getByRole('button', { name: 'Delete MetaMetrics data' }),
+ ).toBeEnabled();
+ expect(
+ getByText(
+ /This will delete historical MetaMetrics data associated with your use on this device. Your wallet and accounts will remain exactly as they are now after this data has been deleted. This process may take up to 30 days. View our/u,
+ ),
+ ).toBeInTheDocument();
+ });
+ it('should enable the data deletion button when page mounts after a deletion task is performed and more data is recoded after the deletion', async () => {
+ useSelectorMock.mockImplementation((selector) => {
+ if (selector === getParticipateInDuringDeletion) {
+ return true;
+ }
+ if (selector === getMetaMetricsDataDeletionStatus) {
+ return 'INITIALIZED';
+ }
+ if (selector === getMetaMetricsId) {
+ return 'fake-metrics-id';
+ }
+ return undefined;
+ });
+ const store = configureStore({});
+ const { getByRole, getByText } = renderWithProvider(
+
,
+ store,
+ );
+ expect(
+ getByRole('button', { name: 'Delete MetaMetrics data' }),
+ ).toBeEnabled();
+ expect(
+ getByText(
+ /This will delete historical MetaMetrics data associated with your use on this device. Your wallet and accounts will remain exactly as they are now after this data has been deleted. This process may take up to 30 days. View our/u,
+ ),
+ ).toBeInTheDocument();
+ });
+
+ // if user does not opt in to participate in metrics or for profile sync, metametricsId will not be created.
+ it('should disable the data deletion button when there is metametrics id not available', async () => {
+ useSelectorMock.mockImplementation((selector) => {
+ if (selector === getMetaMetricsId) {
+ return null;
+ }
+ return undefined;
+ });
+ const store = configureStore({});
+ const { getByRole, getByText } = renderWithProvider(
+
,
+ store,
+ );
+ expect(
+ getByRole('button', { name: 'Delete MetaMetrics data' }),
+ ).toBeDisabled();
+ expect(
+ getByText(
+ /This will delete historical MetaMetrics data associated with your use on this device. Your wallet and accounts will remain exactly as they are now after this data has been deleted. This process may take up to 30 days. View our/u,
+ ),
+ ).toBeInTheDocument();
+ expect(
+ getByText(
+ /Since you've never opted into MetaMetrics, there's no data to delete here./u,
+ ),
+ ).toBeInTheDocument();
+ });
+
+ // metaMetricsDataDeletionMarked is set to true right after the deletion is performed, it will rest to false when the page unmounts.
+ it('should disable the data deletion button when metaMetricsDataDeletionMarked is true', async () => {
+ useSelectorMock.mockImplementation((selector) => {
+ if (selector === isMetaMetricsDataDeletionMarked) {
+ return true;
+ }
+ if (selector === getMetaMetricsId) {
+ return 'fake-metrics-id';
+ }
+ if (selector === getParticipateInDuringDeletion) {
+ return true;
+ }
+ if (selector === getMetaMetricsDataDeletionStatus) {
+ return 'INITIALIZED';
+ }
+ if (selector === getMetaMetricsDataDeletionDate) {
+ return 1717779342113;
+ }
+ return undefined;
+ });
+ const store = configureStore({});
+ const { getByRole, getByText } = renderWithProvider(
+
,
+ store,
+ );
+ expect(
+ getByRole('button', { name: 'Delete MetaMetrics data' }),
+ ).toBeDisabled();
+ expect(
+ getByText(
+ /You initiated this action on 7\/06\/2024. This process can take up to 30 days. View the/u,
+ ),
+ ).toBeInTheDocument();
+ });
+
+ // particilapteInMetrics will be false before the deletion is performed, this way no further data will be recorded after deletion.
+ it('should disable the data deletion button after a deletion task is performed and no data is recoded after the deletion', async () => {
+ useSelectorMock.mockImplementation((selector) => {
+ if (selector === getParticipateInDuringDeletion) {
+ return false;
+ }
+ if (selector === getMetaMetricsId) {
+ return 'fake-metrics-id';
+ }
+ if (selector === getParticipateInDuringDeletion) {
+ return true;
+ }
+ if (selector === getMetaMetricsDataDeletionStatus) {
+ return 'INITIALIZED';
+ }
+ if (selector === getMetaMetricsDataDeletionDate) {
+ return 1717779342113;
+ }
+ return undefined;
+ });
+ const store = configureStore({});
+ const { getByRole, getByText } = renderWithProvider(
+
,
+ store,
+ );
+ expect(
+ getByRole('button', { name: 'Delete MetaMetrics data' }),
+ ).toBeDisabled();
+ expect(
+ getByText(
+ /You initiated this action on 7\/06\/2024. This process can take up to 30 days. View the/u,
+ ),
+ ).toBeInTheDocument();
+ });
+
+ it('should open the modal on the button click', () => {
+ const store = configureStore({});
+ const { getByRole } = renderWithProvider(
+
,
+ store,
+ );
+ const deleteButton = getByRole('button', {
+ name: 'Delete MetaMetrics data',
+ });
+ fireEvent.click(deleteButton);
+ expect(mockDispatch).toHaveBeenCalledWith(openDeleteMetaMetricsDataModal());
+ });
+});
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
new file mode 100644
index 000000000000..b2e9fd9a34cc
--- /dev/null
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
@@ -0,0 +1,135 @@
+import React, { useState } from 'react';
+import { useDispatch, useSelector } from 'react-redux';
+import { CONSENSYS_PRIVACY_LINK } from '../../../../../shared/lib/ui-utils';
+import ClearMetametricsData from '../../../../components/app/clear-metametrics-data';
+import {
+ Box,
+ ButtonPrimary,
+ Icon,
+ IconName,
+ IconSize,
+ Text,
+} from '../../../../components/component-library';
+import {
+ Display,
+ FlexDirection,
+ TextVariant,
+} from '../../../../helpers/constants/design-system';
+import { useI18nContext } from '../../../../hooks/useI18nContext';
+import {
+ getMetaMetricsDataDeletionDate,
+ getMetaMetricsDataDeletionStatus,
+ getMetaMetricsId,
+ getShowDataDeletionErrorModal,
+ getShowDeleteMetaMetricsDataModal,
+ getParticipateInDuringDeletion,
+ isMetaMetricsDataDeletionMarked,
+ getParticipateInMetaMetrics,
+} from '../../../../selectors';
+import { openDeleteMetaMetricsDataModal } from '../../../../ducks/app/app';
+import DataDeletionErrorModal from '../../../../components/app/data-deletion-error-modal';
+import { formatDate } from '../../../../helpers/utils/util';
+import { DeleteRegulationStatus } from '../../../../../shared/constants/metametrics';
+
+const DeleteMetaMetricsDataButton = () => {
+ const t = useI18nContext();
+ const dispatch = useDispatch();
+
+ const metaMetricsId = useSelector(getMetaMetricsId);
+ const metaMetricsDataDeletionStatus = useSelector(
+ getMetaMetricsDataDeletionStatus,
+ );
+ const metaMetricsDataDeletionDate = useSelector(
+ getMetaMetricsDataDeletionDate,
+ );
+ const formatedDate = formatDate(metaMetricsDataDeletionDate, 'd/MM/y');
+
+ const metaMetricsDataDeletionMarked = useSelector(
+ isMetaMetricsDataDeletionMarked,
+ );
+ const showDeleteMetaMetricsDataModal = useSelector(
+ getShowDeleteMetaMetricsDataModal,
+ );
+ const showDataDeletionErrorModal = useSelector(getShowDataDeletionErrorModal);
+ const participateInDuringDeletion: boolean = useSelector(
+ getParticipateInDuringDeletion,
+ );
+ const participateInMetaMetrics = useSelector(getParticipateInMetaMetrics);
+ const [hasMetricsRecordedAfterDeletion, setHasMetricsRecordedAfterDeletion] =
+ useState(participateInDuringDeletion);
+ if (!hasMetricsRecordedAfterDeletion && participateInMetaMetrics) {
+ setHasMetricsRecordedAfterDeletion(participateInMetaMetrics);
+ }
+
+ let dataDeletionButtonDisabled: boolean =
+ metaMetricsDataDeletionMarked || Boolean(!metaMetricsId);
+ if (!dataDeletionButtonDisabled && metaMetricsDataDeletionStatus) {
+ dataDeletionButtonDisabled =
+ [
+ DeleteRegulationStatus.initialized,
+ DeleteRegulationStatus.running,
+ DeleteRegulationStatus.finished,
+ ].includes(metaMetricsDataDeletionStatus) &&
+ !hasMetricsRecordedAfterDeletion;
+ }
+ const privacyPolicyLink = (
+
+ {t('privacyMsg')}
+
+ );
+ return (
+ <>
+
+
+
{t('deleteMetaMetricsData')}
+
+ {dataDeletionButtonDisabled && Boolean(metaMetricsId)
+ ? t('deleteMetaMetricsDataRequestedDescription', [
+ formatedDate,
+ privacyPolicyLink,
+ ])
+ : t('deleteMetaMetricsDataDescription', [privacyPolicyLink])}
+
+
+
+ {Boolean(!metaMetricsId) && (
+
+
+
+ {t('metaMetricsIdNotAvailableError')}
+
+
+ )}
+ {
+ dispatch(openDeleteMetaMetricsDataModal());
+ }}
+ disabled={dataDeletionButtonDisabled}
+ >
+ {t('deleteMetaMetricsData')}
+
+
+
+ {showDeleteMetaMetricsDataModal &&
}
+ {showDataDeletionErrorModal &&
}
+ >
+ );
+};
+
+export default DeleteMetaMetricsDataButton;
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-button/index.ts b/ui/pages/settings/security-tab/delete-metametrics-data-button/index.ts
new file mode 100644
index 000000000000..945f4d349ede
--- /dev/null
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-button/index.ts
@@ -0,0 +1 @@
+export { default } from './delete-metametrics-data-button';
From 5a83469c4f88cc344bb41fd163ec13a1bcf779f2 Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Fri, 12 Jul 2024 13:49:00 -0400
Subject: [PATCH 19/40] updating the state variable name
---
.../delete-metametrics-data-button.test.tsx | 13 +++++--------
.../delete-metametrics-data-button.tsx | 8 ++++----
ui/selectors/selectors.js | 4 ++--
3 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx
index ba78272adbaa..4abba75fecb9 100644
--- a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx
@@ -9,7 +9,7 @@ import {
getMetaMetricsDataDeletionDate,
getMetaMetricsDataDeletionStatus,
getMetaMetricsId,
- getParticipateInDuringDeletion,
+ getParticipateInMetricsDuringDeletion,
isMetaMetricsDataDeletionMarked,
} from '../../../../selectors';
import { openDeleteMetaMetricsDataModal } from '../../../../ducks/app/app';
@@ -35,7 +35,7 @@ describe('DeleteMetaMetricsDataButton', () => {
if (selector === getMetaMetricsId) {
return 'fake-metrics-id';
}
- if (selector === getParticipateInDuringDeletion) {
+ if (selector === getParticipateInMetricsDuringDeletion) {
return null;
}
if (selector === getMetaMetricsDataDeletionStatus) {
@@ -85,7 +85,7 @@ describe('DeleteMetaMetricsDataButton', () => {
});
it('should enable the data deletion button when page mounts after a deletion task is performed and more data is recoded after the deletion', async () => {
useSelectorMock.mockImplementation((selector) => {
- if (selector === getParticipateInDuringDeletion) {
+ if (selector === getParticipateInMetricsDuringDeletion) {
return true;
}
if (selector === getMetaMetricsDataDeletionStatus) {
@@ -148,7 +148,7 @@ describe('DeleteMetaMetricsDataButton', () => {
if (selector === getMetaMetricsId) {
return 'fake-metrics-id';
}
- if (selector === getParticipateInDuringDeletion) {
+ if (selector === getParticipateInMetricsDuringDeletion) {
return true;
}
if (selector === getMetaMetricsDataDeletionStatus) {
@@ -177,15 +177,12 @@ describe('DeleteMetaMetricsDataButton', () => {
// particilapteInMetrics will be false before the deletion is performed, this way no further data will be recorded after deletion.
it('should disable the data deletion button after a deletion task is performed and no data is recoded after the deletion', async () => {
useSelectorMock.mockImplementation((selector) => {
- if (selector === getParticipateInDuringDeletion) {
+ if (selector === getParticipateInMetricsDuringDeletion) {
return false;
}
if (selector === getMetaMetricsId) {
return 'fake-metrics-id';
}
- if (selector === getParticipateInDuringDeletion) {
- return true;
- }
if (selector === getMetaMetricsDataDeletionStatus) {
return 'INITIALIZED';
}
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
index b2e9fd9a34cc..77795f8c72a6 100644
--- a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
@@ -22,7 +22,7 @@ import {
getMetaMetricsId,
getShowDataDeletionErrorModal,
getShowDeleteMetaMetricsDataModal,
- getParticipateInDuringDeletion,
+ getParticipateInMetricsDuringDeletion,
isMetaMetricsDataDeletionMarked,
getParticipateInMetaMetrics,
} from '../../../../selectors';
@@ -51,12 +51,12 @@ const DeleteMetaMetricsDataButton = () => {
getShowDeleteMetaMetricsDataModal,
);
const showDataDeletionErrorModal = useSelector(getShowDataDeletionErrorModal);
- const participateInDuringDeletion: boolean = useSelector(
- getParticipateInDuringDeletion,
+ const participateInMetricsDuringDeletion: boolean = useSelector(
+ getParticipateInMetricsDuringDeletion,
);
const participateInMetaMetrics = useSelector(getParticipateInMetaMetrics);
const [hasMetricsRecordedAfterDeletion, setHasMetricsRecordedAfterDeletion] =
- useState(participateInDuringDeletion);
+ useState(participateInMetricsDuringDeletion);
if (!hasMetricsRecordedAfterDeletion && participateInMetaMetrics) {
setHasMetricsRecordedAfterDeletion(participateInMetaMetrics);
}
diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js
index 416240211e58..1a4f8f8fe5cc 100644
--- a/ui/selectors/selectors.js
+++ b/ui/selectors/selectors.js
@@ -2585,8 +2585,8 @@ export function isMetaMetricsDataDeletionMarked(state) {
return state.appState.metaMetricsDataDeletionMarked;
}
-export function getParticipateInDuringDeletion(state) {
- return state.metamask.participateInDuringDeletion;
+export function getParticipateInMetricsDuringDeletion(state) {
+ return state.metamask.participateInMetricsDuringDeletion;
}
/**
From 664661beec19415051dc06fb471a9efd00abbf43 Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Fri, 12 Jul 2024 16:52:18 -0400
Subject: [PATCH 20/40] updating privacy-snapshot
---
privacy-snapshot.json | 1 +
1 file changed, 1 insertion(+)
diff --git a/privacy-snapshot.json b/privacy-snapshot.json
index b8920724a597..3d1a5a0eeb36 100644
--- a/privacy-snapshot.json
+++ b/privacy-snapshot.json
@@ -33,6 +33,7 @@
"mainnet.infura.io",
"metamask.eth",
"metamask.github.io",
+ "metametrics.metamask.test",
"min-api.cryptocompare.com",
"nft.api.cx.metamask.io",
"oidc.api.cx.metamask.io",
From e6b24495448c46f12b8fccd2345db7a1a4694b1f Mon Sep 17 00:00:00 2001
From: seaona <54408225+seaona@users.noreply.github.com>
Date: Thu, 18 Jul 2024 18:33:27 +0200
Subject: [PATCH 21/40] fix: mitigate race condition and flakiness for delete
metametrics test (#25945)
---
test/e2e/tests/metrics/delete-metametrics-data.spec.ts | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
index 246043ae3caa..bcfa983b5b01 100644
--- a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
+++ b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
@@ -178,7 +178,11 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
await driver.findElement(rowLocators.deletMetaMetricsSettings);
await driver.clickElement(rowLocators.deleteMetaMetricsDataButton);
- await driver.clickElement(rowLocators.clearButton);
+
+ // there is a race condition, where we need to wait before clicking clear button otherwise an error is thrown in the background
+ // we cannot wait for a UI conditon, so we a delay to mitigate this until another solution is found
+ await driver.delay(3000);
+ await driver.clickElementAndWaitToDisappear(rowLocators.clearButton);
const deleteMetaMetricsDataButton = await driver.findElement(
rowLocators.deleteMetaMetricsDataButton,
@@ -202,6 +206,10 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
const deleteMetaMetricsDataButtonRefreshed = await driver.findElement(
rowLocators.deleteMetaMetricsDataButton,
);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ await (deleteMetaMetricsDataButtonRefreshed as any).waitForElementState(
+ 'disabled',
+ );
assert.equal(
await deleteMetaMetricsDataButtonRefreshed.isEnabled(),
false,
From c7a0c99dbd0cf448864ff85cfbb922987d674eb7 Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Thu, 18 Jul 2024 15:14:48 -0400
Subject: [PATCH 22/40] updating UI to use timestamp to track teh data
recording
---
.../clear-metametrics-data.tsx | 15 ++++---
ui/ducks/app/app.ts | 24 -----------
.../delete-metametrics-data-button.test.tsx | 40 ++++++-------------
.../delete-metametrics-data-button.tsx | 34 +++++-----------
.../security-tab/security-tab.component.js | 10 ++---
.../security-tab/security-tab.container.js | 10 ++---
.../security-tab/security-tab.test.js | 3 --
ui/selectors/metametrics.js | 3 ++
ui/selectors/selectors.js | 12 +-----
ui/store/actionConstants.ts | 4 --
10 files changed, 45 insertions(+), 110 deletions(-)
diff --git a/ui/components/app/clear-metametrics-data/clear-metametrics-data.tsx b/ui/components/app/clear-metametrics-data/clear-metametrics-data.tsx
index aa4df5086d06..222497facf30 100644
--- a/ui/components/app/clear-metametrics-data/clear-metametrics-data.tsx
+++ b/ui/components/app/clear-metametrics-data/clear-metametrics-data.tsx
@@ -2,7 +2,6 @@ import React, { useContext } from 'react';
import { useDispatch } from 'react-redux';
import {
hideDeleteMetaMetricsDataModal,
- markingMetaMetricsDataDeletion,
openDataDeletionErrorModal,
} from '../../../ducks/app/app';
import { useI18nContext } from '../../../hooks/useI18nContext';
@@ -45,11 +44,15 @@ export default function ClearMetaMetricsData() {
const deleteMetaMetricsData = async () => {
try {
await createMetaMetricsDataDeletionTask();
- dispatch(markingMetaMetricsDataDeletion());
- trackEvent({
- category: MetaMetricsEventCategory.Settings,
- event: MetaMetricsEventName.MetricsDataDeletionRequest,
- });
+ trackEvent(
+ {
+ category: MetaMetricsEventCategory.Settings,
+ event: MetaMetricsEventName.MetricsDataDeletionRequest,
+ },
+ {
+ excludeMetaMetricsId: true,
+ },
+ );
} catch (error: unknown) {
dispatch(openDataDeletionErrorModal());
} finally {
diff --git a/ui/ducks/app/app.ts b/ui/ducks/app/app.ts
index ccd384f39040..e6a7855ce7a5 100644
--- a/ui/ducks/app/app.ts
+++ b/ui/ducks/app/app.ts
@@ -102,7 +102,6 @@ type AppState = {
accountDetailsAddress: string;
showDeleteMetaMetricsDataModal: boolean;
showDataDeletionErrorModal: boolean;
- metaMetricsDataDeletionMarked: boolean;
snapsInstallPrivacyWarningShown: boolean;
isAddingNewNetwork: boolean;
isMultiRpcOnboarding: boolean;
@@ -190,7 +189,6 @@ const initialState: AppState = {
accountDetailsAddress: '',
showDeleteMetaMetricsDataModal: false,
showDataDeletionErrorModal: false,
- metaMetricsDataDeletionMarked: false,
snapsInstallPrivacyWarningShown: false,
isAddingNewNetwork: false,
isMultiRpcOnboarding: false,
@@ -634,16 +632,6 @@ export default function reduceApp(
...appState,
showDataDeletionErrorModal: false,
};
- case actionConstants.METAMETRICS_DATA_DELETION_MARKED:
- return {
- ...appState,
- metaMetricsDataDeletionMarked: true,
- };
- case actionConstants.METAMETRICS_DATA_DELETION_UNMARKED:
- return {
- ...appState,
- metaMetricsDataDeletionMarked: false,
- };
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
case actionConstants.SHOW_KEYRING_SNAP_REMOVAL_RESULT:
return {
@@ -777,15 +765,3 @@ export function hideDataDeletionErrorModal(): Action {
type: actionConstants.DATA_DELETION_ERROR_MODAL_CLOSE,
};
}
-
-export function markingMetaMetricsDataDeletion(): Action {
- return {
- type: actionConstants.METAMETRICS_DATA_DELETION_MARKED,
- };
-}
-
-export function unMarkingMetaMetricsDataDeletion(): Action {
- return {
- type: actionConstants.METAMETRICS_DATA_DELETION_UNMARKED,
- };
-}
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx
index 4abba75fecb9..d9eeb6cbf5cd 100644
--- a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx
@@ -2,15 +2,13 @@ import * as React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { fireEvent } from '@testing-library/react';
import configureStore from '../../../../store/store';
-// import mockState from '../../../../../test/data/mock-state.json';
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
import {
- getMetaMetricsDataDeletionDate,
+ getMetaMetricsDataDeletionTimestamp,
getMetaMetricsDataDeletionStatus,
getMetaMetricsId,
- getParticipateInMetricsDuringDeletion,
- isMetaMetricsDataDeletionMarked,
+ getLatestMetricsEventTimestamp,
} from '../../../../selectors';
import { openDeleteMetaMetricsDataModal } from '../../../../ducks/app/app';
import DeleteMetaMetricsDataButton from './delete-metametrics-data-button';
@@ -29,19 +27,13 @@ describe('DeleteMetaMetricsDataButton', () => {
beforeEach(() => {
useDispatchMock.mockReturnValue(mockDispatch);
useSelectorMock.mockImplementation((selector) => {
- if (selector === isMetaMetricsDataDeletionMarked) {
- return false;
- }
if (selector === getMetaMetricsId) {
return 'fake-metrics-id';
}
- if (selector === getParticipateInMetricsDuringDeletion) {
- return null;
- }
if (selector === getMetaMetricsDataDeletionStatus) {
return undefined;
}
- if (selector === getMetaMetricsDataDeletionDate) {
+ if (selector === getMetaMetricsDataDeletionTimestamp) {
return '';
}
@@ -85,9 +77,6 @@ describe('DeleteMetaMetricsDataButton', () => {
});
it('should enable the data deletion button when page mounts after a deletion task is performed and more data is recoded after the deletion', async () => {
useSelectorMock.mockImplementation((selector) => {
- if (selector === getParticipateInMetricsDuringDeletion) {
- return true;
- }
if (selector === getMetaMetricsDataDeletionStatus) {
return 'INITIALIZED';
}
@@ -139,24 +128,21 @@ describe('DeleteMetaMetricsDataButton', () => {
).toBeInTheDocument();
});
- // metaMetricsDataDeletionMarked is set to true right after the deletion is performed, it will rest to false when the page unmounts.
- it('should disable the data deletion button when metaMetricsDataDeletionMarked is true', async () => {
+ // particilapteInMetrics will be false before the deletion is performed, this way no further data will be recorded after deletion.
+ it('should disable the data deletion button after a deletion task is performed and no data is recoded after the deletion', async () => {
useSelectorMock.mockImplementation((selector) => {
- if (selector === isMetaMetricsDataDeletionMarked) {
- return true;
- }
if (selector === getMetaMetricsId) {
return 'fake-metrics-id';
}
- if (selector === getParticipateInMetricsDuringDeletion) {
- return true;
- }
if (selector === getMetaMetricsDataDeletionStatus) {
return 'INITIALIZED';
}
- if (selector === getMetaMetricsDataDeletionDate) {
+ if (selector === getMetaMetricsDataDeletionTimestamp) {
return 1717779342113;
}
+ if (selector === getLatestMetricsEventTimestamp) {
+ return 1717779342110;
+ }
return undefined;
});
const store = configureStore({});
@@ -177,18 +163,18 @@ describe('DeleteMetaMetricsDataButton', () => {
// particilapteInMetrics will be false before the deletion is performed, this way no further data will be recorded after deletion.
it('should disable the data deletion button after a deletion task is performed and no data is recoded after the deletion', async () => {
useSelectorMock.mockImplementation((selector) => {
- if (selector === getParticipateInMetricsDuringDeletion) {
- return false;
- }
if (selector === getMetaMetricsId) {
return 'fake-metrics-id';
}
if (selector === getMetaMetricsDataDeletionStatus) {
return 'INITIALIZED';
}
- if (selector === getMetaMetricsDataDeletionDate) {
+ if (selector === getMetaMetricsDataDeletionTimestamp) {
return 1717779342113;
}
+ if (selector === getLatestMetricsEventTimestamp) {
+ return 1717779342110;
+ }
return undefined;
});
const store = configureStore({});
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
index 77795f8c72a6..e2a67fbdc8e0 100644
--- a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from 'react';
+import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { CONSENSYS_PRIVACY_LINK } from '../../../../../shared/lib/ui-utils';
import ClearMetametricsData from '../../../../components/app/clear-metametrics-data';
@@ -17,14 +17,12 @@ import {
} from '../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import {
- getMetaMetricsDataDeletionDate,
+ getMetaMetricsDataDeletionTimestamp,
getMetaMetricsDataDeletionStatus,
getMetaMetricsId,
getShowDataDeletionErrorModal,
getShowDeleteMetaMetricsDataModal,
- getParticipateInMetricsDuringDeletion,
- isMetaMetricsDataDeletionMarked,
- getParticipateInMetaMetrics,
+ getLatestMetricsEventTimestamp,
} from '../../../../selectors';
import { openDeleteMetaMetricsDataModal } from '../../../../ducks/app/app';
import DataDeletionErrorModal from '../../../../components/app/data-deletion-error-modal';
@@ -36,33 +34,23 @@ const DeleteMetaMetricsDataButton = () => {
const dispatch = useDispatch();
const metaMetricsId = useSelector(getMetaMetricsId);
- const metaMetricsDataDeletionStatus = useSelector(
+ const metaMetricsDataDeletionStatus: DeleteRegulationStatus = useSelector(
getMetaMetricsDataDeletionStatus,
);
- const metaMetricsDataDeletionDate = useSelector(
- getMetaMetricsDataDeletionDate,
+ const metaMetricsDataDeletionTimestamp = useSelector(
+ getMetaMetricsDataDeletionTimestamp,
);
- const formatedDate = formatDate(metaMetricsDataDeletionDate, 'd/MM/y');
+ const formatedDate = formatDate(metaMetricsDataDeletionTimestamp, 'd/MM/y');
- const metaMetricsDataDeletionMarked = useSelector(
- isMetaMetricsDataDeletionMarked,
- );
const showDeleteMetaMetricsDataModal = useSelector(
getShowDeleteMetaMetricsDataModal,
);
const showDataDeletionErrorModal = useSelector(getShowDataDeletionErrorModal);
- const participateInMetricsDuringDeletion: boolean = useSelector(
- getParticipateInMetricsDuringDeletion,
+ const latestMetricsEventTimestamp = useSelector(
+ getLatestMetricsEventTimestamp,
);
- const participateInMetaMetrics = useSelector(getParticipateInMetaMetrics);
- const [hasMetricsRecordedAfterDeletion, setHasMetricsRecordedAfterDeletion] =
- useState(participateInMetricsDuringDeletion);
- if (!hasMetricsRecordedAfterDeletion && participateInMetaMetrics) {
- setHasMetricsRecordedAfterDeletion(participateInMetaMetrics);
- }
- let dataDeletionButtonDisabled: boolean =
- metaMetricsDataDeletionMarked || Boolean(!metaMetricsId);
+ let dataDeletionButtonDisabled = Boolean(!metaMetricsId);
if (!dataDeletionButtonDisabled && metaMetricsDataDeletionStatus) {
dataDeletionButtonDisabled =
[
@@ -70,7 +58,7 @@ const DeleteMetaMetricsDataButton = () => {
DeleteRegulationStatus.running,
DeleteRegulationStatus.finished,
].includes(metaMetricsDataDeletionStatus) &&
- !hasMetricsRecordedAfterDeletion;
+ metaMetricsDataDeletionTimestamp > latestMetricsEventTimestamp;
}
const privacyPolicyLink = (
{
@@ -82,6 +80,7 @@ const mapStateToProps = (state) => {
petnamesEnabled,
securityAlertsEnabled: getIsSecurityAlertsEnabled(state),
useTransactionSimulations: metamask.useTransactionSimulations,
+ metaMetricsDataDeletionId: getMetaMetricsDataDeletionId(state),
};
};
@@ -123,9 +122,6 @@ const mapDispatchToProps = (dispatch) => {
updateDataDeletionTaskStatus: () => {
return updateDataDeletionTaskStatus();
},
- unMarkingMetaMetricsDataDeletion: () => {
- return dispatch(unMarkingMetaMetricsDataDeletion());
- },
setSecurityAlertsEnabled: (value) => setSecurityAlertsEnabled(value),
};
};
diff --git a/ui/pages/settings/security-tab/security-tab.test.js b/ui/pages/settings/security-tab/security-tab.test.js
index ef962b56c641..5e31cfb68c57 100644
--- a/ui/pages/settings/security-tab/security-tab.test.js
+++ b/ui/pages/settings/security-tab/security-tab.test.js
@@ -43,9 +43,6 @@ jest.mock('../../../ducks/app/app.ts', () => {
openDeleteMetaMetricsDataModal: () => {
return mockOpenDeleteMetaMetricsDataModal;
},
- unMarkingMetaMetricsDataDeletion: () => {
- return jest.fn();
- },
};
});
diff --git a/ui/selectors/metametrics.js b/ui/selectors/metametrics.js
index c623e378c003..1b0a9dd603dd 100644
--- a/ui/selectors/metametrics.js
+++ b/ui/selectors/metametrics.js
@@ -8,6 +8,9 @@ export const getDataCollectionForMarketing = (state) =>
export const getParticipateInMetaMetrics = (state) =>
Boolean(state.metamask.participateInMetaMetrics);
+export const getLatestMetricsEventTimestamp = (state) =>
+ state.metamask.latestNonAnonymousEventTimestamp;
+
export const selectFragmentBySuccessEvent = createSelector(
selectFragments,
(_, fragmentOptions) => fragmentOptions,
diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js
index 1a4f8f8fe5cc..644924a41e3e 100644
--- a/ui/selectors/selectors.js
+++ b/ui/selectors/selectors.js
@@ -2573,22 +2573,14 @@ export function getMetaMetricsDataDeletionId(state) {
return state.metamask.metaMetricsDataDeletionId;
}
-export function getMetaMetricsDataDeletionDate(state) {
- return state.metamask.metaMetricsDataDeletionDate;
+export function getMetaMetricsDataDeletionTimestamp(state) {
+ return state.metamask.metaMetricsDataDeletionTimestamp;
}
export function getMetaMetricsDataDeletionStatus(state) {
return state.metamask.metaMetricsDataDeletionStatus;
}
-export function isMetaMetricsDataDeletionMarked(state) {
- return state.appState.metaMetricsDataDeletionMarked;
-}
-
-export function getParticipateInMetricsDuringDeletion(state) {
- return state.metamask.participateInMetricsDuringDeletion;
-}
-
/**
* To get all installed snaps with proper metadata
*
diff --git a/ui/store/actionConstants.ts b/ui/store/actionConstants.ts
index 5f5cb5e807c9..6e1e33d9531f 100644
--- a/ui/store/actionConstants.ts
+++ b/ui/store/actionConstants.ts
@@ -107,10 +107,6 @@ export const DATA_DELETION_ERROR_MODAL_OPEN =
'DELETE_METAMETRICS_DATA_ERROR_MODAL_OPEN';
export const DATA_DELETION_ERROR_MODAL_CLOSE =
'DELETE_METAMETRICS_DATA_ERROR_MODAL_CLOSE';
-export const METAMETRICS_DATA_DELETION_MARKED =
- 'METAMETRICS_DATA_DELETION_MARKED';
-export const METAMETRICS_DATA_DELETION_UNMARKED =
- 'METAMETRICS_DATA_DELETION_UNMARKED';
// locale
export const SET_CURRENT_LOCALE = 'SET_CURRENT_LOCALE';
From 7c838e44ca1dcb50c9133354232162fc87762594 Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Fri, 19 Jul 2024 16:16:44 -0400
Subject: [PATCH 23/40] fixing e2e
---
test/e2e/tests/metrics/delete-metametrics-data.spec.ts | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
index bcfa983b5b01..0be4d87bd1d0 100644
--- a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
+++ b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
@@ -114,7 +114,11 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
await driver.findElement(rowLocators.deletMetaMetricsSettings);
await driver.clickElement(rowLocators.deleteMetaMetricsDataButton);
- await driver.clickElement(rowLocators.clearButton);
+
+ // there is a race condition, where we need to wait before clicking clear button otherwise an error is thrown in the background
+ // we cannot wait for a UI conditon, so we a delay to mitigate this until another solution is found
+ await driver.delay(3000);
+ await driver.clickElementAndWaitToDisappear(rowLocators.clearButton);
const deleteMetaMetricsDataButton = await driver.findElement(
rowLocators.deleteMetaMetricsDataButton,
From 6b12b0e1e4f5fbdf3b0f0b81822adddcd2741858 Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Mon, 22 Jul 2024 17:05:59 -0400
Subject: [PATCH 24/40] updating the e2e
---
.../metrics/delete-metametrics-data.spec.ts | 20 ++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
index 0be4d87bd1d0..ba330ede95f3 100644
--- a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
+++ b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
@@ -141,12 +141,18 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
chain_id: '0x539',
environment_type: 'fullscreen',
});
- await driver.clickElement(rowLocators.experimentalSettings);
- await driver.clickElement(rowLocators.securityAndPrivacySettings);
- const deleteMetaMetricsDataButtonRefreshed = await driver.findElement(
- rowLocators.deleteMetaMetricsDataButton,
+ await driver.clickElementAndWaitToDisappear(
+ '.mm-box button[aria-label="Close"]',
);
+ await driver.clickElement(rowLocators.accountOptionsMenuButton);
+ await driver.clickElement(rowLocators.globalMenuSettingsButton);
+ await driver.clickElement(rowLocators.securityAndPrivacySettings);
+
+ const deleteMetaMetricsDataButtonRefreshed =
+ await driver.findClickableElement(
+ rowLocators.deleteMetaMetricsDataButton,
+ );
assert.equal(
await deleteMetaMetricsDataButtonRefreshed.isEnabled(),
true,
@@ -204,7 +210,11 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
const events = await getEventPayloads(driver, mockedEndpoints);
assert.equal(events.length, 2);
- await driver.clickElement(rowLocators.experimentalSettings);
+ await driver.clickElementAndWaitToDisappear(
+ '.mm-box button[aria-label="Close"]',
+ );
+ await driver.clickElement(rowLocators.accountOptionsMenuButton);
+ await driver.clickElement(rowLocators.globalMenuSettingsButton);
await driver.clickElement(rowLocators.securityAndPrivacySettings);
const deleteMetaMetricsDataButtonRefreshed = await driver.findElement(
From 751b2b955aa415e1d86476a81fe17706caeaa0e4 Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Tue, 20 Aug 2024 15:06:07 -0400
Subject: [PATCH 25/40] renaming rowLocator to selectors
---
.../metrics/delete-metametrics-data.spec.ts | 56 +++++++++----------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
index ba330ede95f3..ee1d8fb07023 100644
--- a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
+++ b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
@@ -10,7 +10,7 @@ import {
import FixtureBuilder from '../../fixture-builder';
import { Driver } from '../../webdriver/driver';
-const rowLocators = {
+const selectors = {
accountOptionsMenuButton: '[data-testid="account-options-menu-button"]',
globalMenuSettingsButton: '[data-testid="global-menu-settings"]',
securityAndPrivacySettings: { text: 'Security & privacy', tag: 'div' },
@@ -108,20 +108,20 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
}) => {
await unlockWallet(driver);
- await driver.clickElement(rowLocators.accountOptionsMenuButton);
- await driver.clickElement(rowLocators.globalMenuSettingsButton);
- await driver.clickElement(rowLocators.securityAndPrivacySettings);
+ await driver.clickElement(selectors.accountOptionsMenuButton);
+ await driver.clickElement(selectors.globalMenuSettingsButton);
+ await driver.clickElement(selectors.securityAndPrivacySettings);
- await driver.findElement(rowLocators.deletMetaMetricsSettings);
- await driver.clickElement(rowLocators.deleteMetaMetricsDataButton);
+ await driver.findElement(selectors.deletMetaMetricsSettings);
+ await driver.clickElement(selectors.deleteMetaMetricsDataButton);
// there is a race condition, where we need to wait before clicking clear button otherwise an error is thrown in the background
// we cannot wait for a UI conditon, so we a delay to mitigate this until another solution is found
await driver.delay(3000);
- await driver.clickElementAndWaitToDisappear(rowLocators.clearButton);
+ await driver.clickElementAndWaitToDisappear(selectors.clearButton);
const deleteMetaMetricsDataButton = await driver.findElement(
- rowLocators.deleteMetaMetricsDataButton,
+ selectors.deleteMetaMetricsDataButton,
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await (deleteMetaMetricsDataButton as any).waitForElementState(
@@ -145,13 +145,13 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
await driver.clickElementAndWaitToDisappear(
'.mm-box button[aria-label="Close"]',
);
- await driver.clickElement(rowLocators.accountOptionsMenuButton);
- await driver.clickElement(rowLocators.globalMenuSettingsButton);
- await driver.clickElement(rowLocators.securityAndPrivacySettings);
+ await driver.clickElement(selectors.accountOptionsMenuButton);
+ await driver.clickElement(selectors.globalMenuSettingsButton);
+ await driver.clickElement(selectors.securityAndPrivacySettings);
const deleteMetaMetricsDataButtonRefreshed =
await driver.findClickableElement(
- rowLocators.deleteMetaMetricsDataButton,
+ selectors.deleteMetaMetricsDataButton,
);
assert.equal(
await deleteMetaMetricsDataButtonRefreshed.isEnabled(),
@@ -182,20 +182,20 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
}) => {
await unlockWallet(driver);
- await driver.clickElement(rowLocators.accountOptionsMenuButton);
- await driver.clickElement(rowLocators.globalMenuSettingsButton);
- await driver.clickElement(rowLocators.securityAndPrivacySettings);
+ await driver.clickElement(selectors.accountOptionsMenuButton);
+ await driver.clickElement(selectors.globalMenuSettingsButton);
+ await driver.clickElement(selectors.securityAndPrivacySettings);
- await driver.findElement(rowLocators.deletMetaMetricsSettings);
- await driver.clickElement(rowLocators.deleteMetaMetricsDataButton);
+ await driver.findElement(selectors.deletMetaMetricsSettings);
+ await driver.clickElement(selectors.deleteMetaMetricsDataButton);
// there is a race condition, where we need to wait before clicking clear button otherwise an error is thrown in the background
// we cannot wait for a UI conditon, so we a delay to mitigate this until another solution is found
await driver.delay(3000);
- await driver.clickElementAndWaitToDisappear(rowLocators.clearButton);
+ await driver.clickElementAndWaitToDisappear(selectors.clearButton);
const deleteMetaMetricsDataButton = await driver.findElement(
- rowLocators.deleteMetaMetricsDataButton,
+ selectors.deleteMetaMetricsDataButton,
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await (deleteMetaMetricsDataButton as any).waitForElementState(
@@ -213,12 +213,12 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
await driver.clickElementAndWaitToDisappear(
'.mm-box button[aria-label="Close"]',
);
- await driver.clickElement(rowLocators.accountOptionsMenuButton);
- await driver.clickElement(rowLocators.globalMenuSettingsButton);
- await driver.clickElement(rowLocators.securityAndPrivacySettings);
+ await driver.clickElement(selectors.accountOptionsMenuButton);
+ await driver.clickElement(selectors.globalMenuSettingsButton);
+ await driver.clickElement(selectors.securityAndPrivacySettings);
const deleteMetaMetricsDataButtonRefreshed = await driver.findElement(
- rowLocators.deleteMetaMetricsDataButton,
+ selectors.deleteMetaMetricsDataButton,
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await (deleteMetaMetricsDataButtonRefreshed as any).waitForElementState(
@@ -243,13 +243,13 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
- await driver.clickElement(rowLocators.accountOptionsMenuButton);
- await driver.clickElement(rowLocators.globalMenuSettingsButton);
- await driver.clickElement(rowLocators.securityAndPrivacySettings);
- await driver.findElement(rowLocators.deletMetaMetricsSettings);
+ await driver.clickElement(selectors.accountOptionsMenuButton);
+ await driver.clickElement(selectors.globalMenuSettingsButton);
+ await driver.clickElement(selectors.securityAndPrivacySettings);
+ await driver.findElement(selectors.deletMetaMetricsSettings);
const deleteMetaMetricsDataButton = await driver.findElement(
- rowLocators.deleteMetaMetricsDataButton,
+ selectors.deleteMetaMetricsDataButton,
);
assert.equal(
await deleteMetaMetricsDataButton.isEnabled(),
From d854e426dc9d78426c8a5ab582b2e7444b5206da Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Tue, 20 Aug 2024 22:02:40 -0400
Subject: [PATCH 26/40] updaing settings constant and fixing e2e
---
.../metrics/delete-metametrics-data.spec.ts | 23 ++++++++++---------
ui/helpers/constants/settings.js | 7 ++++++
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
index ee1d8fb07023..b2ae5b331cb3 100644
--- a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
+++ b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
@@ -1,5 +1,5 @@
import { strict as assert } from 'assert';
-import { Mockttp } from 'mockttp';
+import { MockedEndpoint, Mockttp } from 'mockttp';
import { Suite } from 'mocha';
import {
defaultGanacheOptions,
@@ -9,6 +9,7 @@ import {
} from '../../helpers';
import FixtureBuilder from '../../fixture-builder';
import { Driver } from '../../webdriver/driver';
+import { TestSuiteArguments } from '../confirmations/transactions/shared';
const selectors = {
accountOptionsMenuButton: '[data-testid="account-options-menu-button"]',
@@ -102,10 +103,7 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
async ({
driver,
mockedEndpoint: mockedEndpoints,
- }: {
- driver: Driver;
- mockedEndpoint: Mockttp;
- }) => {
+ }: TestSuiteArguments) => {
await unlockWallet(driver);
await driver.clickElement(selectors.accountOptionsMenuButton);
@@ -133,7 +131,10 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
'Delete MetaMetrics data button is disabled',
);
- const events = await getEventPayloads(driver, mockedEndpoints);
+ const events = await getEventPayloads(
+ driver,
+ mockedEndpoints as MockedEndpoint[],
+ );
assert.equal(events.length, 3);
assert.deepStrictEqual(events[0].properties, {
category: 'Settings',
@@ -176,10 +177,7 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
async ({
driver,
mockedEndpoint: mockedEndpoints,
- }: {
- driver: Driver;
- mockedEndpoint: Mockttp;
- }) => {
+ }: TestSuiteArguments) => {
await unlockWallet(driver);
await driver.clickElement(selectors.accountOptionsMenuButton);
@@ -207,7 +205,10 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
'Delete MetaMetrics data button is disabled',
);
- const events = await getEventPayloads(driver, mockedEndpoints);
+ const events = await getEventPayloads(
+ driver,
+ mockedEndpoints as MockedEndpoint[],
+ );
assert.equal(events.length, 2);
await driver.clickElementAndWaitToDisappear(
diff --git a/ui/helpers/constants/settings.js b/ui/helpers/constants/settings.js
index 569999f8900e..89cca83f27cf 100644
--- a/ui/helpers/constants/settings.js
+++ b/ui/helpers/constants/settings.js
@@ -324,6 +324,13 @@ const SETTINGS_CONSTANTS = [
route: `${SECURITY_ROUTE}#dataCollectionForMarketing`,
icon: 'fa fa-lock',
},
+ {
+ tabMessage: (t) => t('securityAndPrivacy'),
+ sectionMessage: (t) => t('deleteMetaMetricsData'),
+ descriptionMessage: (t) => t('deleteMetaMetricsDataDescription'),
+ route: `${SECURITY_ROUTE}#delete-metametrics-data`,
+ icon: 'fa fa-lock',
+ },
{
tabMessage: (t) => t('alerts'),
sectionMessage: (t) => t('alertSettingsUnconnectedAccount'),
From 4931f26ce39234f3e36a84efe007cc37a51b9626 Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Thu, 29 Aug 2024 15:32:31 -0400
Subject: [PATCH 27/40] fixing e2e
---
privacy-snapshot.json | 1 +
test/e2e/tests/metrics/delete-metametrics-data.spec.ts | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/privacy-snapshot.json b/privacy-snapshot.json
index 3d1a5a0eeb36..2516654f1803 100644
--- a/privacy-snapshot.json
+++ b/privacy-snapshot.json
@@ -43,6 +43,7 @@
"portfolio.metamask.io",
"price.api.cx.metamask.io",
"proxy.api.cx.metamask.io",
+ "proxy.dev-api.cx.metamask.io",
"raw.githubusercontent.com",
"registry.npmjs.org",
"responsive-rpc.test",
diff --git a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
index b2ae5b331cb3..32adb55ac27b 100644
--- a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
+++ b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
@@ -135,7 +135,7 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
driver,
mockedEndpoints as MockedEndpoint[],
);
- assert.equal(events.length, 3);
+ assert.equal(events.length, 1);
assert.deepStrictEqual(events[0].properties, {
category: 'Settings',
locale: 'en',
@@ -209,7 +209,7 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
driver,
mockedEndpoints as MockedEndpoint[],
);
- assert.equal(events.length, 2);
+ assert.equal(events.length, 0);
await driver.clickElementAndWaitToDisappear(
'.mm-box button[aria-label="Close"]',
From ec16861e52aebd3236c6203b61c66cdccb910f2d Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Thu, 29 Aug 2024 16:52:55 -0400
Subject: [PATCH 28/40] Update delete-metametrics-data.spec.ts
---
test/e2e/tests/metrics/delete-metametrics-data.spec.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
index 32adb55ac27b..b2ae5b331cb3 100644
--- a/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
+++ b/test/e2e/tests/metrics/delete-metametrics-data.spec.ts
@@ -135,7 +135,7 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
driver,
mockedEndpoints as MockedEndpoint[],
);
- assert.equal(events.length, 1);
+ assert.equal(events.length, 3);
assert.deepStrictEqual(events[0].properties, {
category: 'Settings',
locale: 'en',
@@ -209,7 +209,7 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
driver,
mockedEndpoints as MockedEndpoint[],
);
- assert.equal(events.length, 0);
+ assert.equal(events.length, 2);
await driver.clickElementAndWaitToDisappear(
'.mm-box button[aria-label="Close"]',
From d67c2f750c7089fccd17ec2121367a5e3b153f21 Mon Sep 17 00:00:00 2001
From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com>
Date: Thu, 5 Sep 2024 14:02:14 -0400
Subject: [PATCH 29/40] fixing settings search
---
.../delete-metametrics-data-button.tsx | 9 ++++++++-
ui/pages/settings/security-tab/security-tab.component.js | 4 ++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
index e2a67fbdc8e0..68285775ebff 100644
--- a/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
+++ b/ui/pages/settings/security-tab/delete-metametrics-data-button/delete-metametrics-data-button.tsx
@@ -8,6 +8,7 @@ import {
Icon,
IconName,
IconSize,
+ PolymorphicRef,
Text,
} from '../../../../components/component-library';
import {
@@ -29,7 +30,12 @@ import DataDeletionErrorModal from '../../../../components/app/data-deletion-err
import { formatDate } from '../../../../helpers/utils/util';
import { DeleteRegulationStatus } from '../../../../../shared/constants/metametrics';
-const DeleteMetaMetricsDataButton = () => {
+const DeleteMetaMetricsDataButton = ({
+ wrapperRef,
+}: {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ wrapperRef?: PolymorphicRef;
+}) => {
const t = useI18nContext();
const dispatch = useDispatch();
@@ -73,6 +79,7 @@ const DeleteMetaMetricsDataButton = () => {
return (
<>
{this.renderDataCollectionForMarketing()}
-
+