Skip to content

Commit b076b3b

Browse files
[DDW-409] Improve mnemonic validaiton during wallet backup/creation
1 parent 67acd6c commit b076b3b

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

source/renderer/app/components/wallet/WalletBackupDialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class WalletBackupDialog extends Component<Props> {
8484
<WalletRecoveryPhraseEntryDialog
8585
isTermOfflineAccepted={isTermOfflineAccepted}
8686
enteredPhrase={enteredPhrase}
87+
recoveryPhrase={recoveryPhrase}
8788
canFinishBackup={canFinishBackup}
8889
isTermRecoveryAccepted={isTermRecoveryAccepted}
8990
isValid={isValid}

source/renderer/app/components/wallet/backup-recovery/WalletRecoveryPhraseEntryDialog.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import suggestedMnemonics from '../../../../../common/config/crypto/valid-words.
1010
import { isValidMnemonic } from '../../../../../common/config/crypto/decrypt';
1111
import ReactToolboxMobxForm from '../../../utils/ReactToolboxMobxForm';
1212
import { validateMnemonics } from '../../../utils/validations';
13-
import WalletRecoveryPhraseMnemonic from './WalletRecoveryPhraseMnemonic';
1413
import DialogCloseButton from '../../widgets/DialogCloseButton';
1514
import DialogBackButton from '../../widgets/DialogBackButton';
1615
import Dialog from '../../widgets/Dialog';
@@ -68,6 +67,7 @@ const messages = defineMessages({
6867
},
6968
});
7069
type Props = {
70+
recoveryPhrase: string;
7171
enteredPhrase: Array<string>;
7272
isValid: boolean;
7373
isTermOfflineAccepted: boolean;
@@ -101,6 +101,13 @@ class WalletRecoveryPhraseEntryDialog extends Component<Props> {
101101
this.props.onUpdateVerificationPhrase({
102102
verificationPhrase: enteredWords,
103103
});
104+
105+
if (this.props.recoveryPhrase !== enteredWords.join(' ')) {
106+
return this.context.intl.formatMessage(
107+
messages.recoveryPhraseInvalidMnemonics
108+
);
109+
}
110+
104111
return validateMnemonics({
105112
requiredWords: WALLET_RECOVERY_PHRASE_WORD_COUNT,
106113
providedWords: field.value,
@@ -120,11 +127,20 @@ class WalletRecoveryPhraseEntryDialog extends Component<Props> {
120127
vjf: vjf(),
121128
},
122129
options: {
130+
showErrorsOnChange: false,
123131
validateOnChange: true,
124132
},
125133
}
126134
);
127135

136+
handleSubmit = () => {
137+
this.form.submit({
138+
onSuccess: () => {
139+
this.props.onFinishBackup();
140+
},
141+
});
142+
};
143+
128144
render() {
129145
const { form } = this;
130146
const { intl } = this.context;
@@ -139,7 +155,7 @@ class WalletRecoveryPhraseEntryDialog extends Component<Props> {
139155
canFinishBackup,
140156
onRestartBackup,
141157
onCancelBackup,
142-
onFinishBackup,
158+
recoveryPhrase,
143159
} = this.props;
144160
const recoveryPhraseField = form.$('recoveryPhrase');
145161
const dialogClasses = classnames([
@@ -152,11 +168,17 @@ class WalletRecoveryPhraseEntryDialog extends Component<Props> {
152168
) : (
153169
<LoadingSpinner />
154170
);
171+
const canSubmit =
172+
(!recoveryPhraseField.error &&
173+
recoveryPhraseField.value.length === recoveryPhrase.split(' ').length &&
174+
recoveryPhraseField.value.every((word) => word)) ||
175+
canFinishBackup;
176+
155177
const actions = [
156178
{
157179
label: buttonLabel,
158-
onClick: onFinishBackup,
159-
disabled: !canFinishBackup,
180+
onClick: this.handleSubmit,
181+
disabled: !canSubmit,
160182
primary: true,
161183
},
162184
];

0 commit comments

Comments
 (0)