chore: fix issue in publishing sigit
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 45s
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 45s
This commit is contained in:
parent
006ed7b548
commit
01bb68d87b
@ -2,7 +2,7 @@ import { useCallback } from 'react'
|
|||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
|
|
||||||
import { bytesToHex } from '@noble/hashes/utils'
|
import { bytesToHex } from '@noble/hashes/utils'
|
||||||
import { NDKEvent, NDKFilter, NDKKind } from '@nostr-dev-kit/ndk'
|
import { NDKEvent, NDKFilter, NDKKind, NDKRelaySet } from '@nostr-dev-kit/ndk'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import {
|
import {
|
||||||
Event,
|
Event,
|
||||||
@ -35,14 +35,20 @@ import {
|
|||||||
getUserAppDataFromBlossom,
|
getUserAppDataFromBlossom,
|
||||||
hexToNpub,
|
hexToNpub,
|
||||||
parseJson,
|
parseJson,
|
||||||
|
SIGIT_RELAY,
|
||||||
unixNow,
|
unixNow,
|
||||||
uploadUserAppDataToBlossom
|
uploadUserAppDataToBlossom
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
|
|
||||||
export const useNDK = () => {
|
export const useNDK = () => {
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
const { ndk, fetchEvent, fetchEventsFromUserRelays, publish } =
|
const {
|
||||||
useNDKContext()
|
ndk,
|
||||||
|
fetchEvent,
|
||||||
|
fetchEventsFromUserRelays,
|
||||||
|
publish,
|
||||||
|
getNDKRelayList
|
||||||
|
} = useNDKContext()
|
||||||
const usersPubkey = useAppSelector((state) => state.auth.usersPubkey)
|
const usersPubkey = useAppSelector((state) => state.auth.usersPubkey)
|
||||||
const appData = useAppSelector((state) => state.userAppData)
|
const appData = useAppSelector((state) => state.userAppData)
|
||||||
const processedEvents = useAppSelector(
|
const processedEvents = useAppSelector(
|
||||||
@ -448,16 +454,33 @@ export const useNDK = () => {
|
|||||||
|
|
||||||
// Publish the notification event to the recipient's read relays
|
// Publish the notification event to the recipient's read relays
|
||||||
const ndkEvent = new NDKEvent(ndk, wrappedEvent)
|
const ndkEvent = new NDKEvent(ndk, wrappedEvent)
|
||||||
await publish(ndkEvent).catch((err) => {
|
|
||||||
// Log an error if publishing the notification event fails
|
const ndkRelayList = await getNDKRelayList(receiver)
|
||||||
console.log(
|
|
||||||
`An error occurred while publishing notification event for ${hexToNpub(receiver)}`,
|
const readRelayUrls = [...ndkRelayList.readRelayUrls]
|
||||||
err
|
if (!readRelayUrls.includes(SIGIT_RELAY)) {
|
||||||
)
|
readRelayUrls.push(SIGIT_RELAY)
|
||||||
throw err
|
}
|
||||||
})
|
|
||||||
|
await ndkEvent
|
||||||
|
.publish(NDKRelaySet.fromRelayUrls(readRelayUrls, ndk, true))
|
||||||
|
.then((publishedOnRelays) => {
|
||||||
|
if (publishedOnRelays.size === 0) {
|
||||||
|
throw new Error('Could not publish to any relay')
|
||||||
|
}
|
||||||
|
|
||||||
|
return publishedOnRelays
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
// Log an error if publishing the notification event fails
|
||||||
|
console.log(
|
||||||
|
`An error occurred while publishing notification event for ${hexToNpub(receiver)}`,
|
||||||
|
err
|
||||||
|
)
|
||||||
|
throw err
|
||||||
|
})
|
||||||
},
|
},
|
||||||
[ndk, publish, usersPubkey]
|
[ndk, usersPubkey, getNDKRelayList]
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user