Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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