Skip to content

Commit

Permalink
wallet-ext: disable importing invalid mnemonic
Browse files Browse the repository at this point in the history
  • Loading branch information
pchrysochoidis committed May 17, 2022
1 parent 6b5996b commit 8dee75b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions wallet/src/shared/cryptography/mnemonics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ export function normalizeMnemonics(mnemonics: string): string {
.map((part) => part.toLowerCase())
.join(' ');
}

export const validateMnemonics = bip39.validateMnemonic;
2 changes: 2 additions & 0 deletions wallet/src/ui/app/pages/initialize/import/Import.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
font-size: 13px;
color: #b10000;
font-weight: 400;
min-height: 1em;
line-height: 1;
}
10 changes: 6 additions & 4 deletions wallet/src/ui/app/pages/initialize/import/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { validateMnemonic } from 'bip39-light';
import { useCallback, useState } from 'react';

import { normalizeMnemonics } from '_shared/cryptography/mnemonics';
import {
normalizeMnemonics,
validateMnemonics,
} from '_shared/cryptography/mnemonics';
import { useAppDispatch, useAppSelector } from '_src/ui/app/hooks';
import { createMnemonic, setMnemonic } from '_src/ui/app/redux/slices/account';

Expand All @@ -24,7 +26,7 @@ const ImportPage = () => {
const onHandleInputBlur = useCallback(() => {
const adjMnemonic = normalizeMnemonics(mnemonicInput);
setMnemonicInput(adjMnemonic);
setMnemonicValid(validateMnemonic(adjMnemonic));
setMnemonicValid(validateMnemonics(adjMnemonic));
}, [mnemonicInput]);
const createInProgress = useAppSelector(({ account }) => account.creating);
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -52,7 +54,7 @@ const ImportPage = () => {
<button
type="button"
className="btn"
disabled={!mnemonicInput || createInProgress}
disabled={!mnemonicInput || createInProgress || !mnemonicValid}
onClick={onHandleImport}
>
Import
Expand Down

0 comments on commit 8dee75b

Please sign in to comment.