2020-05-08 17:04:37 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { Grid } from 'react-native-easy-grid';
|
|
|
|
|
|
|
|
import { themes } from '../../../constants/colors';
|
|
|
|
import { resetAttempts } from '../../../utils/localAuthentication';
|
|
|
|
import { TYPE } from '../constants';
|
2021-10-01 18:12:19 +00:00
|
|
|
import { getDiff, getLockedUntil } from '../utils';
|
2020-05-08 17:04:37 +00:00
|
|
|
import I18n from '../../../i18n';
|
|
|
|
import styles from './styles';
|
|
|
|
import Title from './Title';
|
|
|
|
import Subtitle from './Subtitle';
|
|
|
|
import LockIcon from './LockIcon';
|
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
interface IPasscodeTimer {
|
|
|
|
time: string;
|
|
|
|
theme: string;
|
|
|
|
setStatus: Function;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IPasscodeLocked {
|
|
|
|
theme: string;
|
|
|
|
setStatus: Function;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Timer = React.memo(({ time, theme, setStatus }: IPasscodeTimer) => {
|
2020-05-08 17:04:37 +00:00
|
|
|
const calcTimeLeft = () => {
|
|
|
|
const diff = getDiff(time);
|
|
|
|
if (diff > 0) {
|
|
|
|
return Math.floor((diff / 1000) % 60);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
const [timeLeft, setTimeLeft] = useState<any>(calcTimeLeft());
|
2020-05-08 17:04:37 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeLeft(calcTimeLeft());
|
|
|
|
if (timeLeft <= 1) {
|
|
|
|
resetAttempts();
|
|
|
|
setStatus(TYPE.ENTER);
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!timeLeft) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <Subtitle text={I18n.t('Passcode_app_locked_subtitle', { timeLeft })} theme={theme} />;
|
|
|
|
});
|
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
const Locked = React.memo(({ theme, setStatus }: IPasscodeLocked) => {
|
|
|
|
const [lockedUntil, setLockedUntil] = useState<any>(null);
|
2020-05-08 17:04:37 +00:00
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
const readItemFromStorage = async () => {
|
2020-05-08 17:04:37 +00:00
|
|
|
const l = await getLockedUntil();
|
|
|
|
setLockedUntil(l);
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
readItemFromStorage();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2021-10-01 18:12:19 +00:00
|
|
|
<Grid style={[styles.grid, { backgroundColor: themes[theme].passcodeBackground }]}>
|
2020-05-08 17:04:37 +00:00
|
|
|
<LockIcon theme={theme} />
|
|
|
|
<Title text={I18n.t('Passcode_app_locked_title')} theme={theme} />
|
|
|
|
<Timer theme={theme} time={lockedUntil} setStatus={setStatus} />
|
|
|
|
</Grid>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export default Locked;
|