Manually add \r to Windows phrases pre 1.4.5 (#3615)
* Manually add \r to Windows phrases pre 1.4.4 * < 1.4.5 * Only support 1.4.x dictionary
This commit is contained in:
parent
e95ef0160f
commit
50585763aa
@ -15,6 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import React, { Component, PropTypes } from 'react';
|
import React, { Component, PropTypes } from 'react';
|
||||||
|
import { Checkbox } from 'material-ui';
|
||||||
|
|
||||||
import { Form, Input } from '../../../ui';
|
import { Form, Input } from '../../../ui';
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ export default class RecoveryPhrase extends Component {
|
|||||||
password1Error: ERRORS.invalidPassword,
|
password1Error: ERRORS.invalidPassword,
|
||||||
password2: '',
|
password2: '',
|
||||||
password2Error: ERRORS.noMatchPassword,
|
password2Error: ERRORS.noMatchPassword,
|
||||||
|
windowsPhrase: false,
|
||||||
isValidPass: false,
|
isValidPass: false,
|
||||||
isValidName: false,
|
isValidName: false,
|
||||||
isValidPhrase: false
|
isValidPhrase: false
|
||||||
@ -47,7 +49,7 @@ export default class RecoveryPhrase extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { accountName, accountNameError, passwordHint, password1, password1Error, password2, password2Error, recoveryPhrase } = this.state;
|
const { accountName, accountNameError, passwordHint, password1, password1Error, password2, password2Error, recoveryPhrase, windowsPhrase } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
@ -86,20 +88,26 @@ export default class RecoveryPhrase extends Component {
|
|||||||
value={ password2 }
|
value={ password2 }
|
||||||
onChange={ this.onEditPassword2 } />
|
onChange={ this.onEditPassword2 } />
|
||||||
</div>
|
</div>
|
||||||
|
<Checkbox
|
||||||
|
className={ styles.checkbox }
|
||||||
|
label='Key was created with Parity <1.4.5 on Windows'
|
||||||
|
checked={ windowsPhrase }
|
||||||
|
onCheck={ this.onToggleWindowsPhrase } />
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateParent = () => {
|
updateParent = () => {
|
||||||
const { isValidName, isValidPass, isValidPhrase, accountName, passwordHint, password1, recoveryPhrase } = this.state;
|
const { isValidName, isValidPass, isValidPhrase, accountName, passwordHint, password1, recoveryPhrase, windowsPhrase } = this.state;
|
||||||
const isValid = isValidName && isValidPass && isValidPhrase;
|
const isValid = isValidName && isValidPass && isValidPhrase;
|
||||||
|
|
||||||
this.props.onChange(isValid, {
|
this.props.onChange(isValid, {
|
||||||
name: accountName,
|
name: accountName,
|
||||||
passwordHint,
|
passwordHint,
|
||||||
password: password1,
|
password: password1,
|
||||||
phrase: recoveryPhrase
|
phrase: recoveryPhrase,
|
||||||
|
windowsPhrase
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +117,12 @@ export default class RecoveryPhrase extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onToggleWindowsPhrase = (event) => {
|
||||||
|
this.setState({
|
||||||
|
windowsPhrase: !this.state.windowsPhrase
|
||||||
|
}, this.updateParent);
|
||||||
|
}
|
||||||
|
|
||||||
onEditPhrase = (event) => {
|
onEditPhrase = (event) => {
|
||||||
const recoveryPhrase = event.target.value
|
const recoveryPhrase = event.target.value
|
||||||
.toLowerCase() // wordlists are lowercase
|
.toLowerCase() // wordlists are lowercase
|
||||||
@ -116,15 +130,18 @@ export default class RecoveryPhrase extends Component {
|
|||||||
.replace(/\s/g, ' ') // replace any whitespace with single space
|
.replace(/\s/g, ' ') // replace any whitespace with single space
|
||||||
.replace(/ +/g, ' '); // replace multiple spaces with a single space
|
.replace(/ +/g, ' '); // replace multiple spaces with a single space
|
||||||
|
|
||||||
const parts = recoveryPhrase.split(' ');
|
const phraseParts = recoveryPhrase
|
||||||
|
.split(' ')
|
||||||
|
.map((part) => part.trim())
|
||||||
|
.filter((part) => part.length);
|
||||||
let recoveryPhraseError = null;
|
let recoveryPhraseError = null;
|
||||||
|
|
||||||
if (!recoveryPhrase || recoveryPhrase.length < 25 || parts.length < 8) {
|
if (!recoveryPhrase || recoveryPhrase.length < 25 || phraseParts.length < 8) {
|
||||||
recoveryPhraseError = ERRORS.noPhrase;
|
recoveryPhraseError = ERRORS.noPhrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
recoveryPhrase,
|
recoveryPhrase: phraseParts.join(' '),
|
||||||
recoveryPhraseError,
|
recoveryPhraseError,
|
||||||
isValidPhrase: !recoveryPhraseError
|
isValidPhrase: !recoveryPhraseError
|
||||||
}, this.updateParent);
|
}, this.updateParent);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
/* You should have received a copy of the GNU General Public License
|
/* You should have received a copy of the GNU General Public License
|
||||||
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.spaced {
|
.spaced {
|
||||||
line-height: 1.618em;
|
line-height: 1.618em;
|
||||||
}
|
}
|
||||||
@ -67,3 +68,7 @@
|
|||||||
.upload>div {
|
.upload>div {
|
||||||
margin-right: 0.5em;
|
margin-right: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.checkbox {
|
||||||
|
margin-top: 2em;
|
||||||
|
}
|
||||||
|
@ -59,6 +59,7 @@ export default class CreateAccount extends Component {
|
|||||||
passwordHint: null,
|
passwordHint: null,
|
||||||
password: null,
|
password: null,
|
||||||
phrase: null,
|
phrase: null,
|
||||||
|
windowsPhrase: false,
|
||||||
rawKey: null,
|
rawKey: null,
|
||||||
json: null,
|
json: null,
|
||||||
canCreate: false,
|
canCreate: false,
|
||||||
@ -200,7 +201,7 @@ export default class CreateAccount extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onCreate = () => {
|
onCreate = () => {
|
||||||
const { createType } = this.state;
|
const { createType, windowsPhrase } = this.state;
|
||||||
const { api } = this.context;
|
const { api } = this.context;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -208,8 +209,16 @@ export default class CreateAccount extends Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (createType === 'fromNew' || createType === 'fromPhrase') {
|
if (createType === 'fromNew' || createType === 'fromPhrase') {
|
||||||
|
let phrase = this.state.phrase;
|
||||||
|
if (createType === 'fromPhrase' && windowsPhrase) {
|
||||||
|
phrase = phrase
|
||||||
|
.split(' ') // get the words
|
||||||
|
.map((word) => word === 'misjudged' ? word : `${word}\r`) // add \r after each (except last in dict)
|
||||||
|
.join(' '); // re-create string
|
||||||
|
}
|
||||||
|
|
||||||
return api.parity
|
return api.parity
|
||||||
.newAccountFromPhrase(this.state.phrase, this.state.password)
|
.newAccountFromPhrase(phrase, this.state.password)
|
||||||
.then((address) => {
|
.then((address) => {
|
||||||
this.setState({ address });
|
this.setState({ address });
|
||||||
return api.parity
|
return api.parity
|
||||||
@ -326,7 +335,7 @@ export default class CreateAccount extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangeDetails = (canCreate, { name, passwordHint, address, password, phrase, rawKey }) => {
|
onChangeDetails = (canCreate, { name, passwordHint, address, password, phrase, rawKey, windowsPhrase }) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
canCreate,
|
canCreate,
|
||||||
name,
|
name,
|
||||||
@ -334,6 +343,7 @@ export default class CreateAccount extends Component {
|
|||||||
address,
|
address,
|
||||||
password,
|
password,
|
||||||
phrase,
|
phrase,
|
||||||
|
windowsPhrase: windowsPhrase || false,
|
||||||
rawKey
|
rawKey
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user