Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/constants/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum FeatureFlagNames {
tokenDetailsV2Buttons = 'tokenDetailsV2Buttons',
tokenDetailsV2ButtonLayout = 'tokenDetailsV2ButtonLayout',
complianceEnabled = 'complianceEnabled',
legacyIosGoogleConfigEnabled = 'legacyIosGoogleConfigEnabled',
}

export const DEFAULT_FEATURE_FLAG_VALUES: Partial<
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
DEFAULT_LEGACY_IOS_GOOGLE_CONFIG_ENABLED,
selectLegacyIosGoogleConfigEnabled,
} from '.';
import { FeatureFlagNames } from '../../../constants/featureFlags';

describe('Legacy iOS Google Config Feature Flag Selector', () => {
const originalEnv = process.env.MM_LEGACY_IOS_GOOGLE_CONFIG_ENABLED;

beforeEach(() => {
delete process.env.MM_LEGACY_IOS_GOOGLE_CONFIG_ENABLED;
});

afterAll(() => {
if (originalEnv === undefined) {
delete process.env.MM_LEGACY_IOS_GOOGLE_CONFIG_ENABLED;
return;
}

process.env.MM_LEGACY_IOS_GOOGLE_CONFIG_ENABLED = originalEnv;
});

it('returns the default value when the remote flag is missing', () => {
const result = selectLegacyIosGoogleConfigEnabled.resultFunc({});

expect(result).toBe(DEFAULT_LEGACY_IOS_GOOGLE_CONFIG_ENABLED);
});

it('returns the remote flag value when present', () => {
const result = selectLegacyIosGoogleConfigEnabled.resultFunc({
[FeatureFlagNames.legacyIosGoogleConfigEnabled]: false,
});

expect(result).toBe(false);
});

it('allows the local env var to force enable the legacy config', () => {
process.env.MM_LEGACY_IOS_GOOGLE_CONFIG_ENABLED = 'true';

const result = selectLegacyIosGoogleConfigEnabled.resultFunc({
[FeatureFlagNames.legacyIosGoogleConfigEnabled]: false,
});

expect(result).toBe(true);
});

it('allows the local env var to force disable the legacy config', () => {
process.env.MM_LEGACY_IOS_GOOGLE_CONFIG_ENABLED = 'false';

const result = selectLegacyIosGoogleConfigEnabled.resultFunc({
[FeatureFlagNames.legacyIosGoogleConfigEnabled]: true,
});

expect(result).toBe(false);
});
});
26 changes: 26 additions & 0 deletions app/selectors/featureFlagController/legacyIosGoogleConfig/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { hasProperty } from '@metamask/utils';
import { createSelector } from 'reselect';
import { FeatureFlagNames } from '../../../constants/featureFlags';
import { getFeatureFlagValue } from '../env';
import { selectRemoteFeatureFlags } from '..';

export const DEFAULT_LEGACY_IOS_GOOGLE_CONFIG_ENABLED = true;

export const selectLegacyIosGoogleConfigEnabled = createSelector(
selectRemoteFeatureFlags,
(remoteFeatureFlags) => {
const remoteValue = hasProperty(
remoteFeatureFlags,
FeatureFlagNames.legacyIosGoogleConfigEnabled,
)
? Boolean(
remoteFeatureFlags[FeatureFlagNames.legacyIosGoogleConfigEnabled],
)
: DEFAULT_LEGACY_IOS_GOOGLE_CONFIG_ENABLED;
return getFeatureFlagValue(
// Use direct env access so Babel can inline this value in app builds.
process.env.MM_LEGACY_IOS_GOOGLE_CONFIG_ENABLED,
remoteValue,
);
},
);
2 changes: 2 additions & 0 deletions babel.config.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const newOverrides = [
'app/components/UI/Ramp/hooks/useRampTokens.test.ts',
'app/components/Views/confirmations/hooks/pay/useTransactionPayWithdraw.ts',
'app/components/Views/confirmations/hooks/pay/useTransactionPayWithdraw.test.ts',
'app/selectors/featureFlagController/legacyIosGoogleConfig/index.ts',
'app/selectors/featureFlagController/legacyIosGoogleConfig/index.test.ts',
'app/util/environment.ts',
'app/util/environment.test.ts',
'app/core/Engine/controllers/rewards-controller/utils/rewards-api-url.ts',
Expand Down
8 changes: 8 additions & 0 deletions tests/feature-flags/feature-flag-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2829,6 +2829,14 @@ export const FEATURE_FLAG_REGISTRY: Record<string, FeatureFlagRegistryEntry> = {
status: FeatureFlagStatus.Active,
},

legacyIosGoogleConfigEnabled: {
name: 'legacyIosGoogleConfigEnabled',
type: FeatureFlagType.Remote,
inProd: true,
productionDefault: true,
status: FeatureFlagStatus.Active,
},

metalCardCheckoutEnabled: {
name: 'metalCardCheckoutEnabled',
type: FeatureFlagType.Remote,
Expand Down
Loading