Change nostr keys on the fly

This commit is contained in:
benthecarman
2024-03-28 18:00:06 -05:00
committed by Paul Miller
parent 115f11aa6c
commit 183449eb13

View File

@@ -1,10 +1,14 @@
import { MutinyWallet } from "@mutinywallet/mutiny-wasm"; import { MutinyWallet } from "@mutinywallet/mutiny-wasm";
import { useNavigate } from "@solidjs/router";
import { SecureStoragePlugin } from "capacitor-secure-storage-plugin"; import { SecureStoragePlugin } from "capacitor-secure-storage-plugin";
import { createSignal, Show } from "solid-js"; import { createSignal, Show } from "solid-js";
import { Button, InfoBox, SimpleInput } from "~/components"; import { Button, InfoBox, SimpleInput } from "~/components";
import { useMegaStore } from "~/state/megaStore";
export function ImportNsecForm() { export function ImportNsecForm() {
const [state, _actions] = useMegaStore();
const navigate = useNavigate();
const [nsec, setNsec] = createSignal(""); const [nsec, setNsec] = createSignal("");
const [saving, setSaving] = createSignal(false); const [saving, setSaving] = createSignal(false);
const [error, setError] = createSignal<string | undefined>(); const [error, setError] = createSignal<string | undefined>();
@@ -19,8 +23,13 @@ export function ImportNsecForm() {
throw new Error("Invalid nsec"); throw new Error("Invalid nsec");
} }
await SecureStoragePlugin.set({ key: "nsec", value: trimmedNsec }); await SecureStoragePlugin.set({ key: "nsec", value: trimmedNsec });
// TODO: right now we need a reload to set the nsec
window.location.href = "/"; const new_npub = await state.mutiny_wallet?.change_nostr_keys(
trimmedNsec,
undefined
);
console.log("Changed to new npub: ", new_npub);
navigate("/");
} catch (e) { } catch (e) {
console.error(e); console.error(e);
setError("Invalid nsec"); setError("Invalid nsec");