From ccaee2656cea0c3185652d3f09e5cc9f2b2b30e2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Jan 2026 20:49:57 +0000 Subject: [PATCH] fix: resolve TypeScript errors in EventMentionNode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix TypeScript compilation errors: 1. Fix eventStore import - use default import instead of named import 2. Add identifier attribute to EventMentionNode for naddr support 3. Remove redundant nip19.decode call in node view 4. Extract and store identifier when creating naddr nodes in paste handler Changes: - eventStore: named import → default import - Add identifier attribute to node attrs (for naddr d tag) - Use stored identifier instead of re-decoding in node view - Extract identifier from AddressPointer in paste handler - Simplifies logic and fixes type narrowing issues This eliminates the type comparison error where TypeScript couldn't determine that decoded.type matched decodedType at runtime. --- src/components/editor/MentionEditor.tsx | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/components/editor/MentionEditor.tsx b/src/components/editor/MentionEditor.tsx index 706962a..0fe6edd 100644 --- a/src/components/editor/MentionEditor.tsx +++ b/src/components/editor/MentionEditor.tsx @@ -34,7 +34,7 @@ import type { EmojiSearchResult } from "@/services/emoji-search"; import type { ChatAction } from "@/types/chat-actions"; import { nip19 } from "nostr-tools"; import { getKindName } from "@/constants/kinds"; -import { eventStore } from "@/services/event-store"; +import eventStore from "@/services/event-store"; import { MemoizedInlineEventPreview } from "../nostr/InlineEventPreview"; import type { NostrEvent } from "@/types/nostr"; import { FileText } from "lucide-react"; @@ -297,6 +297,7 @@ const EventMentionNode = Node.create({ eventId: { default: null }, kind: { default: null }, pubkey: { default: null }, + identifier: { default: null }, // For naddr (d tag) }; }, @@ -317,7 +318,8 @@ const EventMentionNode = Node.create({ addNodeView() { return ({ node }) => { - const { decodedType, kind, nostrUri, eventId, pubkey } = node.attrs; + const { decodedType, kind, nostrUri, eventId, pubkey, identifier } = + node.attrs; // Create wrapper span const dom = document.createElement("span"); @@ -333,19 +335,14 @@ const EventMentionNode = Node.create({ if (eventId) { // For note/nevent - try to get by ID event = eventStore.event(eventId); - } else if (decodedType === "naddr" && kind !== null && pubkey) { - // For naddr - try to get replaceable event - // Get the identifier from the original naddr - try { - const decoded = nip19.decode(nostrUri.replace("nostr:", "")); - if (decoded.type === "naddr") { - const identifier = (decoded.data as nip19.AddressPointer) - .identifier; - event = eventStore.replaceable(kind, pubkey, identifier); - } - } catch { - // Failed to decode, fall through to fallback - } + } else if ( + decodedType === "naddr" && + kind !== null && + pubkey && + identifier !== null + ) { + // For naddr - try to get replaceable event using stored identifier + event = eventStore.replaceable(kind, pubkey, identifier); } // Render the component @@ -452,6 +449,7 @@ const EventMentionNode = Node.create({ let eventId: string | null = null; let kind: number | null = null; let pubkey: string | null = null; + let identifier: string | null = null; if (decoded.type === "note") { decodedType = "note"; @@ -468,6 +466,7 @@ const EventMentionNode = Node.create({ const data = decoded.data as nip19.AddressPointer; kind = data.kind; pubkey = data.pubkey; + identifier = data.identifier; } else { return false; } @@ -484,6 +483,7 @@ const EventMentionNode = Node.create({ eventId, kind, pubkey, + identifier, }), );