Let signer be undefined if there's no way to sign

This commit is contained in:
Alex Gleason
2024-02-11 12:45:33 -06:00
parent 8412a9869f
commit 7f74ec80af
4 changed files with 18 additions and 71 deletions

View File

@ -1,5 +1,5 @@
import { NiceRelay } from 'nostr-machina';
import { type Event } from 'nostr-tools';
import { type NostrEvent } from 'nspec';
import { useEffect, useMemo } from 'react';
import { signer } from 'soapbox/features/nostr/sign';
@ -14,13 +14,13 @@ function useSignerStream() {
const pubkey = instance.nostr?.pubkey;
const relay = useMemo(() => {
if (relayUrl) {
if (relayUrl && signer) {
return new NiceRelay(relayUrl);
}
}, [relayUrl]);
}, [relayUrl, !!signer]);
async function handleConnectEvent(event: Event) {
if (!relay || !pubkey) return;
async function handleConnectEvent(event: NostrEvent) {
if (!relay || !pubkey || !signer) return;
const decrypted = await signer.nip04!.decrypt(pubkey, event.content);
const reqMsg = jsonSchema.pipe(connectRequestSchema).safeParse(decrypted);
@ -45,8 +45,8 @@ function useSignerStream() {
relay.send(['EVENT', respEvent]);
}
async function handleWalletEvent(event: Event) {
if (!relay || !pubkey) return;
async function handleWalletEvent(event: NostrEvent) {
if (!relay || !pubkey || !signer) return;
const decrypted = await signer.nip04!.decrypt(pubkey, event.content);