Unverified Commit a93ef8a8 authored by Thibaut Sardan's avatar Thibaut Sardan Committed by GitHub
Browse files

Merge pull request #282 from paritytech/tbaut-no-empty-seed

Don't allow empty seed phrase recovery
parents 882349dd 97053acf
Pipeline #44677 failed with stage
in 14 seconds
......@@ -108,29 +108,41 @@ class AccountRecoverView extends React.Component {
onPress={() => {
const validation = validateSeed(selected.seed, selected.validBip39Seed);
if (!validation.valid) {
Alert.alert(
'Warning:',
`${validation.reason}`,
[
{
text: 'I understand the risks',
style: 'default',
onPress: () => {
this.props.navigation.navigate('AccountPin', {
isWelcome: this.props.navigation.getParam(
'isWelcome'
),
isNew: true
});
if (validation.accountRecoveryAllowed){
return Alert.alert(
'Warning:',
`${validation.reason}`,
[
{
text: 'I understand the risks',
style: 'default',
onPress: () => {
this.props.navigation.navigate('AccountPin', {
isWelcome: this.props.navigation.getParam(
'isWelcome'
),
isNew: true
});
}
},
{
text: 'Back',
style: 'cancel'
}
},
{
text: 'Back',
style: 'cancel'
}
]
);
return;
]
);
} else {
return Alert.alert(
'Error:',
`${validation.reason}`,
[
{
text: 'Back',
style: 'cancel'
}
]
);
}
}
this.props.navigation.navigate('AccountPin', {
isWelcome: this.props.navigation.getParam('isWelcome'),
......
......@@ -85,11 +85,15 @@ export default class AccountsStore extends Container<AccountsState> {
async submitNew(pin) {
const account = this.state.newAccount;
await this.save(account, pin);
this.setState({
accounts: this.state.accounts.set(accountId(account), account),
newAccount: empty()
});
// only save the account if the seed isn't empty
if (account.seed) {
await this.save(account, pin);
this.setState({
accounts: this.state.accounts.set(accountId(account), account),
newAccount: empty()
});
}
}
update(accountUpdate) {
......
......@@ -31,8 +31,9 @@ export function empty(account = {}) {
export function validateSeed(seed, validBip39Seed) {
if (seed.length === 0) {
return {
valid: false,
reason: `You're trying to recover from an empty seed phrase`
accountRecoveryAllowed: false,
reason: `A seed phrase is required.`,
valid: false
};
}
const words = seed.split(' ');
......@@ -40,21 +41,24 @@ export function validateSeed(seed, validBip39Seed) {
for (let word of words) {
if (word === '') {
return {
valid: false,
reason: `Extra whitespace found`
accountRecoveryAllowed: true,
reason: `Extra whitespace found.`,
valid: false
};
}
}
if (!validBip39Seed) {
return {
valid: false,
reason: `This recovery phrase will be treated as a legacy Parity brain wallet`
accountRecoveryAllowed: true,
reason: `This recovery phrase will be treated as a legacy Parity brain wallet.`,
valid: false
};
}
return {
valid: true,
reason: null
reason: null,
valid: true
};
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment