Skip to content

Commit

Permalink
fix fetch events tools + not need for signer ndk setup env to fetch (A…
Browse files Browse the repository at this point in the history
…bdelStark#16)

* fix fetch events tools + not need for signer ndk setup env to fetch

* readd filter of nostr tools
  • Loading branch information
MSghais authored Jul 31, 2024
1 parent cb56567 commit 860a8f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions askeladd-dvm-marketplace/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default function Home() {
// const relay = await Relay.connect(ASKELADD_RELAY[0])
// let eventID = await relay.publish(event as EventNostr);
const eventID = await Promise.any(pool.publish(ASKELADD_RELAY, event as EventNostr));
const { events } = await fetchEvents({
const { events } = await fetchEventsTools({
kind: KIND_JOB_REQUEST,
since: timestampJob
});
Expand Down Expand Up @@ -176,6 +176,8 @@ export default function Home() {
// })
setIsWaitingJob(true)
} else {

/** @TODO flow is user doesn't have NIP-07 extension */
// let { result, event } = await sendNote({ content, tags, kind: 5600 })
// console.log("event", event)
// if (event?.sig) {
Expand Down Expand Up @@ -205,7 +207,7 @@ export default function Home() {
// const { events } = await fetchEventsTools({ until: timestampJob, kind: KIND_JOB_RESULT,
// // search:`${jobId}`,
// })
const { events } = await fetchEvents({
const { events } = await fetchEventsTools({
kind: KIND_JOB_RESULT,
// since: timestampJob,
// search:`${jobId}`,
Expand Down
2 changes: 1 addition & 1 deletion askeladd-dvm-marketplace/src/context/NostrContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const NostrProvider: React.FC<React.PropsWithChildren> = ({children}) =>
newNdk.connect().then(() => {
setNdk(newNdk);
});
}, [privateKey, process.env.DEFAULT_NOSTR_USER_SK]);
}, [privateKey, process.env.NEXT_PUBLIC_DEFAULT_NOSTR_USER_SK]);

return <NostrContext.Provider value={{ndk}}>{children}</NostrContext.Provider>;
};
Expand Down
13 changes: 9 additions & 4 deletions askeladd-dvm-marketplace/src/hooks/useFetchEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ interface ISubscriptionData {
const DEFAULT_LIMIT = 300
export const useFetchEvents = () => {
const { ndk } = useNostrContext();
// const pool = new SimplePool()
const [pool, setPool] = useState(new SimplePool())

const fetchEvents = async (data: IEventFilter) => {
try {
if (!ndk?.signer) return { result: undefined, events: undefined };
const { kind, limit, since, until, kinds, search } = data;
let eventsResult = await ndk.fetchEvents({
kinds: kind ? [kind] : kinds ?? [KIND_JOB_RESULT as NDKKind, KIND_JOB_REQUEST],
Expand All @@ -44,12 +44,17 @@ export const useFetchEvents = () => {
}
const fetchEventsTools = async (data: IEventFilter) => {
try {
if (!ndk?.signer) return { result: undefined, events: undefined };
const { kind, limit, since, until, kinds, search } = data;
const pool = new SimplePool()
let relays = ASKELADD_RELAY;
const kind_search = kind ? [kind] : kinds ?? [KIND_JOB_REQUEST, KIND_JOB_RESULT];
const events = await pool.querySync(relays, { kinds: kind_search, until, since, limit: limit ?? DEFAULT_LIMIT, search })
const events = await pool.querySync(relays, {
kinds: kind_search,
until,
since,
limit: limit ?? DEFAULT_LIMIT,
search
})
return {
result: undefined,
events: events
Expand Down Expand Up @@ -90,7 +95,7 @@ export const useFetchEvents = () => {
}
}
)
setPool(pool);
// setPool(pool);
return h;
}
return { fetchEvents, fetchEventsTools, setupSubscriptionNostr, pool }
Expand Down

0 comments on commit 860a8f0

Please sign in to comment.