mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 20:39:08 +01:00
Validating seed phrase in restoration flow (#11586)
This commit is contained in:
parent
a17c4462b4
commit
68c852f7c9
@ -1,6 +1,7 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
import { ethers } from 'ethers';
|
||||||
import {
|
import {
|
||||||
createNewVaultAndRestore,
|
createNewVaultAndRestore,
|
||||||
unMarkPasswordForgotten,
|
unMarkPasswordForgotten,
|
||||||
@ -10,6 +11,8 @@ import { DEFAULT_ROUTE } from '../../helpers/constants/routes';
|
|||||||
import TextField from '../../components/ui/text-field';
|
import TextField from '../../components/ui/text-field';
|
||||||
import Button from '../../components/ui/button';
|
import Button from '../../components/ui/button';
|
||||||
|
|
||||||
|
const { isValidMnemonic } = ethers.utils;
|
||||||
|
|
||||||
class RestoreVaultPage extends Component {
|
class RestoreVaultPage extends Component {
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
t: PropTypes.func,
|
t: PropTypes.func,
|
||||||
@ -38,6 +41,7 @@ class RestoreVaultPage extends Component {
|
|||||||
(seedPhrase || '').trim().toLowerCase().match(/\w+/gu)?.join(' ') || '';
|
(seedPhrase || '').trim().toLowerCase().match(/\w+/gu)?.join(' ') || '';
|
||||||
|
|
||||||
handleSeedPhraseChange(seedPhrase) {
|
handleSeedPhraseChange(seedPhrase) {
|
||||||
|
const { t } = this.context;
|
||||||
let seedPhraseError = null;
|
let seedPhraseError = null;
|
||||||
|
|
||||||
const wordCount = this.parseSeedPhrase(seedPhrase).split(/\s/u).length;
|
const wordCount = this.parseSeedPhrase(seedPhrase).split(/\s/u).length;
|
||||||
@ -45,7 +49,9 @@ class RestoreVaultPage extends Component {
|
|||||||
seedPhrase &&
|
seedPhrase &&
|
||||||
(wordCount % 3 !== 0 || wordCount < 12 || wordCount > 24)
|
(wordCount % 3 !== 0 || wordCount < 12 || wordCount > 24)
|
||||||
) {
|
) {
|
||||||
seedPhraseError = this.context.t('seedPhraseReq');
|
seedPhraseError = t('seedPhraseReq');
|
||||||
|
} else if (!isValidMnemonic(seedPhrase)) {
|
||||||
|
seedPhraseError = t('invalidSeedPhrase');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({ seedPhrase, seedPhraseError });
|
this.setState({ seedPhrase, seedPhraseError });
|
||||||
|
Loading…
Reference in New Issue
Block a user