From a8921bc7f802d32f774bcb51706ca88e17395232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20G=C3=B3mez?= Date: Thu, 11 Dec 2025 10:44:02 +0100 Subject: [PATCH] refactor: use constants --- src/components/EventDetailViewer.tsx | 10 ++-- src/components/KindRenderer.tsx | 49 ++++++++++++++----- .../nostr/kinds/BaseEventRenderer.tsx | 12 +++-- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/components/EventDetailViewer.tsx b/src/components/EventDetailViewer.tsx index d9b58e9..2e3e6b0 100644 --- a/src/components/EventDetailViewer.tsx +++ b/src/components/EventDetailViewer.tsx @@ -16,7 +16,7 @@ import { Wifi, Circle, } from "lucide-react"; -import { nip19 } from "nostr-tools"; +import { nip19, kinds } from "nostr-tools"; import { useCopy } from "../hooks/useCopy"; import { getSeenRelays } from "applesauce-core/helpers/relays"; @@ -173,13 +173,13 @@ export function EventDetailViewer({ pointer }: EventDetailViewerProps) { {/* Rendered Content - Focus Here */}
- {event.kind === 0 ? ( + {event.kind === kinds.Metadata ? ( - ) : event.kind === 3 ? ( + ) : event.kind === kinds.Contacts ? ( - ) : event.kind === 30023 ? ( + ) : event.kind === kinds.LongFormArticle ? ( - ) : event.kind === 9802 ? ( + ) : event.kind === kinds.Highlights ? ( ) : ( diff --git a/src/components/KindRenderer.tsx b/src/components/KindRenderer.tsx index 021ef13..6acad94 100644 --- a/src/components/KindRenderer.tsx +++ b/src/components/KindRenderer.tsx @@ -1,6 +1,15 @@ import { getKindInfo } from "@/constants/kinds"; import Command from "./Command"; import { ExternalLink } from "lucide-react"; +import { kinds } from "nostr-tools"; + +// NIP-01 Kind ranges +const REPLACEABLE_START = 10000; +const REPLACEABLE_END = 20000; +const EPHEMERAL_START = 20000; +const EPHEMERAL_END = 30000; +const PARAMETERIZED_REPLACEABLE_START = 30000; +const PARAMETERIZED_REPLACEABLE_END = 40000; export default function KindRenderer({ kind }: { kind: number }) { const kindInfo = getKindInfo(kind); @@ -49,17 +58,18 @@ export default function KindRenderer({ kind }: { kind: number }) {
Storage
- {kind >= 20000 && kind < 30000 + {kind >= EPHEMERAL_START && kind < EPHEMERAL_END ? "Not stored (ephemeral)" : "Stored by relays"}
- {kind >= 30000 && kind < 40000 && ( - <> -
Identifier
- d-tag - - )} + {kind >= PARAMETERIZED_REPLACEABLE_START && + kind < PARAMETERIZED_REPLACEABLE_END && ( + <> +
Identifier
+ d-tag + + )} {kindInfo.nip && ( <> @@ -106,9 +116,15 @@ function getKindCategory(kind: number): string { if (kind >= 20 && kind <= 39) return "Media & Content"; if (kind >= 40 && kind <= 49) return "Channels"; if (kind >= 1000 && kind <= 9999) return "Application Specific"; - if (kind >= 10000 && kind <= 19999) return "Regular Lists"; - if (kind >= 20000 && kind <= 29999) return "Ephemeral Events"; - if (kind >= 30000 && kind <= 39999) return "Parameterized Replaceable"; + if (kind >= REPLACEABLE_START && kind < REPLACEABLE_END) + return "Regular Lists"; + if (kind >= EPHEMERAL_START && kind < EPHEMERAL_END) + return "Ephemeral Events"; + if ( + kind >= PARAMETERIZED_REPLACEABLE_START && + kind < PARAMETERIZED_REPLACEABLE_END + ) + return "Parameterized Replaceable"; if (kind >= 40000) return "Custom/Experimental"; return "Other"; } @@ -117,13 +133,20 @@ function getKindCategory(kind: number): string { * Determine the replaceability of an event kind */ function getEventType(kind: number): string { - if (kind === 0 || kind === 3 || (kind >= 10000 && kind < 20000)) { + if ( + kind === kinds.Metadata || + kind === kinds.Contacts || + (kind >= REPLACEABLE_START && kind < REPLACEABLE_END) + ) { return "Replaceable"; } - if (kind >= 30000 && kind < 40000) { + if ( + kind >= PARAMETERIZED_REPLACEABLE_START && + kind < PARAMETERIZED_REPLACEABLE_END + ) { return "Parameterized Replaceable"; } - if (kind >= 20000 && kind < 30000) { + if (kind >= EPHEMERAL_START && kind < EPHEMERAL_END) { return "Ephemeral"; } return "Regular"; diff --git a/src/components/nostr/kinds/BaseEventRenderer.tsx b/src/components/nostr/kinds/BaseEventRenderer.tsx index a889fe7..bb7e4a1 100644 --- a/src/components/nostr/kinds/BaseEventRenderer.tsx +++ b/src/components/nostr/kinds/BaseEventRenderer.tsx @@ -16,6 +16,12 @@ import { useCopy } from "@/hooks/useCopy"; import { JsonViewer } from "@/components/JsonViewer"; import { formatTimestamp } from "@/hooks/useLocale"; +// NIP-01 Kind ranges +const REPLACEABLE_START = 10000; +const REPLACEABLE_END = 20000; +const PARAMETERIZED_REPLACEABLE_START = 30000; +const PARAMETERIZED_REPLACEABLE_END = 40000; + /** * Universal event properties and utilities shared across all kind renderers */ @@ -45,10 +51,10 @@ export function EventMenu({ event }: { event: NostrEvent }) { const openEventDetail = () => { // For replaceable/parameterized replaceable events, use AddressPointer - // Replaceable: 10000-19999, Parameterized: 30000-39999 const isAddressable = - (event.kind >= 10000 && event.kind < 20000) || - (event.kind >= 30000 && event.kind < 40000); + (event.kind >= REPLACEABLE_START && event.kind < REPLACEABLE_END) || + (event.kind >= PARAMETERIZED_REPLACEABLE_START && + event.kind < PARAMETERIZED_REPLACEABLE_END); let pointer; if (isAddressable) {