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 { 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]
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.
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 {