Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
feat: add error for 12-word secret keys, closes #178
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Sep 25, 2020
1 parent f5d817f commit 8521c65
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/pages/onboarding/03-restore-wallet/restore-wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,24 @@ export const RestoreWallet: React.FC = () => {

const handleSecretKeyRestore = async (e: React.FormEvent) => {
e.preventDefault();
if (mnemonic.split(' ').length !== 24) {
setError('The Stacks Wallet can only be used with a 24-word Secret Key');

const mnemonicLength = mnemonic.trim().split(' ').length;
if (mnemonicLength === 12) {
setError(
'You’ve entered a 12-word Secret Key. Please enter the 24-word Secret Key you received when creating this wallet.'
);
return;
}
if (mnemonicLength !== 24) {
setError('The Stacks Wallet can only be used with 24-word Secret Keys');
return;
}
const [error] = await safeAwait(deriveRootKeychainFromMnemonic(mnemonic));
if (error) {
setError('Not a valid bip39 mnemonic');
return;
}
dispatch(persistMnemonic(mnemonic));
dispatch(persistMnemonic(mnemonic.trim()));
history.push(routes.SET_PASSWORD);
};

Expand All @@ -64,7 +72,10 @@ export const RestoreWallet: React.FC = () => {
mt="base-tight"
minHeight="88px"
placeholder="24-word Secret Key"
style={{ resize: 'none' }}
style={{
resize: 'none',
border: error ? '2px solid #D4001A' : '',
}}
/>
{error && (
<ErrorLabel>
Expand Down

0 comments on commit 8521c65

Please sign in to comment.