From 67771f39de9c5b860851c4020f0dc1be7d372e59 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 24 Nov 2016 14:56:39 +0100 Subject: [PATCH] Trim whitespace from recovery phrase --- .../RecoveryPhrase/recoveryPhrase.js | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/js/src/modals/CreateAccount/RecoveryPhrase/recoveryPhrase.js b/js/src/modals/CreateAccount/RecoveryPhrase/recoveryPhrase.js index 9feaa4d2c..ffa90ef27 100644 --- a/js/src/modals/CreateAccount/RecoveryPhrase/recoveryPhrase.js +++ b/js/src/modals/CreateAccount/RecoveryPhrase/recoveryPhrase.js @@ -54,8 +54,6 @@ export default class RecoveryPhrase extends Component { { - const value = event.target.value; - let error = null; + const recoveryPhrase = event.target.value + .toLowerCase() // wordlists are lowercase + .trim() // remove whitespace at both ends + .replace(/\s/g, ' ') // replace any whitespace with single space + .replace(/ +/g, ' '); // replace multiple spaces with a single space - if (!value || value.trim().length < 25) { - error = ERRORS.noPhrase; + const parts = recoveryPhrase.split(' '); + let recoveryPhraseError = null; + + if (!recoveryPhrase || recoveryPhrase.length < 25 || parts.length < 8) { + recoveryPhraseError = ERRORS.noPhrase; } this.setState({ - recoveryPhrase: value, - recoveryPhraseError: error, - isValidPhrase: !error + recoveryPhrase, + recoveryPhraseError, + isValidPhrase: !recoveryPhraseError }, this.updateParent); }