chore: fix issue in publishing sigit
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 45s

This commit is contained in:
daniyal 2024-12-28 00:44:21 +05:00
parent 006ed7b548
commit 01bb68d87b

View File

@ -2,7 +2,7 @@ import { useCallback } from 'react'
import { toast } from 'react-toastify'
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 {
Event,
@ -35,14 +35,20 @@ import {
getUserAppDataFromBlossom,
hexToNpub,
parseJson,
SIGIT_RELAY,
unixNow,
uploadUserAppDataToBlossom
} from '../utils'
export const useNDK = () => {
const dispatch = useAppDispatch()
const { ndk, fetchEvent, fetchEventsFromUserRelays, publish } =
useNDKContext()
const {
ndk,
fetchEvent,
fetchEventsFromUserRelays,
publish,
getNDKRelayList
} = useNDKContext()
const usersPubkey = useAppSelector((state) => state.auth.usersPubkey)
const appData = useAppSelector((state) => state.userAppData)
const processedEvents = useAppSelector(
@ -448,16 +454,33 @@ export const useNDK = () => {
// Publish the notification event to the recipient's read relays
const ndkEvent = new NDKEvent(ndk, wrappedEvent)
await publish(ndkEvent).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
})
const ndkRelayList = await getNDKRelayList(receiver)
const readRelayUrls = [...ndkRelayList.readRelayUrls]
if (!readRelayUrls.includes(SIGIT_RELAY)) {
readRelayUrls.push(SIGIT_RELAY)
}
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 {