From 08b5b3e86de351c5f803a177547926260b76c906 Mon Sep 17 00:00:00 2001 From: Jesse Clark Date: Tue, 11 May 2021 18:40:44 +0300 Subject: [PATCH 1/3] Convert numbers to string before saving them to storage. --- src/common/storage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/storage.js b/src/common/storage.js index 08c5846d..2ab6b15a 100644 --- a/src/common/storage.js +++ b/src/common/storage.js @@ -393,11 +393,11 @@ class RNStorage { getUserPassword = () => RNStorage.secureGet(SECURE_USER_PASSWORD) - setLastPasscodeAttempt = (timestamp) => RNStorage.secureSet(SECURE_LAST_WRONG_PASSCODE_TIMESTAMP, timestamp); + setLastPasscodeAttempt = (timestamp) => RNStorage.secureSet(SECURE_LAST_WRONG_PASSCODE_TIMESTAMP, timestamp.toString()); getLastPasscodeAttempt = () => RNStorage.secureGet(SECURE_LAST_WRONG_PASSCODE_TIMESTAMP); - setWrongPasscodeCounter = (count) => RNStorage.secureSet(SECURE_WRONG_PASSCODE_COUNTER, count); + setWrongPasscodeCounter = (count) => RNStorage.secureSet(SECURE_WRONG_PASSCODE_COUNTER, count.toString()); getWrongPasscodeCounter = () => RNStorage.secureGet(SECURE_WRONG_PASSCODE_COUNTER); } From 28258f15c47113fbe877fdd13b327c75bd8b703c Mon Sep 17 00:00:00 2001 From: Jesse Clark Date: Tue, 11 May 2021 18:41:13 +0300 Subject: [PATCH 2/3] Set the key to something. - This was the cause of the error. null could not be set which threw the error. - Set this to 0, or the beginning of computer time. --- src/components/common/passcode/wrongPasscodeUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/common/passcode/wrongPasscodeUtils.js b/src/components/common/passcode/wrongPasscodeUtils.js index 7c17db9a..fa5051ba 100644 --- a/src/components/common/passcode/wrongPasscodeUtils.js +++ b/src/components/common/passcode/wrongPasscodeUtils.js @@ -21,7 +21,7 @@ export const WRONG_ATTEMPTS_STEPS = { export const clearWrongAttempts = () => { try { - storage.setLastPasscodeAttempt(); + storage.setLastPasscodeAttempt(0); storage.setWrongPasscodeCounter(0); } catch (error) { console.error('Error cleaning wrong attempts', error); From 04eacf1f186f23dd3a75c200a54e5d2b7b3294d9 Mon Sep 17 00:00:00 2001 From: Jesse Clark Date: Tue, 11 May 2021 18:42:57 +0300 Subject: [PATCH 3/3] Get string and analyze it. - Get the string from storage first, if it is '0' or false, then the user is good and return. - This is a similar approach that is taken a few lines up under wrongAttemptsStorage --- src/components/common/passcode/passcode.modal.verify.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/common/passcode/passcode.modal.verify.js b/src/components/common/passcode/passcode.modal.verify.js index 09d40329..bc1d8162 100644 --- a/src/components/common/passcode/passcode.modal.verify.js +++ b/src/components/common/passcode/passcode.modal.verify.js @@ -43,7 +43,12 @@ class VerifyPasscodeModal extends PureComponent { if (this.wrongAttemptsCounter < WRONG_ATTEMPTS_STEPS.step1.maxAttempts) { return; } - const lastAttemptTimestamp = parseInt(await storage.getLastPasscodeAttempt(), 10); + const lastPasscodeStorage = await storage.getLastPasscodeAttempt(); + if (!lastPasscodeStorage || lastPasscodeStorage === '0') { + return; + } + + const lastAttemptTimestamp = parseInt(lastPasscodeStorage, 10); const msSinceLastAttempt = Date.now() - lastAttemptTimestamp; const { waitingMinutes } = getClosestStep({ numberOfAttempts: this.wrongAttemptsCounter }); const milliseconds = waitingMinutes * 1000 * 60 - msSinceLastAttempt;