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

[Force upgrade] Automatic security checks settings #4897

Merged
merged 2 commits into from
Aug 24, 2022
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
15 changes: 14 additions & 1 deletion app/actions/security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@ import type { Action } from 'redux';

export enum ActionType {
SET_ALLOW_LOGIN_WITH_REMEMBER_ME = 'SET_ALLOW_LOGIN_WITH_REMEMBER_ME',
SET_AUTOMATIC_SECURITY_CHECKS = 'SET_AUTOMATIC_SECURITY_CHECKS',
}

export interface AllowLoginWithRememberMeUpdated
extends Action<ActionType.SET_ALLOW_LOGIN_WITH_REMEMBER_ME> {
enabled: boolean;
}

export type Action = AllowLoginWithRememberMeUpdated;
export interface AutomaticSecurityChecks
extends Action<ActionType.SET_AUTOMATIC_SECURITY_CHECKS> {
enabled: boolean;
}

export type Action = AllowLoginWithRememberMeUpdated | AutomaticSecurityChecks;

export const setAllowLoginWithRememberMe = (
enabled: boolean,
): AllowLoginWithRememberMeUpdated => ({
type: ActionType.SET_ALLOW_LOGIN_WITH_REMEMBER_ME,
enabled,
});

export const setAutomaticSecurityChecks = (
enabled: boolean,
): AutomaticSecurityChecks => ({
type: ActionType.SET_AUTOMATIC_SECURITY_CHECKS,
enabled,
});
1 change: 1 addition & 0 deletions app/actions/security/state.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface SecuritySettingsState {
allowLoginWithRememberMe: boolean;
automaticSecurityChecks: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useCallback } from 'react';
import { SecurityOptionToggle } from '../../../../UI/SecurityOptionToggle';
import { strings } from '../../../../../../locales/i18n';
import { useSelector, useDispatch } from 'react-redux';
import { setAutomaticSecurityChecks } from '../../../../../actions/security';

const AutomaticSecurityChecks = () => {
const dispatch = useDispatch();
const automaticSecurityChecksState = useSelector(
(state: any) => state.security.automaticSecurityChecks,
);

const toggleAutomaticSecurityChecks = useCallback(
(value: boolean) => {
dispatch(setAutomaticSecurityChecks(value));
},
[dispatch],
);
return (
<SecurityOptionToggle
title={strings(`automatic_security_checks.title`)}
description={strings(`automatic_security_checks.description`)}
value={automaticSecurityChecksState}
onOptionUpdated={toggleAutomaticSecurityChecks}
/>
);
};

export default React.memo(AutomaticSecurityChecks);
2 changes: 2 additions & 0 deletions app/components/Views/Settings/SecuritySettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { LEARN_MORE_URL } from '../../../../constants/urls';
import DeleteMetaMetricsData from './Sections/DeleteMetaMetricsData';
import DeleteWalletData from './Sections/DeleteWalletData';
import RememberMeOptionSection from './Sections/RememberMeOptionSection';
import AutomaticSecurityChecks from './Sections/AutomaticSecurityChecks';

const isIos = Device.isIos();

Expand Down Expand Up @@ -1151,6 +1152,7 @@ class Settings extends PureComponent {
{this.renderApprovalModal()}
{this.renderHistoryModal()}
{this.isMainnet() && this.renderOpenSeaSettings()}
{__DEV__ ? <AutomaticSecurityChecks /> : null}
{this.renderHint()}
</View>
</ScrollView>
Expand Down
7 changes: 7 additions & 0 deletions app/reducers/security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SecuritySettingsState } from '../../actions/security/state';

const initialState: Readonly<SecuritySettingsState> = {
allowLoginWithRememberMe: false,
automaticSecurityChecks: true,
};

const securityReducer = (
Expand All @@ -13,8 +14,14 @@ const securityReducer = (
switch (action.type) {
case ActionType.SET_ALLOW_LOGIN_WITH_REMEMBER_ME:
return {
...state,
allowLoginWithRememberMe: action.enabled,
};
case ActionType.SET_AUTOMATIC_SECURITY_CHECKS:
return {
...state,
automaticSecurityChecks: action.enabled,
};
default:
return state;
}
Expand Down
4 changes: 4 additions & 0 deletions locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2161,5 +2161,9 @@
"confirmation_modal": {
"cancel_cta": "Cancel",
"confirm_cta": "Confirm"
},
"automatic_security_checks": {
"title": "Automatic security checks",
"description": "Automatically checking for updates may expose your IP address to GitHub servers. This only indicates that your IP address is using MetaMask. No other information or account addresses are exposed."
}
}