Skip to content

Commit

Permalink
fix: Auto lock settings theme (#1293)
Browse files Browse the repository at this point in the history
Signed-off-by: al-rosenthal <[email protected]>
  • Loading branch information
al-rosenthal authored Oct 22, 2024
1 parent 2660e98 commit c6ac146
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,9 +22,7 @@ const InactivityWrapper: React.FC<PropsWithChildren> = ({ children }) => {
const { agent } = useAgent()
const { removeSavedWalletSecret } = useAuth()
const timer = useRef<number | undefined>(undefined)
const timeoutAsMilliseconds = useRef<number>(
(store.preferences.autoLockTime !== undefined ? store.preferences.autoLockTime : AutoLockTime.FiveMinutes) * 60000
)
const timeoutAsMilliseconds = useRef<number>((store.preferences.autoLockTime ?? defaultAutoLockTime) * 60000)
const inactivityTimer = useRef<NodeJS.Timeout | null>(null)
const panResponder = React.useRef(
PanResponder.create({
Expand Down
2 changes: 2 additions & 0 deletions packages/legacy/core/App/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const attemptLockoutThresholdRules = {
attemptPenalty: 24 * hour,
}

export const defaultAutoLockTime = 5

export const walletId = 'walletId'

export const minPINLength = 6
Expand Down
3 changes: 2 additions & 1 deletion packages/legacy/core/App/contexts/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <S extends State>(state: S, action: ReducerAction<any>) => S

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions packages/legacy/core/App/localization/fr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/legacy/core/App/screens/AutoLock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ 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'
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
Expand All @@ -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: {
Expand Down
10 changes: 8 additions & 2 deletions packages/legacy/core/App/screens/PINEnter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -355,7 +361,7 @@ const PINEnter: React.FC<PINEnterProps> = ({ setAuthenticated, usage = PINEntryU
return (
<>
<Text style={style.helpText}>
{t('PINEnter.LockedOut', { time: String(store.preferences.autoLockTime ?? 5) })}
{t('PINEnter.LockedOut', { time: String(store.preferences.autoLockTime ?? defaultAutoLockTime) })}
</Text>
<Text style={style.helpText}>{t('PINEnter.ReEnterPIN')}</Text>
</>
Expand Down

0 comments on commit c6ac146

Please sign in to comment.