small nip-07 fixes

This commit is contained in:
hzrd149
2023-03-15 13:38:39 -05:00
parent 53055985df
commit 2fd2f7df87
2 changed files with 23 additions and 9 deletions

View File

@@ -3,10 +3,9 @@ import { DraftNostrEvent, NostrEvent } from "./nostr-event";
declare global { declare global {
interface Window { interface Window {
nostr?: { nostr?: {
enabled: boolean;
getPublicKey: () => Promise<string> | string; getPublicKey: () => Promise<string> | string;
signEvent: (event: DraftNostrEvent) => Promise<NostrEvent> | NostrEvent; signEvent: (event: DraftNostrEvent) => Promise<NostrEvent> | NostrEvent;
getRelays: () => Record<string, { read: boolean; write: boolean }> | string[]; getRelays?: () => Record<string, { read: boolean; write: boolean }> | string[];
nip04?: { nip04?: {
encrypt: (pubkey: string, plaintext: string) => Promise<string> | string; encrypt: (pubkey: string, plaintext: string) => Promise<string> | string;
decrypt: (pubkey: string, ciphertext: string) => Promise<string> | string; decrypt: (pubkey: string, ciphertext: string) => Promise<string> | string;

View File

@@ -1,4 +1,15 @@
import { Alert, AlertDescription, AlertIcon, AlertTitle, Box, Button, Flex, Heading, Spinner } from "@chakra-ui/react"; import {
Alert,
AlertDescription,
AlertIcon,
AlertTitle,
Box,
Button,
Flex,
Heading,
Spinner,
useToast,
} from "@chakra-ui/react";
import { useState } from "react"; import { useState } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import AccountCard from "./components/account-card"; import AccountCard from "./components/account-card";
@@ -7,6 +18,7 @@ import accountService from "../../services/account";
export default function LoginStartView() { export default function LoginStartView() {
const navigate = useNavigate(); const navigate = useNavigate();
const toast = useToast();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const accounts = useSubject(accountService.accounts); const accounts = useSubject(accountService.accounts);
@@ -19,7 +31,7 @@ export default function LoginStartView() {
if (!accountService.hasAccount(pubkey)) { if (!accountService.hasAccount(pubkey)) {
let relays: string[] = []; let relays: string[] = [];
const extRelays = await window.nostr.getRelays(); const extRelays = (await window.nostr.getRelays?.()) ?? [];
if (Array.isArray(extRelays)) { if (Array.isArray(extRelays)) {
relays = extRelays; relays = extRelays;
} else { } else {
@@ -36,6 +48,11 @@ export default function LoginStartView() {
accountService.switchAccount(pubkey); accountService.switchAccount(pubkey);
} catch (e) {} } catch (e) {}
setLoading(false); setLoading(false);
} else {
toast({
status: "warning",
title: "Cant find extension",
});
} }
}; };
@@ -50,11 +67,9 @@ export default function LoginStartView() {
<AlertDescription>There are bugs and things will break.</AlertDescription> <AlertDescription>There are bugs and things will break.</AlertDescription>
</Box> </Box>
</Alert> </Alert>
{window.nostr && ( <Button onClick={loginWithExtension} colorScheme="brand">
<Button onClick={loginWithExtension} colorScheme="brand"> Use browser extension (NIP-07)
Use browser extension (NIP-07) </Button>
</Button>
)}
<Button onClick={() => navigate("./nip05")}>Login with Nip-05 Id</Button> <Button onClick={() => navigate("./nip05")}>Login with Nip-05 Id</Button>
<Button onClick={() => navigate("./npub")}>Login with pubkey key (npub)</Button> <Button onClick={() => navigate("./npub")}>Login with pubkey key (npub)</Button>
<Button onClick={() => navigate("./nsec")}>Login with secret key (nsec)</Button> <Button onClick={() => navigate("./nsec")}>Login with secret key (nsec)</Button>