feat: add basic settings page

This commit is contained in:
Roland Bewick
2023-08-26 22:26:49 +07:00
parent 7cba67e4c1
commit afd3c9a232
10 changed files with 270 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import Copy from "./copy";
import { hexToBech32, openFile } from "utils";
import { VoidApi } from "@void-cat/api";
import { LoginType } from "login";
import { bech32 } from "@scure/base";
enum Stage {
Login = 0,
@ -41,6 +42,26 @@ export function LoginSignup({ close }: { close: () => void }) {
}
}
}
function doLoginNsec() {
try {
const nsec = prompt("nsec");
if (!nsec) {
throw new Error("no nsec provided");
}
const {words} = bech32.decode(nsec, 5000);
const data = new Uint8Array(bech32.fromWords(words));
Login.loginWithPrivateKey(bytesToHex(data));
close();
} catch (e) {
console.error(e);
if (e instanceof Error) {
setError(e.message);
} else {
setError(e as string);
}
}
}
function createAccount() {
const newKey = bytesToHex(schnorr.utils.randomPrivateKey());
@ -108,6 +129,13 @@ export function LoginSignup({ close }: { close: () => void }) {
>
Create Account
</button>
<button
type="button"
className="btn btn-primary"
onClick={doLoginNsec}
>
Enter Nsec (INSECURE)
</button>
{error && <b className="error">{error}</b>}
</>
);