Skip to content

Commit 603e5e3

Browse files
Merge pull request #674 from syscoin/fix/unlock-wallet
Fix: unlock opened wallet
2 parents 083716d + 2764be1 commit 603e5e3

24 files changed

+281
-237
lines changed

source/assets/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@
424424
"thisActionErases": "This action erases your current wallet.",
425425
"toRestoreThis": "To restore this current wallet in the future ensure you have the recovery phrase.",
426426
"allYourSettings": "All your settings, like custom tokens and imported accounts, will get lost, however, your funds it’s saved!",
427-
"setAutoLockTime": "Set auto lock time",
427+
"setAutoLockTime": "Set auto lock timer",
428+
"errorMinutes": "the minutes must be between 5 and 120",
428429
"defaultMinutes": "Default: 5 minutes after no activity.",
429430
"maximumMinutes": "Maximum: 120 minutes."
430431
},

source/assets/locales/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@
425425
"toRestoreThis": "Para restaurar esta billetera actual en el futuro, asegúrese de tener la frase de recuperación.",
426426
"allYourSettings": "All your settings, like custom tokens and imported accounts, will get lost, however, your funds it’s saved!",
427427
"setAutoLockTime": "Configurar tiempo de bloqueo automático",
428+
"errorMinutes": "los minutos deben ser entre 5 y 120",
428429
"defaultMinutes": "Predeterminado: 5 minutos después de inactividad.",
429430
"maximumMinutes": "Máximo: 120 minutos."
430431
},

source/assets/locales/pt-br.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@
294294
"toRestoreThis": "To restore this current wallet in the future ensure you have the recovery phrase.",
295295
"allYourSettings": "All your settings, like custom tokens and imported accounts, will get lost, however, your funds it’s saved!",
296296
"setAutoLockTime": "Configurar tempo de bloqueio automático",
297+
"errorMinutes": "o valor para o autolock deve ser entre 5 e 120 minutos",
297298
"defaultMinutes": "Padrão: 5 minutos após inatividade.",
298299
"maximumMinutes": "Máximo: 120 minutos.",
299300
"connectYourWalletAndClick": "CONECTE SUA {{hardwalletName}} E CLIQUE PARA CONECTAR!",

source/hooks/useController.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { CustomJsonRpcProvider } from '@pollum-io/sysweb3-keyring';
44
import { INetwork } from '@pollum-io/sysweb3-network';
55

66
import { controllerEmitter } from 'scripts/Background/controllers/controllerEmitter';
7-
// import { rehydrateStore } from 'state/rehydrate';
8-
// import store from 'state/store';
97

108
export function useController() {
119
const [isUnlocked, setIsUnlocked] = useState(false);
@@ -27,18 +25,21 @@ export function useController() {
2725
'getNetwork',
2826
])) as INetwork;
2927

30-
const _web3Provider = new CustomJsonRpcProvider(
28+
const walletWeb3Provider = new CustomJsonRpcProvider(
3129
abortController.signal,
3230
network.url
3331
);
3432

35-
const _isUnlocked = await controllerEmitter(['wallet', 'isUnlocked'], []);
33+
const isWalletUnlocked = await controllerEmitter(
34+
['wallet', 'isUnlocked'],
35+
[]
36+
);
3637

3738
setActiveNetwork(network);
3839

39-
setWeb3Provider(_web3Provider);
40+
setWeb3Provider(walletWeb3Provider);
4041

41-
setIsUnlocked(!!_isUnlocked);
42+
setIsUnlocked(!!isWalletUnlocked);
4243

4344
setIsLoading(false);
4445
},

source/pages/Settings/AutoLock.tsx

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
import { Form } from 'antd';
2-
import React, { useState } from 'react';
2+
import React, { useState, useEffect } from 'react';
33
import { useTranslation } from 'react-i18next';
44
import { useSelector } from 'react-redux';
55
import { useNavigate } from 'react-router-dom';
66

77
import { Layout, Button } from 'components/index';
88
import { TimeSetSuccessfully } from 'components/Modal/WarningBaseModal';
99
import { useController } from 'hooks/useController';
10+
import { startInactivityTimer } from 'scripts/Background/events/InactivityTimer';
1011
import { RootState } from 'state/store';
1112

12-
const AutolockView = () => {
13+
const AutoLockView = () => {
1314
const { isTimerEnabled } = useSelector((state: RootState) => state.vault);
1415
const timer = useSelector((state: RootState) => state.vault.timer);
1516
const { t } = useTranslation();
16-
const [confirmed, setConfirmed] = useState<boolean>(false);
17-
const [isEnabled, setIsEnabled] = useState<boolean>(isTimerEnabled);
18-
const [loading, setLoading] = useState<boolean>(false);
17+
const [confirmed, setConfirmed] = useState(false);
18+
const [isEnabled, setIsEnabled] = useState(isTimerEnabled);
19+
const [loading, setLoading] = useState(false);
1920
const [form] = Form.useForm();
2021
const [inputValue, setInputValue] = useState(timer);
22+
const [hasError, setHasError] = useState(false);
23+
24+
const { controllerEmitter } = useController();
25+
const navigate = useNavigate();
26+
27+
useEffect(() => {
28+
form.setFieldsValue({ minutes: timer });
29+
if (isEnabled) {
30+
startInactivityTimer(timer);
31+
}
32+
}, [timer, form, isEnabled]);
2133

2234
const handleMaxClick = () => {
2335
setInputValue(120);
@@ -29,25 +41,18 @@ const AutolockView = () => {
2941
form.setFieldsValue({ minutes: 5 });
3042
};
3143

32-
const { controllerEmitter } = useController();
33-
const navigate = useNavigate();
34-
3544
const onSubmit = (data: any) => {
45+
setLoading(true);
3646
try {
37-
setLoading(true);
38-
const minimumMinutesPossible = 5;
39-
const maximumMinutesPossible = 120;
4047
const autolockMinutes = +data.minutes;
41-
42-
if (
43-
autolockMinutes < minimumMinutesPossible ||
44-
autolockMinutes > maximumMinutesPossible
45-
) {
46-
throw new Error('Value must be between 5 and 120');
48+
if (autolockMinutes < 5 || autolockMinutes > 120) {
49+
setHasError(true);
50+
return;
51+
} else {
52+
setHasError(false);
4753
}
48-
controllerEmitter(['wallet', 'setAutolockTimer'], [+data.minutes]);
54+
controllerEmitter(['wallet', 'setAutolockTimer'], [autolockMinutes]);
4955
controllerEmitter(['wallet', 'setIsAutolockEnabled'], [isEnabled]);
50-
5156
setConfirmed(true);
5257
} catch (error) {
5358
console.error('Error:', error);
@@ -56,8 +61,8 @@ const AutolockView = () => {
5661
}
5762
};
5863

59-
const handleInputChange = (e) => {
60-
setInputValue(e.target.value);
64+
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
65+
setInputValue(+e.target.value);
6166
};
6267

6368
return (
@@ -89,7 +94,7 @@ const AutolockView = () => {
8994
initialValues={{ minutes: inputValue }}
9095
autoComplete="off"
9196
>
92-
<Form.Item name="minutes" className=" bg-transparent" hasFeedback>
97+
<Form.Item name="minutes" className="bg-transparent" hasFeedback>
9398
<div className="relative">
9499
<span
95100
onClick={handleMaxClick}
@@ -112,6 +117,11 @@ const AutolockView = () => {
112117
</p>
113118
</div>
114119
</Form.Item>
120+
<div className="flex flex-col items-center justify-center m-3">
121+
{hasError && (
122+
<p className="text-xs text-red-500">{t('settings.errorMinutes')}</p>
123+
)}
124+
</div>
115125

116126
<div className="flex flex-col justify-start items-start my-6 text-sm text-brand-gray200">
117127
<p>{t('settings.defaultMinutes')}</p>
@@ -122,12 +132,6 @@ const AutolockView = () => {
122132
id="verify-address-switch"
123133
name="verify"
124134
className="flex flex-col w-full text-center"
125-
rules={[
126-
{
127-
required: false,
128-
message: '',
129-
},
130-
]}
131135
>
132136
<div className="flex flex-row gap-2 align-center justify-between w-full">
133137
<span className="text-sm">{t('settings.enableAutolock')}</span>
@@ -145,7 +149,6 @@ const AutolockView = () => {
145149
</div>
146150
</div>
147151
</Form.Item>
148-
149152
<div className="relative bottom-[-11rem] md:static">
150153
<Button
151154
className="flex items-center justify-center w-full h-10 bg-white text-brand-blue400 text-base font-medium rounded-[100px]"
@@ -160,4 +163,4 @@ const AutolockView = () => {
160163
);
161164
};
162165

163-
export default AutolockView;
166+
export default AutoLockView;

0 commit comments

Comments
 (0)