Skip to content

Commit

Permalink
fix: the default duraction for auto lock (#10638)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuanyang233 committed Aug 28, 2023
1 parent 9ed646a commit 326c3af
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CrossIsolationMessages } from '@masknet/shared-base'
import { walletDatabase } from '../../../database/Plugin.db.js'

const DEFAULT_LOCK_DURATION = 1000 * 60 * 15 // 15 mins
const DEFAULT_LOCK_DURATION = 1000 * 60 * 60 * 24 // One day

const ID = 'locker'

Expand Down
2 changes: 2 additions & 0 deletions packages/mask/shared-ui/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@
"popups_wallet_settings_change_network": "Change Network",
"popups_wallet_settings_auto_unlock_time": "Auto-lock Time",
"popups_wallet_settings_auto_unlock_time_mins": "{{time}} Mins",
"popups_wallet_settings_auto-unlock_time_hour_one": "{{count}} Hour",
"popups_wallet_settings_auto-unlock_time_hour_other": "{{count}} Hours",
"popups_wallet_settings_auto_unlock_time_title": "Auto-lock",
"popups_wallet_settings_change_payment_password": "Change Payment Password",
"popups_wallet_settings_show_private_key": "Show Private Key",
Expand Down
6 changes: 5 additions & 1 deletion packages/mask/src/extension/popups/UI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
VerifyBackupPasswordModal,
} from './modals/index.js'
import SwitchWallet from './pages/Wallet/SwitchWallet/index.js'
import { noop } from 'lodash-es'

const Wallet = lazy(() => import(/* webpackPreload: true */ './pages/Wallet/index.js'))
const Personas = lazy(() => import(/* webpackPreload: true */ './pages/Personas/index.js'))
Expand Down Expand Up @@ -142,7 +143,10 @@ export default function Popups() {
[title, extension, customBackHandler],
)

useIdleTimer({ onAction: Services.Wallet.setAutoLockTimer, throttle: 10000 })
useIdleTimer({
onAction: !location.hash.includes('/swap') ? Services.Wallet.setAutoLockTimer : noop,
throttle: 10000,
})
useEffect(() => {
if (location.hash.includes('/swap')) return
return CrossIsolationMessages.events.popupRouteUpdated.on((url) => PopupsHistory.replace(url))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ enum OptionName {
NEVER = 'Never',
}

const DEFAULT_MIN_AUTO_LOCKER_TIME = 1000 * 60 * 15 // 15 mins
const DEFAULT_MIN_AUTO_LOCKER_TIME = 1000 * 60 * 60 * 24 // One day

const ONE_DAY_IN_MILLISECONDS = hoursToMilliseconds(24)

Expand Down Expand Up @@ -114,7 +114,7 @@ function WalletAutoLockSettingDrawer(props: BottomDrawerProps) {
sx={{ mt: 2 }}
error={error}
fullWidth
placeholder={'15'}
placeholder={'1440'}
value={time || initialTime}
onChange={(e) => {
if (!e.target.value) setTime('')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useMemo } from 'react'
import { Icons } from '@masknet/icons'
import { Box, ListItem, Typography, useTheme } from '@mui/material'
import millisecondsToMinutes from 'date-fns/millisecondsToMinutes'
import millisecondsToHours from 'date-fns/millisecondsToHours'
import { useI18N } from '../../../../../utils/index.js'
import { useStyles } from './useStyles.js'
import { WalletAutoLockSettingModal } from '../../../modals/modals.js'
Expand All @@ -13,6 +15,7 @@ export function AutoLock() {

const { value } = useWalletAutoLockTime()

const minutes = useMemo(() => (value ? millisecondsToMinutes(value) : undefined), [value])
return (
<ListItem
className={classes.item}
Expand All @@ -28,7 +31,9 @@ export function AutoLock() {
<Box className={classes.itemBox}>
{value ? (
<Typography className={classes.itemText}>
{t('popups_wallet_settings_auto_unlock_time_mins', { time: millisecondsToMinutes(value) })}
{minutes && minutes >= 60
? t('popups_wallet_settings_auto-unlock_time_hour', { count: millisecondsToHours(value) })
: t('popups_wallet_settings_auto_unlock_time_mins', { time: millisecondsToMinutes(value) })}
</Typography>
) : null}
<Icons.ArrowRight color={theme.palette.maskColor.second} size={24} />
Expand Down

0 comments on commit 326c3af

Please sign in to comment.