From 51534d4cc943edab44c849e439c658f4cff1a70d Mon Sep 17 00:00:00 2001 From: William Grant Date: Tue, 14 May 2024 14:54:31 +1000 Subject: [PATCH] feat: added new hide recovery password setting --- ts/components/SessionInboxView.tsx | 1 + .../buttons/ModalConfirmButtonContainer.tsx | 12 +++++ .../dialog/TermsOfServicePrivacyDialog.tsx | 50 ++++++++----------- ts/data/settings-key.ts | 2 + ts/state/ducks/settings.tsx | 5 ++ ts/state/selectors/settings.ts | 9 ++++ ts/util/accountManager.ts | 8 ++- 7 files changed, 56 insertions(+), 31 deletions(-) create mode 100644 ts/components/buttons/ModalConfirmButtonContainer.tsx diff --git a/ts/components/SessionInboxView.tsx b/ts/components/SessionInboxView.tsx index f5f2b9645..623ea642a 100644 --- a/ts/components/SessionInboxView.tsx +++ b/ts/components/SessionInboxView.tsx @@ -102,6 +102,7 @@ function setupLeftPane(forceUpdateInboxComponent: () => void) { settingsLinkPreview: Storage.getBoolOrFalse(SettingsKey.settingsLinkPreview), hasFollowSystemThemeEnabled: Storage.getBoolOrFalse(SettingsKey.hasFollowSystemThemeEnabled), hasShiftSendEnabled: Storage.getBoolOrFalse(SettingsKey.hasShiftSendEnabled), + hideRecoveryPassword: Storage.getBoolOrFalse(SettingsKey.hideRecoveryPassword), }) ); forceUpdateInboxComponent(); diff --git a/ts/components/buttons/ModalConfirmButtonContainer.tsx b/ts/components/buttons/ModalConfirmButtonContainer.tsx new file mode 100644 index 000000000..573c38fe7 --- /dev/null +++ b/ts/components/buttons/ModalConfirmButtonContainer.tsx @@ -0,0 +1,12 @@ +import styled from 'styled-components'; +import { Flex } from '../basic/Flex'; + +/** We use this in the modals only to bypass the padding on the body so the buttons take up the full space width of the modal window + * See .session-modal__body for padding values + */ +export const ModalConfirmButtonContainer = styled(Flex)` + margin-top: 0px; + margin-right: calc(var(--margins-lg) * -1); + margin-bottom: calc(var(--margins-lg) * -1); + margin-left: calc(var(--margins-lg) * -1); +`; diff --git a/ts/components/dialog/TermsOfServicePrivacyDialog.tsx b/ts/components/dialog/TermsOfServicePrivacyDialog.tsx index 703d6236d..43e9b589c 100644 --- a/ts/components/dialog/TermsOfServicePrivacyDialog.tsx +++ b/ts/components/dialog/TermsOfServicePrivacyDialog.tsx @@ -1,16 +1,10 @@ import { shell } from 'electron'; import { useDispatch } from 'react-redux'; -import styled from 'styled-components'; import { updateTermsOfServicePrivacyModal } from '../../state/onboarding/ducks/modals'; import { SessionWrapperModal } from '../SessionWrapperModal'; -import { Flex } from '../basic/Flex'; import { SessionButton, SessionButtonType } from '../basic/SessionButton'; import { SpacerSM } from '../basic/Text'; - -// NOTE we want to bypass the padding on the modal body so the buttons take up the full space -const ConfirmButtonContainer = styled(Flex)` - margin: 0px calc(var(--margins-lg) * -1) calc(var(--margins-lg) * -1) calc(var(--margins-lg) * -1); -`; +import { ModalConfirmButtonContainer } from '../buttons/ModalConfirmButtonContainer'; export type TermsOfServicePrivacyDialogProps = { show: boolean; @@ -37,28 +31,26 @@ export function TermsOfServicePrivacyDialog(props: TermsOfServicePrivacyDialogPr showHeader={true} headerReverse={true} > -
- {window.i18n('urlOpenBrowser')} - - - { - void shell.openExternal('https://getsession.org/terms-of-service'); - }} - dataTestId="terms-of-service-button" - /> - { - void shell.openExternal('https://getsession.org/privacy-policy'); - }} - dataTestId="privacy-policy-button" - /> - -
+ {window.i18n('urlOpenBrowser')} + + + { + void shell.openExternal('https://getsession.org/terms-of-service'); + }} + dataTestId="terms-of-service-button" + /> + { + void shell.openExternal('https://getsession.org/privacy-policy'); + }} + dataTestId="privacy-policy-button" + /> + ); } diff --git a/ts/data/settings-key.ts b/ts/data/settings-key.ts index 872f57e7f..ee08ff535 100644 --- a/ts/data/settings-key.ts +++ b/ts/data/settings-key.ts @@ -15,6 +15,7 @@ const hasSyncedInitialConfigurationItem = 'hasSyncedInitialConfigurationItem'; const lastAvatarUploadTimestamp = 'lastAvatarUploadTimestamp'; const hasLinkPreviewPopupBeenDisplayed = 'hasLinkPreviewPopupBeenDisplayed'; const hasFollowSystemThemeEnabled = 'hasFollowSystemThemeEnabled'; +const hideRecoveryPassword = 'hideRecoveryPassword'; // user config tracking timestamps (to discard incoming messages which would make a change we reverted in the last config message we merged) const latestUserProfileEnvelopeTimestamp = 'latestUserProfileEnvelopeTimestamp'; @@ -42,6 +43,7 @@ export const SettingsKey = { latestUserGroupEnvelopeTimestamp, latestUserContactsEnvelopeTimestamp, hasFollowSystemThemeEnabled, + hideRecoveryPassword, } as const; export const KNOWN_BLINDED_KEYS_ITEM = 'KNOWN_BLINDED_KEYS_ITEM'; diff --git a/ts/state/ducks/settings.tsx b/ts/state/ducks/settings.tsx index 7397b47c3..a231606ab 100644 --- a/ts/state/ducks/settings.tsx +++ b/ts/state/ducks/settings.tsx @@ -9,6 +9,7 @@ const SettingsBoolsKeyTrackedInRedux = [ SettingsKey.hasBlindedMsgRequestsEnabled, SettingsKey.hasFollowSystemThemeEnabled, SettingsKey.hasShiftSendEnabled, + SettingsKey.hideRecoveryPassword, ] as const; export type SettingsState = { @@ -23,6 +24,7 @@ export function getSettingsInitialState() { hasBlindedMsgRequestsEnabled: false, hasFollowSystemThemeEnabled: false, hasShiftSendEnabled: false, + hideRecoveryPassword: false, }, }; } @@ -53,6 +55,7 @@ const settingsSlice = createSlice({ hasBlindedMsgRequestsEnabled: boolean; hasFollowSystemThemeEnabled: boolean; hasShiftSendEnabled: boolean; + hideRecoveryPassword: boolean; }> ) { const { @@ -61,6 +64,7 @@ const settingsSlice = createSlice({ settingsLinkPreview, someDeviceOutdatedSyncing, hasShiftSendEnabled, + hideRecoveryPassword, } = payload; state.settingsBools.someDeviceOutdatedSyncing = someDeviceOutdatedSyncing; @@ -68,6 +72,7 @@ const settingsSlice = createSlice({ state.settingsBools.hasBlindedMsgRequestsEnabled = hasBlindedMsgRequestsEnabled; state.settingsBools.hasFollowSystemThemeEnabled = hasFollowSystemThemeEnabled; state.settingsBools.hasShiftSendEnabled = hasShiftSendEnabled; + state.settingsBools.hideRecoveryPassword = hideRecoveryPassword; return state; }, diff --git a/ts/state/selectors/settings.ts b/ts/state/selectors/settings.ts index ff0ccb3ec..9137a3ec3 100644 --- a/ts/state/selectors/settings.ts +++ b/ts/state/selectors/settings.ts @@ -17,6 +17,9 @@ const getHasFollowSystemThemeEnabled = (state: StateType) => const getHasShiftSendEnabled = (state: StateType) => state.settings.settingsBools[SettingsKey.hasShiftSendEnabled]; +const getHideRecoveryPassword = (state: StateType) => + state.settings.settingsBools[SettingsKey.hideRecoveryPassword]; + export const useHasLinkPreviewEnabled = () => { const value = useSelector(getLinkPreviewEnabled); return Boolean(value); @@ -42,3 +45,9 @@ export const useHasEnterSendEnabled = () => { return Boolean(value); }; + +export const useHideRecoveryPasswordEnabled = () => { + const value = useSelector(getHideRecoveryPassword); + + return Boolean(value); +}; diff --git a/ts/util/accountManager.ts b/ts/util/accountManager.ts index 3a4cbf056..5761b2b1e 100644 --- a/ts/util/accountManager.ts +++ b/ts/util/accountManager.ts @@ -158,10 +158,11 @@ async function createAccount(identityKeyPair: SessionKeyPair) { Storage.remove('number_id'), Storage.remove('device_name'), Storage.remove('userAgent'), - Storage.remove(SettingsKey.settingsReadReceipt), - Storage.remove(SettingsKey.settingsTypingIndicator), Storage.remove('regionCode'), Storage.remove('local_attachment_encrypted_key'), + Storage.remove(SettingsKey.settingsReadReceipt), + Storage.remove(SettingsKey.settingsTypingIndicator), + Storage.remove(SettingsKey.hideRecoveryPassword), ]); // update our own identity key, which may have changed @@ -181,6 +182,9 @@ async function createAccount(identityKeyPair: SessionKeyPair) { await Storage.put(SettingsKey.settingsOpengroupPruning, true); await window.setOpengroupPruning(true); + // turn off hide recovery password by default + await Storage.put(SettingsKey.hideRecoveryPassword, false); + await setLocalPubKey(pubKeyString); }