This commit is contained in:
Paul Miller
2024-03-20 16:33:41 -05:00
parent 33b8190a2d
commit 52d89a2617
37 changed files with 2044 additions and 2489 deletions

View File

@@ -0,0 +1,46 @@
import { MutinyWallet } from "@mutinywallet/mutiny-wasm";
import { SecureStoragePlugin } from "capacitor-secure-storage-plugin";
import { createSignal, Show } from "solid-js";
import { Button, InfoBox, SimpleInput } from "~/components";
export function ImportNsecForm() {
const [nsec, setNsec] = createSignal("");
const [saving, setSaving] = createSignal(false);
const [error, setError] = createSignal<string | undefined>();
async function saveNsec() {
setSaving(true);
setError(undefined);
const trimmedNsec = nsec().trim();
try {
const npub = await MutinyWallet.nsec_to_npub(trimmedNsec);
if (!npub) {
throw new Error("Invalid nsec");
}
await SecureStoragePlugin.set({ key: "nsec", value: trimmedNsec });
// TODO: right now we need a reload to set the nsec
window.location.href = "/";
} catch (e) {
console.error(e);
setError("Invalid nsec");
}
setSaving(false);
}
return (
<>
<SimpleInput
value={nsec()}
onInput={(e) => setNsec(e.currentTarget.value)}
placeholder={`Nostr private key (starts with "nsec")`}
/>
<Button layout="full" onClick={saveNsec} loading={saving()}>
Import
</Button>
<Show when={error()}>
<InfoBox accent="red">{error()}</InfoBox>
</Show>
</>
);
}