Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Trim whitespace from input recovery phrase #3599

Merged
merged 1 commit into from
Nov 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions js/src/modals/CreateAccount/RecoveryPhrase/recoveryPhrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export default class RecoveryPhrase extends Component {
<Input
hint='the account recovery phrase'
label='account recovery phrase'
multiLine
rows={ 1 }
value={ recoveryPhrase }
onChange={ this.onEditPhrase } />
<Input
Expand Down Expand Up @@ -112,17 +110,23 @@ export default class RecoveryPhrase extends Component {
}

onEditPhrase = (event) => {
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

const parts = recoveryPhrase.split(' ');
let recoveryPhraseError = null;

if (!value || value.trim().length < 25) {
error = ERRORS.noPhrase;
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);
}

Expand Down