Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 1653 first feature flag poc #11578

Merged
merged 14 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ const Main = (props) => {
useEnableAutomaticSecurityChecks();
useMinimumVersions();




useEffect(() => {
if (DEPRECATED_NETWORKS.includes(props.chainId)) {
setShowDeprecatedAlert(true);
Expand Down Expand Up @@ -268,7 +265,6 @@ const Main = (props) => {
initForceReload();
return;
}

});

// Remove all notifications that aren't visible
Expand Down
68 changes: 68 additions & 0 deletions app/components/hooks/MinimumVersions/useMinimumVersions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { renderHook } from '@testing-library/react-hooks';
import { useSelector } from 'react-redux';
import { useNavigation } from '@react-navigation/native';
import { getBuildNumber } from 'react-native-device-info';
import useMinimumVersions from './useMinimumVersions';

jest.mock('react-redux', () => ({
useSelector: jest.fn(),
}));

jest.mock('@react-navigation/native', () => ({
useNavigation: jest.fn(),
}));

jest.mock('react-native-device-info', () => ({
getBuildNumber: jest.fn(),
}));

jest.mock('react-native', () => ({
InteractionManager: {
runAfterInteractions: jest.fn((callback) => callback()),
},
}));

jest.mock('../../UI/UpdateNeeded/UpdateNeeded', () => ({
createUpdateNeededNavDetails: jest.fn(),
}));

describe('useMinimumVersions', () => {
const mockNavigation = {
navigate: jest.fn(),
};

beforeEach(() => {
jest.clearAllMocks();
(useNavigation as jest.Mock).mockReturnValue(mockNavigation);
});

it('requires update only if automaticSecurityChecksEnabled', () => {
(useSelector as jest.Mock).mockImplementation(() => ({
security: { automaticSecurityChecksEnabled: false },
featureFlags: {
featureFlags: { mobileMinimumVersions: { appMinimumBuild: 100 } },
},
}));

(getBuildNumber as jest.Mock).mockReturnValue('101');

renderHook(() => useMinimumVersions());

expect(mockNavigation.navigate).not.toHaveBeenCalled();
});

it('requires update only if currentBuildNumber is lower than appMinimumBuild', () => {
(useSelector as jest.Mock).mockImplementation(() => ({
security: { automaticSecurityChecksEnabled: true },
featureFlags: {
featureFlags: { mobileMinimumVersions: { appMinimumBuild: 100 } },
},
}));

(getBuildNumber as jest.Mock).mockReturnValue('101');

renderHook(() => useMinimumVersions());

expect(mockNavigation.navigate).not.toHaveBeenCalled();
});
});
29 changes: 12 additions & 17 deletions app/components/hooks/MinimumVersions/useMinimumVersions.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import { useEffect, useMemo } from 'react';
import { useEffect } from 'react';
import { getBuildNumber } from 'react-native-device-info';
import { useAppConfig } from '../AppConfig';
import { createUpdateNeededNavDetails } from '../../UI/UpdateNeeded/UpdateNeeded';
import { useSelector } from 'react-redux';
import { useNavigation } from '@react-navigation/native';
import { InteractionManager } from 'react-native';
import { FeatureFlagsState } from '../../../core/redux/slices/featureFlags';
import { SecurityState } from '../../../../app/reducers/security';
import { RootState } from '../../../../app/reducers';

const useMinimumVersions = () => {
const allowAutomaticSecurityChecks = useSelector(
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(state: any) => state.security.automaticSecurityChecksEnabled,
const { automaticSecurityChecksEnabled }: SecurityState = useSelector(
(state: RootState) => state.security,
);
const { featureFlags }: FeatureFlagsState = useSelector(
(state: RootState) => state.featureFlags,
);
const minimumValues = useAppConfig(allowAutomaticSecurityChecks);
const currentBuildNumber = Number(getBuildNumber());
const navigation = useNavigation();
const shouldTriggerUpdateFlow = useMemo(
() =>
!!(
allowAutomaticSecurityChecks &&
minimumValues.data &&
minimumValues.data.security.minimumVersions.appMinimumBuild >
currentBuildNumber
),
[allowAutomaticSecurityChecks, currentBuildNumber, minimumValues.data],
);
const shouldTriggerUpdateFlow =
automaticSecurityChecksEnabled &&
featureFlags?.mobileMinimumVersions?.appMinimumBuild > currentBuildNumber;

useEffect(() => {
if (shouldTriggerUpdateFlow) {
Expand Down
2 changes: 1 addition & 1 deletion app/core/AppConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export default {
'config-api.metamask.io/featureFlags',
],
FEATURE_FLAGS_API: {
BASE_URL: 'https://client-config.api.cx.metamask.io/',
BASE_URL: 'https://client-config.api.cx.metamask.io',
VERSION: 'v1',
},
} as const;
4 changes: 2 additions & 2 deletions app/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import infuraAvailabilityReducer from './infuraAvailability';
import collectiblesReducer from './collectibles';
import navigationReducer from './navigation';
import networkOnboardReducer from './networkSelector';
import securityReducer from './security';
import securityReducer, { SecurityState } from './security';
import { combineReducers, Reducer } from 'redux';
import experimentalSettingsReducer from './experimentalSettings';
import { EngineState } from '../core/Engine';
Expand Down Expand Up @@ -106,7 +106,7 @@ export interface RootState {
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
networkOnboarded: any;
security: StateFromReducer<typeof securityReducer>;
security: SecurityState;
sdk: StateFromReducer<typeof sdkReducer>;
// The experimentalSettings reducer is TypeScript but not yet a valid reducer
// TODO: Replace "any" with type
Expand Down
9 changes: 9 additions & 0 deletions app/reducers/security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
import { ActionType, Action } from '../../actions/security';
import { SecuritySettingsState } from '../../actions/security/state';

export interface SecurityState {
allowLoginWithRememberMe: boolean;
automaticSecurityChecksEnabled: boolean;
hasUserSelectedAutomaticSecurityCheckOption: boolean;
isAutomaticSecurityChecksModalOpen: boolean;
dataCollectionForMarketing: boolean | null;
isNFTAutoDetectionModalViewed: boolean;
}

export const initialState: Readonly<SecuritySettingsState> = {
allowLoginWithRememberMe: false,
automaticSecurityChecksEnabled: false,
Expand Down
Loading