Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Wallet): check mnemonic via bip39.validateMnemonic #1005

Merged
merged 7 commits into from
Mar 5, 2024
13 changes: 3 additions & 10 deletions packages/screens/Wallet/Screens/ImportWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Secp256k1HdWallet } from "@cosmjs/amino";
import { validateMnemonic } from "bip39";
import React, { useState } from "react";
import { TextInput, View } from "react-native";
import { useSelector } from "react-redux";
Expand Down Expand Up @@ -105,21 +106,13 @@ export const ImportWallet: ScreenFC<"ImportWallet"> = ({ navigation }) => {
<SpacerColumn size={2} />
<CustomButton
onPress={(_, navigation) => {
console.log(localPhrase);
if (!localPhrase) {
if (!localPhrase || !validateMnemonic(localPhrase)) {
alert("Invalid mnemonic");
omniwired marked this conversation as resolved.
Show resolved Hide resolved
return;
}
(async () => {
await setMnemonic(localPhrase, maxIndex + 1);
const native = await getNativeWallet("TORI", maxIndex + 1);

if (
(native as unknown as string) === "bad mnemonic" ||
!native
) {
alert("Invalid mnemonic");
return;
}
setWallet(native);
})();
if (wallet) {
Expand Down
Loading