chore: improve nsec input, fix copy nsec

This commit is contained in:
Roland Bewick
2023-08-28 18:20:28 +07:00
parent afd3c9a232
commit ce24d0e9c2
2 changed files with 10 additions and 6 deletions

View File

@ -45,13 +45,16 @@ export function LoginSignup({ close }: { close: () => void }) {
function doLoginNsec() {
try {
const nsec = prompt("nsec");
let nsec = prompt("Enter your nsec\nWARNING: THIS IS NOT RECOMMENDED. DO NOT IMPORT ANY KEYS YOU CARE ABOUT");
if (!nsec) {
throw new Error("no nsec provided");
}
if (nsec.startsWith("nsec")) {
const {words} = bech32.decode(nsec, 5000);
const data = new Uint8Array(bech32.fromWords(words));
Login.loginWithPrivateKey(bytesToHex(data));
nsec = bytesToHex(data);
}
Login.loginWithPrivateKey(nsec);
close();
} catch (e) {
console.error(e);
@ -134,7 +137,7 @@ export function LoginSignup({ close }: { close: () => void }) {
className="btn btn-primary"
onClick={doLoginNsec}
>
Enter Nsec (INSECURE)
Enter Nsec
</button>
{error && <b className="error">{error}</b>}
</>

View File

@ -4,6 +4,7 @@ import "./settings-page.css";
import React from "react";
import { Button } from "@getalby/bitcoin-connect-react";
import Copy from "element/copy";
import { hexToBech32 } from "@snort/shared";
export function SettingsPage() {
const navigate = useNavigate();
@ -26,7 +27,7 @@ export function SettingsPage() {
</div>}
{login?.privateKey && <div className="private-key">
<p>Private key</p>
<Copy text={login.privateKey} hideText />
<Copy text={hexToBech32('nsec', login.privateKey)} hideText />
</div>}
<h1>Zaps</h1>