chore: use-ndk #283

Merged
s merged 18 commits from use-ndk into staging 2025-01-06 11:10:49 +00:00
Showing only changes of commit 01bb68d87b - Show all commits

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,7 +454,24 @@ export const useNDK = () => {
// Publish the notification event to the recipient's read relays
const ndkEvent = new NDKEvent(ndk, wrappedEvent)
await publish(ndkEvent).catch((err) => {
const ndkRelayList = await getNDKRelayList(receiver)
const readRelayUrls = [...ndkRelayList.readRelayUrls]
Outdated
Review

Had this error after completing a sigit (error types here don't indicate undefined to be a possibility) and after timestamp upgrades triggered.

TypeError: Cannot read properties of undefined (reading 'readRelayUrls')
    at useNDK.ts:460:46
    at async Promise.all (:5173/index 0)
    at async upgradeT (index.tsx:383:11)```
Had this error after completing a sigit (error types here don't indicate `undefined` to be a possibility) and after timestamp upgrades triggered. ``` TypeError: Cannot read properties of undefined (reading 'readRelayUrls') at useNDK.ts:460:46 at async Promise.all (:5173/index 0) at async upgradeT (index.tsx:383:11)```
Outdated
Review

I tried multiple sigit rounds, but couldn't reproduce this issue.

I tried multiple sigit rounds, but couldn't reproduce this issue.
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)}`,
@ -457,7 +480,7 @@ export const useNDK = () => {
throw err
})
},
[ndk, publish, usersPubkey]
[ndk, usersPubkey, getNDKRelayList]
)
return {