From c6ac1461225748581cbc2c42e2e51c71a3d5a7a0 Mon Sep 17 00:00:00 2001 From: Al Rosenthal Date: Tue, 22 Oct 2024 14:00:33 -0700 Subject: [PATCH] fix: Auto lock settings theme (#1293) Signed-off-by: al-rosenthal --- .../core/App/components/misc/InactivityWrapper.tsx | 5 ++--- packages/legacy/core/App/constants.ts | 2 ++ packages/legacy/core/App/contexts/store.tsx | 3 ++- packages/legacy/core/App/localization/fr/index.ts | 10 +++++----- packages/legacy/core/App/screens/AutoLock.tsx | 3 ++- packages/legacy/core/App/screens/PINEnter.tsx | 10 ++++++++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/legacy/core/App/components/misc/InactivityWrapper.tsx b/packages/legacy/core/App/components/misc/InactivityWrapper.tsx index 22e73a6337..c93bd039a6 100644 --- a/packages/legacy/core/App/components/misc/InactivityWrapper.tsx +++ b/packages/legacy/core/App/components/misc/InactivityWrapper.tsx @@ -5,6 +5,7 @@ import { useAuth } from '../../contexts/auth' import { useStore } from '../../contexts/store' import { DispatchAction } from '../../contexts/reducers/store' import { TOKENS, useServices } from '../../container-api' +import { defaultAutoLockTime } from '../../constants' // number of minutes before the timeout action is triggered // a value of 0 will never trigger the lock out action and an undefined value will default to 5 minutes @@ -21,9 +22,7 @@ const InactivityWrapper: React.FC = ({ children }) => { const { agent } = useAgent() const { removeSavedWalletSecret } = useAuth() const timer = useRef(undefined) - const timeoutAsMilliseconds = useRef( - (store.preferences.autoLockTime !== undefined ? store.preferences.autoLockTime : AutoLockTime.FiveMinutes) * 60000 - ) + const timeoutAsMilliseconds = useRef((store.preferences.autoLockTime ?? defaultAutoLockTime) * 60000) const inactivityTimer = useRef(null) const panResponder = React.useRef( PanResponder.create({ diff --git a/packages/legacy/core/App/constants.ts b/packages/legacy/core/App/constants.ts index c8dee3bf76..d4b1674ee6 100644 --- a/packages/legacy/core/App/constants.ts +++ b/packages/legacy/core/App/constants.ts @@ -61,6 +61,8 @@ export const attemptLockoutThresholdRules = { attemptPenalty: 24 * hour, } +export const defaultAutoLockTime = 5 + export const walletId = 'walletId' export const minPINLength = 6 diff --git a/packages/legacy/core/App/contexts/store.tsx b/packages/legacy/core/App/contexts/store.tsx index 7428b5986c..8dc46c237d 100644 --- a/packages/legacy/core/App/contexts/store.tsx +++ b/packages/legacy/core/App/contexts/store.tsx @@ -4,6 +4,7 @@ import { State } from '../types/state' import { generateRandomWalletName } from '../utils/helpers' import _defaultReducer, { ReducerAction } from './reducers/store' +import { defaultAutoLockTime } from '../constants' type Reducer = (state: S, action: ReducerAction) => S @@ -56,7 +57,7 @@ export const defaultState: State = { preventAutoLock: false, enableShareableLink: false, alternateContactNames: {}, - autoLockTime: 5, // default wallets lockout time to 5 minutes + autoLockTime: defaultAutoLockTime, // default wallets lockout time to 5 minutes }, tours: { seenToursPrompt: false, diff --git a/packages/legacy/core/App/localization/fr/index.ts b/packages/legacy/core/App/localization/fr/index.ts index 149b67d905..e6116574d1 100644 --- a/packages/legacy/core/App/localization/fr/index.ts +++ b/packages/legacy/core/App/localization/fr/index.ts @@ -655,13 +655,13 @@ const translation = { "WhatAreContacts": "Qu’est-ce qu’un Contact?", "ScanMyQR": "Scanner mon code QR", "Developer": "Options de développeur", - "AutoLockTime": "Auto lock time (fr)", + "AutoLockTime": "Auto lock time (FR)", }, "AutoLockTimes": { - "FiveMinutes": "Five Minutes (fr)", - "ThreeMinutes": "Three Minutes (fr)", - "OneMinute": "One Minute (fr)", - "Never": "Never (fr)", + "FiveMinutes": "Five Minutes (FR)", + "ThreeMinutes": "Three Minutes (FR)", + "OneMinute": "One Minute (FR)", + "Never": "Never (FR)", }, "TabStack": { "Home": "Notifications", diff --git a/packages/legacy/core/App/screens/AutoLock.tsx b/packages/legacy/core/App/screens/AutoLock.tsx index 585092ce30..0e4913d55a 100644 --- a/packages/legacy/core/App/screens/AutoLock.tsx +++ b/packages/legacy/core/App/screens/AutoLock.tsx @@ -2,7 +2,6 @@ import { Pressable, StyleSheet, Text, View } from 'react-native' import BouncyCheckbox from 'react-native-bouncy-checkbox' import { SafeAreaView } from 'react-native-safe-area-context' import Icon from 'react-native-vector-icons/MaterialIcons' -import { ColorPallet, SettingsTheme, TextTheme } from '../theme' import { AutoLockTime } from '../components/misc/InactivityWrapper' import { testIdWithKey } from '../utils/testable' import { useStore } from '../contexts/store' @@ -10,6 +9,7 @@ import { DispatchAction } from '../contexts/reducers/store' import React from 'react' import { FlatList } from 'react-native-gesture-handler' import { useTranslation } from 'react-i18next' +import { useTheme } from '../contexts/theme' type AutoLockListItem = { title: string @@ -22,6 +22,7 @@ type AutoLockListItem = { const AutoLock: React.FC = () => { const { t } = useTranslation() const [store, dispatch] = useStore() + const { ColorPallet, SettingsTheme, TextTheme } = useTheme() const currentLockoutTime = store.preferences.autoLockTime ?? AutoLockTime.FiveMinutes const styles = StyleSheet.create({ container: { diff --git a/packages/legacy/core/App/screens/PINEnter.tsx b/packages/legacy/core/App/screens/PINEnter.tsx index 7d118d700d..581d08a695 100644 --- a/packages/legacy/core/App/screens/PINEnter.tsx +++ b/packages/legacy/core/App/screens/PINEnter.tsx @@ -8,7 +8,13 @@ import PINInput from '../components/inputs/PINInput' import { InfoBoxType } from '../components/misc/InfoBox' import PopupModal from '../components/modals/PopupModal' import KeyboardView from '../components/views/KeyboardView' -import { minPINLength, attemptLockoutBaseRules, attemptLockoutThresholdRules, EventTypes } from '../constants' +import { + minPINLength, + attemptLockoutBaseRules, + attemptLockoutThresholdRules, + EventTypes, + defaultAutoLockTime, +} from '../constants' import { TOKENS, useServices } from '../container-api' import { useAnimatedComponents } from '../contexts/animated-components' import { useAuth } from '../contexts/auth' @@ -355,7 +361,7 @@ const PINEnter: React.FC = ({ setAuthenticated, usage = PINEntryU return ( <> - {t('PINEnter.LockedOut', { time: String(store.preferences.autoLockTime ?? 5) })} + {t('PINEnter.LockedOut', { time: String(store.preferences.autoLockTime ?? defaultAutoLockTime) })} {t('PINEnter.ReEnterPIN')}