Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #676 from rsksmart/fix-double
Browse files Browse the repository at this point in the history
  • Loading branch information
patogallaiovlabs authored May 12, 2021
2 parents b284b77 + 04eacf1 commit 12b3470
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/common/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 6 additions & 1 deletion src/components/common/passcode/passcode.modal.verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/passcode/wrongPasscodeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 12b3470

Please sign in to comment.