-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2454c67
commit 8063c2a
Showing
9 changed files
with
102 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { MutinyWallet } from "@mutinywallet/mutiny-wasm"; | ||
import { useNavigate } from "@solidjs/router"; | ||
import { SecureStoragePlugin } from "capacitor-secure-storage-plugin"; | ||
import { createSignal, Show } from "solid-js"; | ||
|
||
import { | ||
Button, | ||
ButtonLink, | ||
DefaultMain, | ||
InfoBox, | ||
SimpleInput | ||
} from "~/components"; | ||
|
||
export function ImportProfile() { | ||
const [nsec, setNsec] = createSignal(""); | ||
const [saving, setSaving] = createSignal(false); | ||
const [error, setError] = createSignal<string | undefined>(); | ||
|
||
const navigate = useNavigate(); | ||
|
||
function handleSkip() { | ||
localStorage.setItem("profile_setup_stage", "skipped"); | ||
navigate("/"); | ||
} | ||
|
||
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 ( | ||
<DefaultMain> | ||
<div class="mx-auto flex max-w-[20rem] flex-1 flex-col items-center gap-4"> | ||
<div class="flex-1" /> | ||
<h1 class="text-3xl font-semibold">Import nostr profile</h1> | ||
<p class="text-center text-xl font-light text-neutral-200"> | ||
Login with an existing nostr account. | ||
<br /> | ||
</p> | ||
<div class="flex-1" /> | ||
<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> | ||
<div class="flex-1" /> | ||
<div class="flex flex-col items-center"> | ||
<ButtonLink href="/newprofile" intent="text"> | ||
Create new nostr profile | ||
</ButtonLink> | ||
<Button onClick={handleSkip} intent="text"> | ||
Skip for now | ||
</Button> | ||
</div> | ||
<div class="flex-1" /> | ||
</div> | ||
</DefaultMain> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters