diff --git a/CONTEXT.md b/CONTEXT.md index 03acefb..3ad6344 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -106,8 +106,9 @@ function usePosts() { return useQuery({ queryKey: ['posts'], - queryFn: async () => { - const events = await nostr.query([{ kinds: [1], limit: 20 }]); + queryFn: async (c) => { + const signal = AbortSignal.any([c.signal, AbortSignal.timeout(1500)]); + const events = await nostr.query([{ kinds: [1], limit: 20 }], { signal }); return events; // these events could be transformed into another format }, }); diff --git a/package-lock.json b/package-lock.json index e85fe66..0cfd03f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,8 @@ "version": "0.0.0", "dependencies": { "@hookform/resolvers": "^3.9.0", - "@nostrify/nostrify": "npm:@jsr/nostrify__nostrify@^0.43.0", - "@nostrify/react": "npm:@jsr/nostrify__react@^0.2.0", + "@nostrify/nostrify": "npm:@jsr/nostrify__nostrify@^0.44.0", + "@nostrify/react": "npm:@jsr/nostrify__react@^0.2.1", "@radix-ui/react-accordion": "^1.2.0", "@radix-ui/react-alert-dialog": "^1.1.1", "@radix-ui/react-aspect-ratio": "^1.1.0", @@ -414,9 +414,9 @@ } }, "node_modules/@jsr/nostrify__nostrify": { - "version": "0.43.0", - "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__nostrify/0.43.0.tgz", - "integrity": "sha512-rl4jDvxadeCjLsp78lpu8TtuQMiR80alTj4TF33puJgNlbJn0xW6pYWpkw6WOgsgjAvUeytMm3FvdFEnibr+iQ==", + "version": "0.44.0", + "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__nostrify/0.44.0.tgz", + "integrity": "sha512-xkN00DJadsTZjhV7D3iQfU6NG9FCzZ/8nljzty5+BTeOyy/nNMLJo3vTrs/IG0dbutJrVn+g/fOjQ5WTW9J4kw==", "dependencies": { "@jsr/nostrify__types": "^0.36.0", "@jsr/scure__base": "^1.2.4", @@ -552,9 +552,9 @@ }, "node_modules/@nostrify/nostrify": { "name": "@jsr/nostrify__nostrify", - "version": "0.43.0", - "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__nostrify/0.43.0.tgz", - "integrity": "sha512-rl4jDvxadeCjLsp78lpu8TtuQMiR80alTj4TF33puJgNlbJn0xW6pYWpkw6WOgsgjAvUeytMm3FvdFEnibr+iQ==", + "version": "0.44.0", + "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__nostrify/0.44.0.tgz", + "integrity": "sha512-xkN00DJadsTZjhV7D3iQfU6NG9FCzZ/8nljzty5+BTeOyy/nNMLJo3vTrs/IG0dbutJrVn+g/fOjQ5WTW9J4kw==", "dependencies": { "@jsr/nostrify__types": "^0.36.0", "@jsr/scure__base": "^1.2.4", @@ -568,11 +568,11 @@ }, "node_modules/@nostrify/react": { "name": "@jsr/nostrify__react", - "version": "0.2.0", - "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__react/0.2.0.tgz", - "integrity": "sha512-zV3sMK0oKuwhzazr8C8cnyr6oemYVUoJ63Ik77MeANudto9EUPw8Hp/FtnMX4UDBjr8pU/JXxbEqilCz9CxHzA==", + "version": "0.2.1", + "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__react/0.2.1.tgz", + "integrity": "sha512-raKZLgyL07Mb+dtg+aPD8i3eWYMqyv/ko9MXliOvbAX1Ki5o4cBorjsGShT0LvOOgP+2l4e+ZMpl2mceVRjILQ==", "dependencies": { - "@jsr/nostrify__nostrify": "^0.43.0", + "@jsr/nostrify__nostrify": "^0.44.0", "nostr-tools": "^2.10.4", "react": "^18.0.0" } diff --git a/package.json b/package.json index 7bbafbd..00cbb73 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ }, "dependencies": { "@hookform/resolvers": "^3.9.0", - "@nostrify/nostrify": "npm:@jsr/nostrify__nostrify@^0.43.0", - "@nostrify/react": "npm:@jsr/nostrify__react@^0.2.0", + "@nostrify/nostrify": "npm:@jsr/nostrify__nostrify@^0.44.0", + "@nostrify/react": "npm:@jsr/nostrify__react@^0.2.1", "@radix-ui/react-accordion": "^1.2.0", "@radix-ui/react-alert-dialog": "^1.1.1", "@radix-ui/react-aspect-ratio": "^1.1.0", diff --git a/recipe.yaml b/recipe.yaml new file mode 100644 index 0000000..9529871 --- /dev/null +++ b/recipe.yaml @@ -0,0 +1,32 @@ +version: 1.0.0 +title: Nostr Client Development +description: A recipe for building Nostr client applications +instructions: Create a Nostr client application according to the user's request. +extensions: + - type: builtin + name: developer + display_name: Developer Tools + timeout: 300 + bundled: true + - type: stdio + name: nostr + cmd: npx + args: + - -y + - xjsr + - "@nostrbook/mcp" + envs: {} + timeout: 20 + description: null + bundled: null + - type: stdio + name: fetch + cmd: uvx + args: + - mcp-server-fetch + envs: {} + timeout: 20 + description: null + bundled: null +author: + contact: Alex Gleason diff --git a/src/hooks/useAuthor.ts b/src/hooks/useAuthor.ts index 980fc12..d44a9de 100644 --- a/src/hooks/useAuthor.ts +++ b/src/hooks/useAuthor.ts @@ -18,7 +18,7 @@ export function useAuthor(pubkey: string | undefined) { ); if (!event) { - return {}; + throw new Error('No event found'); } try { @@ -28,5 +28,6 @@ export function useAuthor(pubkey: string | undefined) { return { event }; } }, + retry: 3, }); } diff --git a/src/hooks/useLoggedInAccounts.ts b/src/hooks/useLoggedInAccounts.ts index 7b090e6..8471f36 100644 --- a/src/hooks/useLoggedInAccounts.ts +++ b/src/hooks/useLoggedInAccounts.ts @@ -17,17 +17,10 @@ export function useLoggedInAccounts() { const { data: authors = [] } = useQuery({ queryKey: ['logins', logins.map((l) => l.id).join(';')], queryFn: async ({ signal }) => { - let events: NostrEvent[] = []; - - try { - events = await nostr.query( - [{ kinds: [0], authors: logins.map((l) => l.pubkey) }], - { signal: AbortSignal.any([signal, AbortSignal.timeout(3000)]) }, - ); - } catch (error) { - console.error('Error fetching accounts:', error); - return []; - } + const events = await nostr.query( + [{ kinds: [0], authors: logins.map((l) => l.pubkey) }], + { signal: AbortSignal.any([signal, AbortSignal.timeout(3000)]) }, + ); return logins.map(({ id, pubkey }): Account => { const event = events.find((e) => e.pubkey === pubkey); @@ -38,7 +31,8 @@ export function useLoggedInAccounts() { return { id, pubkey, metadata: {}, event }; } }); - } + }, + retry: 3, }); // Current user is the first login diff --git a/src/hooks/useNostrPublish.ts b/src/hooks/useNostrPublish.ts index d36ada4..204b6bc 100644 --- a/src/hooks/useNostrPublish.ts +++ b/src/hooks/useNostrPublish.ts @@ -23,7 +23,7 @@ export function useNostrPublish() { tags: t.tags ?? [], created_at: t.created_at ?? Math.floor(Date.now() / 1000), }); - nostr.event(event); + await nostr.event(event, { signal: AbortSignal.timeout(5000) }); } else { throw new Error("User is not logged in"); } diff --git a/vite.config.ts b/vite.config.ts index b3de935..6dafad4 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,9 +1,9 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; -import path from "path"; +import path from "node:path"; // https://vitejs.dev/config/ -export default defineConfig(({ mode }) => ({ +export default defineConfig(() => ({ server: { host: "::", port: 8080,