Skip to content

Commit

Permalink
fix bug with hd path, add passphrase
Browse files Browse the repository at this point in the history
  • Loading branch information
kieled committed Aug 19, 2024
1 parent bda613f commit 637d6c2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/background/services/keyring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class KeyringService {
hideRoot,
restoreFrom,
hdPath,
passphrase = undefined,
passphrase,
network,
}: INewWalletProps) {
let keyring: HDPrivateKey | HDSimpleKey;
Expand Down
3 changes: 2 additions & 1 deletion src/shared/locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
"recover": "Recover",
"invalid_private_key_error": "Invalid private key"
},
"hd_path": "Hd path"
"hd_path": "Hd path",
"passphrase": "Passphrase"
},
"receive": {
"click_to_copy": "Click to copy",
Expand Down
22 changes: 17 additions & 5 deletions src/ui/pages/main/new-wallet/restore-mnemonic/component.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import s from "./styles.module.scss";
import { useCreateNewWallet } from "@/ui/hooks/wallet";
import { useWalletState } from "@/ui/states/walletState";
import { useMemo, useState } from "react";
import cn from "classnames";
import { useNavigate } from "react-router-dom";
import toast from "react-hot-toast";
import SwitchAddressType from "@/ui/components/switch-address-type";
import SelectWithHint from "@/ui/components/select-hint/component";
import { t } from "i18next";
import { AddressType } from "bellhdw";
import { TailSpin } from "react-loading-icons";
import Switch from "@/ui/components/switch";
import { useAppState } from "@/ui/states/appState";
Expand All @@ -21,12 +19,14 @@ const selectOptions = [
label: "Default",
value: DEFAULT_HD_PATH,
lecacyDerivation: false,
passphrase: "bells",
},
{
label: "Ordinals",
value: "m/44'/3'/0'/0/0",
lecacyDerivation: true,
isLegacySwitchLocked: true,
passphrase: "",
},
{
label: "Custom",
Expand All @@ -36,9 +36,11 @@ const selectOptions = [

const RestoreMnemonic = () => {
const [step, setStep] = useState(1);
const { updateWalletState } = useWalletState(ss(["updateWalletState"]));
const [addressType, setAddressType] = useState(ADDRESS_TYPES[0].value);
const [hdPath, setHdPath] = useState<string | undefined>(DEFAULT_HD_PATH);
const [passphrase, setPassphrase] = useState(
selectOptions[0].passphrase ?? ""
);
const [mnemonicPhrase, setMnemonicPhrase] = useState<(string | undefined)[]>(
new Array(12).fill("")
);
Expand Down Expand Up @@ -77,6 +79,8 @@ const RestoreMnemonic = () => {
addressType,
hideRoot: !showRootAcc,
network,
hdPath,
passphrase,
});
navigate("/home");
} catch (e) {
Expand Down Expand Up @@ -131,11 +135,10 @@ const RestoreMnemonic = () => {
/>

<div className="w-full flex flex-col gap-2">
<h5 className="uppercase text-sm">{t("new_wallet.hd_path")}</h5>
<div className="flex w-full gap-2 text-sm">
<input
disabled={selectedOption.name !== "Custom"}
className={cn("input w-full mt-1", s.input)}
className={cn("input w-full mt-1 py-1", s.input)}
placeholder={t("new_wallet.hd_path")}
value={hdPath ?? ""}
onChange={(e) =>
Expand All @@ -157,6 +160,7 @@ const RestoreMnemonic = () => {
setShowRootAcc(false);
}
setHdPath(v.value);
setPassphrase(v.passphrase ?? "");
}
}}
values={selectOptions.map((i) => ({
Expand All @@ -165,6 +169,14 @@ const RestoreMnemonic = () => {
className="w-28"
/>
</div>

<input
disabled={selectedOption.name !== "Custom"}
className={cn(s.input, "input w-full py-2")}
placeholder={t("new_wallet.passphrase")}
value={passphrase}
onChange={(e) => setPassphrase(e.target.value)}
/>
</div>

<Switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
}

.input {
@apply py-1 disabled:cursor-not-allowed disabled:opacity-50;
@apply disabled:cursor-not-allowed disabled:opacity-50;
}
4 changes: 0 additions & 4 deletions src/ui/pages/main/settings/language/styles.module.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.languages {
@apply w-full gap-3 flex flex-col p-6 h-full;

> * {
@apply min-h-40;
}
}

0 comments on commit 637d6c2

Please sign in to comment.