Skip to content

Commit 9e3cb84

Browse files
revert: remove feature-flags to user traits tracking (PR MetaMask#24178) (MetaMask#24317)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This reverts the changes from PR MetaMask#24178 that added automatic tracking of remote feature flags to user traits via addTraitsToUser. Automatic Github revert not available for this PR. Reverted changes: - Removed useEffect hook that called addTraitsToUser with rawFeatureFlags - Removed useMetrics import and addTraitsToUser usage - Removed related unit tests for feature flag user traits tracking ## Related Reverts MetaMask#24178 ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Reverts MetaMask#24178 ## **Manual testing steps** Identify calls should be sent to Segment server again. ## **Screenshots/Recordings** NA ### **Before** NA ### **After** NA ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Reverts automatic syncing of remote feature flags to user traits. > > - Removes `useMetrics` import and the `useEffect` that called `addTraitsToUser(rawFeatureFlags)` in `FeatureFlagOverrideContext.tsx` > - Deletes related unit tests and mocks in `FeatureFlagOverrideContext.test.tsx` for bulk/add-on-change trait updates > - Keeps feature flag override functionality (set/remove/clear) intact > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 27ec9cd. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 3af9925 commit 9e3cb84

2 files changed

Lines changed: 1 addition & 125 deletions

File tree

app/contexts/FeatureFlagOverrideContext.test.tsx

Lines changed: 1 addition & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import React from 'react';
2-
import {
3-
renderHook,
4-
act,
5-
render,
6-
screen,
7-
waitFor,
8-
} from '@testing-library/react-native';
2+
import { renderHook, act, render, screen } from '@testing-library/react-native';
93
import { useSelector } from 'react-redux';
104
import { Text } from 'react-native';
115
import {
@@ -54,15 +48,6 @@ jest.mock('../util/feature-flags', () => ({
5448
getFeatureFlagType: jest.fn(),
5549
}));
5650

57-
// Mock useMetrics hook
58-
const mockAddTraitsToUser = jest.fn();
59-
jest.mock('../components/hooks/useMetrics/useMetrics', () => ({
60-
__esModule: true,
61-
default: jest.fn(() => ({
62-
addTraitsToUser: mockAddTraitsToUser,
63-
})),
64-
}));
65-
6651
describe('FeatureFlagOverrideContext', () => {
6752
let mockUseSelector: jest.MockedFunction<typeof useSelector>;
6853
let mockGetFeatureFlagType: jest.MockedFunction<typeof getFeatureFlagType>;
@@ -72,7 +57,6 @@ describe('FeatureFlagOverrideContext', () => {
7257

7358
beforeEach(() => {
7459
jest.clearAllMocks();
75-
mockAddTraitsToUser.mockClear();
7660
mockSetFlagOverride.mockClear();
7761
mockRemoveFlagOverride.mockClear();
7862
mockClearAllFlagOverrides.mockClear();
@@ -729,102 +713,4 @@ describe('FeatureFlagOverrideContext', () => {
729713
expect(result.current.hasOverride('')).toBe(true);
730714
});
731715
});
732-
733-
describe('Remote Feature Flag Change Tracking', () => {
734-
it('adds all feature flags to user traits in bulk when received', async () => {
735-
const mockFlags = {
736-
booleanFlag: true,
737-
stringFlag: 'variant_a',
738-
numberFlag: 42,
739-
};
740-
mockUseSelector.mockReturnValue(mockFlags);
741-
742-
renderHook(() => useFeatureFlagOverride(), {
743-
wrapper: createWrapper,
744-
});
745-
746-
await waitFor(() => {
747-
expect(mockAddTraitsToUser).toHaveBeenCalledWith({
748-
booleanFlag: true,
749-
stringFlag: 'variant_a',
750-
numberFlag: 42,
751-
});
752-
});
753-
});
754-
755-
it('adds all feature flags to user traits in bulk when flags change', async () => {
756-
const initialFlags = { flag1: true, flag2: 'variant_a' };
757-
mockUseSelector.mockReturnValue(initialFlags);
758-
759-
const { rerender } = renderHook(() => useFeatureFlagOverride(), {
760-
wrapper: createWrapper,
761-
});
762-
763-
mockAddTraitsToUser.mockClear();
764-
765-
const updatedFlags = { flag1: false, flag2: 'variant_b', newFlag: 100 };
766-
mockUseSelector.mockReturnValue(updatedFlags);
767-
768-
rerender(null);
769-
770-
await waitFor(() => {
771-
expect(mockAddTraitsToUser).toHaveBeenCalledWith({
772-
flag1: false,
773-
flag2: 'variant_b',
774-
newFlag: 100,
775-
});
776-
});
777-
});
778-
779-
it('does not call addTraitsToUser when no feature flags exist', async () => {
780-
mockUseSelector.mockReturnValue({});
781-
782-
renderHook(() => useFeatureFlagOverride(), {
783-
wrapper: createWrapper,
784-
});
785-
786-
await waitFor(
787-
() => {
788-
expect(mockAddTraitsToUser).not.toHaveBeenCalled();
789-
},
790-
{ timeout: 200 },
791-
);
792-
});
793-
794-
it('sends user traits in a single bulk call, not per-flag', async () => {
795-
const mockFlags = { flag1: true, flag2: 'variant', flag3: 123 };
796-
mockUseSelector.mockReturnValue(mockFlags);
797-
798-
renderHook(() => useFeatureFlagOverride(), {
799-
wrapper: createWrapper,
800-
});
801-
802-
await waitFor(() => {
803-
// Should be called exactly once with all flags
804-
expect(mockAddTraitsToUser).toHaveBeenCalledTimes(1);
805-
expect(mockAddTraitsToUser).toHaveBeenCalledWith({
806-
flag1: true,
807-
flag2: 'variant',
808-
flag3: 123,
809-
});
810-
});
811-
});
812-
});
813-
814-
describe('Bulk Traits on Mount', () => {
815-
it('calls addTraitsToUser in bulk on mount with all feature flags', () => {
816-
const mockFlags = { stringFlag: 'test', boolFlag: true };
817-
mockUseSelector.mockReturnValue(mockFlags);
818-
819-
renderHook(() => useFeatureFlagOverride(), {
820-
wrapper: createWrapper,
821-
});
822-
823-
// useEffect sends all flags in bulk on mount
824-
expect(mockAddTraitsToUser).toHaveBeenCalledWith({
825-
stringFlag: 'test',
826-
boolFlag: true,
827-
});
828-
});
829-
});
830716
});

app/contexts/FeatureFlagOverrideContext.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import React, {
44
useCallback,
55
ReactNode,
66
useMemo,
7-
useEffect,
87
} from 'react';
98
import { useSelector } from 'react-redux';
109
import {
@@ -13,7 +12,6 @@ import {
1312
selectRawFeatureFlags,
1413
} from '../selectors/featureFlagController';
1514
import { FeatureFlagInfo, getFeatureFlagType } from '../util/feature-flags';
16-
import useMetrics from '../components/hooks/useMetrics/useMetrics';
1715
import Engine from '../core/Engine';
1816
import type { Json } from '@metamask/utils';
1917

@@ -44,21 +42,13 @@ interface FeatureFlagOverrideProviderProps {
4442
export const FeatureFlagOverrideProvider: React.FC<
4543
FeatureFlagOverrideProviderProps
4644
> = ({ children }) => {
47-
const { addTraitsToUser } = useMetrics();
4845
// Get the initial feature flags from Redux
4946
const featureFlagsWithOverrides = useSelector(selectRemoteFeatureFlags);
5047
const rawFeatureFlags = useSelector(selectRawFeatureFlags);
5148

5249
// Get overrides from controller state via Redux
5350
const overrides = useSelector(selectLocalOverrides);
5451

55-
// Track remote feature flags and add all flags to user traits in bulk
56-
useEffect(() => {
57-
if (rawFeatureFlags && Object.keys(rawFeatureFlags).length > 0) {
58-
addTraitsToUser(rawFeatureFlags);
59-
}
60-
}, [rawFeatureFlags, addTraitsToUser]);
61-
6252
const setOverride = useCallback((key: string, value: unknown) => {
6353
Engine.context?.RemoteFeatureFlagController?.setFlagOverride(
6454
key,

0 commit comments

Comments
 (0)