small fix for nostr-connect

This commit is contained in:
hzrd149
2024-04-17 08:18:16 -05:00
parent 3868f7ec03
commit d27bcaffef
2 changed files with 6 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ import { isFilterEqual } from "../helpers/nostr/filter";
import ControlledObservable from "./controlled-observable"; import ControlledObservable from "./controlled-observable";
import { Filter, Relay, Subscription } from "nostr-tools"; import { Filter, Relay, Subscription } from "nostr-tools";
import { offlineMode } from "../services/offline-mode"; import { offlineMode } from "../services/offline-mode";
import RelaySet from "./relay-set";
export default class NostrMultiSubscription { export default class NostrMultiSubscription {
static INIT = "initial"; static INIT = "initial";
@@ -64,9 +65,9 @@ export default class NostrMultiSubscription {
} }
} }
const urlArr = Array.from(relays); const relaySet = RelaySet.from(relays);
for (const relay of this.relays) { for (const relay of this.relays) {
if (!urlArr.includes(relay.url)) { if (!relaySet.has(relay.url)) {
this.relays = this.relays.filter((r) => r !== relay); this.relays = this.relays.filter((r) => r !== relay);
this.handleRemoveRelay(relay); this.handleRemoveRelay(relay);
} }
@@ -111,7 +112,7 @@ export default class NostrMultiSubscription {
} }
publish(event: NostrEvent) { publish(event: NostrEvent) {
return Promise.all(this.relays.map((r) => r.publish(event))); return Promise.allSettled(this.relays.map((r) => r.publish(event)));
} }
open() { open() {
@@ -127,7 +128,7 @@ export default class NostrMultiSubscription {
} }
waitForAllConnection(): Promise<void> { waitForAllConnection(): Promise<void> {
if (offlineMode.value) return Promise.resolve(); if (offlineMode.value) return Promise.resolve();
return Promise.all(this.relays.filter((r) => !r.connected).map((r) => r.connect())).then((v) => void 0); return Promise.allSettled(this.relays.filter((r) => !r.connected).map((r) => r.connect())).then((v) => void 0);
} }
close() { close() {
if (this.state !== NostrMultiSubscription.OPEN) return this; if (this.state !== NostrMultiSubscription.OPEN) return this;

View File

@@ -75,7 +75,7 @@ export class NostrConnectClient {
supportedMethods: NostrConnectMethod[] | undefined; supportedMethods: NostrConnectMethod[] | undefined;
constructor(pubkey: string, relays: string[], secretKey?: string, provider?: string) { constructor(pubkey: string, relays: string[], secretKey?: string, provider?: string) {
this.sub = new NostrMultiSubscription(`${truncatedId(pubkey)}-nostr-connect`); this.sub = new NostrMultiSubscription(`${pubkey}-nostr-connect`);
this.pubkey = pubkey; this.pubkey = pubkey;
this.relays = relays; this.relays = relays;
this.provider = provider; this.provider = provider;