diff --git a/app/scripts/controller-init/profile-metrics-controller-init.ts b/app/scripts/controller-init/profile-metrics-controller-init.ts index 07b73c57502b..833936f170d4 100644 --- a/app/scripts/controller-init/profile-metrics-controller-init.ts +++ b/app/scripts/controller-init/profile-metrics-controller-init.ts @@ -24,9 +24,12 @@ export const ProfileMetricsControllerInit: ControllerInitFunction< 'RemoteFeatureFlagController', ); const metaMetricsController = getController('MetaMetricsController'); + const appStateController = getController('AppStateController'); const assertUserOptedIn = () => remoteFeatureFlagController.state.remoteFeatureFlags.extensionUxPna25 === - true && metaMetricsController.state.participateInMetaMetrics === true; + true && + appStateController.state.pna25Acknowledged === true && + metaMetricsController.state.participateInMetaMetrics === true; const controller = new ProfileMetricsController({ messenger: controllerMessenger, diff --git a/test/e2e/tests/profile-metrics/profile-metrics.spec.ts b/test/e2e/tests/profile-metrics/profile-metrics.spec.ts index 5a8cacae803f..7937b5ace423 100644 --- a/test/e2e/tests/profile-metrics/profile-metrics.spec.ts +++ b/test/e2e/tests/profile-metrics/profile-metrics.spec.ts @@ -77,7 +77,7 @@ async function waitForEndpointToBeCalled( } describe('Profile Metrics', function () { - describe('when MetaMetrics is enabled and the feature flag is on', function () { + describe('when MetaMetrics is enabled, the feature flag is on, and the user acknowledged the privacy change', function () { it('sends exising accounts to the API on wallet unlock after activating MetaMetrics', async function () { await withFixtures( { @@ -85,6 +85,9 @@ describe('Profile Metrics', function () { .withMetaMetricsController({ participateInMetaMetrics: true, }) + .withAppStateController({ + pna25Acknowledged: true, + }) .build(), testSpecificMock: async (server: Mockttp) => [ await mockAuthService(server), @@ -121,6 +124,9 @@ describe('Profile Metrics', function () { .withMetaMetricsController({ participateInMetaMetrics: true, }) + .withAppStateController({ + pna25Acknowledged: true, + }) .build(), testSpecificMock: async (server: Mockttp) => [ await mockAuthService(server), @@ -159,77 +165,67 @@ describe('Profile Metrics', function () { }); }); - describe('when MetaMetrics is disabled or the feature flag is off', function () { - it('does not send existing accounts to the API on wallet unlock if MetaMetrics is disabled', async function () { - await withFixtures( - { - fixtures: new FixtureBuilder() - .withMetaMetricsController({ - participateInMetaMetrics: false, - }) - .build(), - testSpecificMock: async (server: Mockttp) => [ - await mockAuthService(server), - await mockSendFeatureFlag(true)(server), - ], - title: this.test?.fullTitle(), - }, - async ({ - driver, - mockedEndpoint, - }: { - driver: Driver; - mockedEndpoint: MockedEndpoint[]; - }) => { - await loginWithBalanceValidation(driver); - - await driver.delay(5000); - - const [authCall] = mockedEndpoint; - const requests = await authCall.getSeenRequests(); - assert.equal( - requests.length, - 0, - 'Expected no requests to the auth API.', + [ + { + title: 'when MetaMetrics is disabled', + participateInMetaMetrics: false, + featureFlag: true, + pna25Acknowledged: true, + }, + { + title: 'when the relevant feature flag is off', + participateInMetaMetrics: true, + featureFlag: false, + pna25Acknowledged: true, + }, + { + title: 'when the user has not acknowledged the privacy change', + participateInMetaMetrics: true, + featureFlag: true, + pna25Acknowledged: false, + }, + ].forEach( + ({ title, participateInMetaMetrics, featureFlag, pna25Acknowledged }) => { + describe(title, function () { + it('does not send existing accounts to the API on wallet unlock', async function () { + await withFixtures( + { + fixtures: new FixtureBuilder() + .withMetaMetricsController({ + participateInMetaMetrics, + }) + .withAppStateController({ + pna25Acknowledged, + }) + .build(), + testSpecificMock: async (server: Mockttp) => [ + await mockAuthService(server), + await mockSendFeatureFlag(featureFlag)(server), + ], + title: this.test?.fullTitle(), + }, + async ({ + driver, + mockedEndpoint, + }: { + driver: Driver; + mockedEndpoint: MockedEndpoint[]; + }) => { + await loginWithBalanceValidation(driver); + + await driver.delay(5000); + + const [authCall] = mockedEndpoint; + const requests = await authCall.getSeenRequests(); + assert.equal( + requests.length, + 0, + 'Expected no requests to the auth API.', + ); + }, ); - }, - ); - }); - - it('does not send existing accounts to the API on wallet unlock if feature flag is disabled', async function () { - await withFixtures( - { - fixtures: new FixtureBuilder() - .withMetaMetricsController({ - participateInMetaMetrics: true, - }) - .build(), - testSpecificMock: async (server: Mockttp) => [ - await mockAuthService(server), - await mockSendFeatureFlag(false)(server), - ], - title: this.test?.fullTitle(), - }, - async ({ - driver, - mockedEndpoint, - }: { - driver: Driver; - mockedEndpoint: MockedEndpoint[]; - }) => { - await loginWithBalanceValidation(driver); - - await driver.delay(5000); - - const [authCall] = mockedEndpoint; - const requests = await authCall.getSeenRequests(); - assert.equal( - requests.length, - 0, - 'Expected no requests to the auth API.', - ); - }, - ); - }); - }); + }); + }); + }, + ); });