From e547c97a447586fe5854334646977ba751979b07 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 4 Aug 2025 12:18:49 -0700 Subject: [PATCH] fix(Nostr Public Post): Posting to multiple Nostr relays --- .../app-body/nostr/nostr-post/public-post.js | 32 ++++++++++++------- src/config/index.js | 7 +++- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/components/app-body/nostr/nostr-post/public-post.js b/src/components/app-body/nostr/nostr-post/public-post.js index ec92d49..58f10f7 100644 --- a/src/components/app-body/nostr/nostr-post/public-post.js +++ b/src/components/app-body/nostr/nostr-post/public-post.js @@ -1,5 +1,5 @@ /* -Component for posting nostr information on kind 1. + Component for posting nostr information on kind 1. */ // Global npm libraries @@ -10,6 +10,9 @@ import { finalizeEvent } from 'nostr-tools/pure' import { Relay } from 'nostr-tools/relay' import { hexToBytes } from '@noble/hashes/utils' // already an installed dependency +// Local libraries +import config from '../../../../config' + function PublicPost (props) { const [accordionKey, setAccordionKey] = useState('0') const [onFetch, setOnFetch] = useState(false) @@ -44,9 +47,6 @@ function PublicPost (props) { // Convert private key to binary const privateKeyBin = hexToBytes(nostrKeyPair.privHex) - // Relay list - const psf = 'wss://nostr-relay.psfoundation.info' - // BCH address of the user. const bchAddr = bchWalletState.address @@ -63,16 +63,24 @@ function PublicPost (props) { const signedEvent = finalizeEvent(eventTemplate, privateKeyBin) console.log('signedEvent: ', signedEvent) - // Connect to a relay. - const relay = await Relay.connect(psf) - console.log(`connected to ${relay.url}`) + // Publish the post to each relay. + config.nostrRelays.map(async (relayUrl) => { + try { + // Connect to a relay. + const relay = await Relay.connect(relayUrl) + console.log(`connected to ${relay.url}`) - // Publish the message to the relay. - const result = await relay.publish(signedEvent) - console.log('result: ', result) + // Publish the message to the relay. + const result = await relay.publish(signedEvent) + console.log('result: ', result) + + // Close the connection to the relay. + relay.close() + } catch (err) { + console.warn(`Skipping publishing to ${relayUrl} due to error: ${err}`) + } + }) - // Close the connection to the relay. - relay.close() resetForm() setSuccessMsg('Post successfully published!') setOnFetch(false) diff --git a/src/config/index.js b/src/config/index.js index 5635d6d..98a881a 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -18,7 +18,12 @@ const config = { // dexServer: 'http://localhost:5700', nostrTopic: 'bch-dex-test-topic-02', - nostrRelay: 'wss://nostr-relay.psfoundation.info' + nostrRelay: 'wss://nostr-relay.psfoundation.info', + nostrRelays: [ + 'wss://nostr-relay.psfoundation.info', + 'wss://nos.lol', + 'wss://relay.damus.io' + ] }