mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex-taker-v2.git
synced 2026-09-21 16:52:01 -07:00
fix(Nostr Profile Post): Posting to multiple relays
This commit is contained in:
@@ -11,6 +11,9 @@ import { Relay } from 'nostr-tools/relay'
|
|||||||
import { hexToBytes } from '@noble/hashes/utils' // already an installed dependency
|
import { hexToBytes } from '@noble/hashes/utils' // already an installed dependency
|
||||||
import { RelayPool } from 'nostr'
|
import { RelayPool } from 'nostr'
|
||||||
|
|
||||||
|
// Local libraries
|
||||||
|
import config from '../../../../config'
|
||||||
|
|
||||||
function ProfilePost (props) {
|
function ProfilePost (props) {
|
||||||
const { bchWalletState } = props.appData
|
const { bchWalletState } = props.appData
|
||||||
const [accordionKey, setAccordionKey] = useState(null)
|
const [accordionKey, setAccordionKey] = useState(null)
|
||||||
@@ -90,7 +93,7 @@ function ProfilePost (props) {
|
|||||||
const privateKeyBin = hexToBytes(nostrKeyPair.privHex)
|
const privateKeyBin = hexToBytes(nostrKeyPair.privHex)
|
||||||
|
|
||||||
// Relay list
|
// Relay list
|
||||||
const psf = 'wss://nostr-relay.psfoundation.info'
|
// const psf = 'wss://nostr-relay.psfoundation.info'
|
||||||
|
|
||||||
const formDataString = JSON.stringify(formData)
|
const formDataString = JSON.stringify(formData)
|
||||||
|
|
||||||
@@ -107,16 +110,24 @@ function ProfilePost (props) {
|
|||||||
const signedEvent = finalizeEvent(eventTemplate, privateKeyBin)
|
const signedEvent = finalizeEvent(eventTemplate, privateKeyBin)
|
||||||
console.log('signedEvent: ', signedEvent)
|
console.log('signedEvent: ', signedEvent)
|
||||||
|
|
||||||
// Connect to a relay.
|
// Publish the post to each relay.
|
||||||
const relay = await Relay.connect(psf)
|
config.nostrRelays.map(async (relayUrl) => {
|
||||||
console.log(`connected to ${relay.url}`)
|
try {
|
||||||
|
// Connect to a relay.
|
||||||
|
const relay = await Relay.connect(relayUrl)
|
||||||
|
console.log(`connected to ${relay.url}`)
|
||||||
|
|
||||||
// Publish the message to the relay.
|
// Publish the message to the relay.
|
||||||
const result = await relay.publish(signedEvent)
|
const result = await relay.publish(signedEvent)
|
||||||
console.log('result: ', result)
|
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()
|
|
||||||
setSuccessMsg('Post successfully published!')
|
setSuccessMsg('Post successfully published!')
|
||||||
setOnFetch(false)
|
setOnFetch(false)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user