diff --git a/src/lib/components/CommentBox.svelte b/src/lib/components/CommentBox.svelte
index 1e23ce2..087a9ab 100644
--- a/src/lib/components/CommentBox.svelte
+++ b/src/lib/components/CommentBox.svelte
@@ -23,13 +23,15 @@
} from "$lib/utils/nostrEventService";
import { tick } from "svelte";
import { goto } from "$app/navigation";
- import { activeInboxRelays, activeOutboxRelays } from "$lib/ndk";
+ import { activeInboxRelays, activeOutboxRelays, getNdkContext } from "$lib/ndk";
const props = $props<{
event: NDKEvent;
userRelayPreference: boolean;
}>();
+ const ndk = getNdkContext();
+
let content = $state("");
let preview = $state("");
let isSubmitting = $state(false);
@@ -216,7 +218,7 @@
relays = $activeOutboxRelays.slice(0, 3); // Use first 3 outbox relays
}
- const successfulRelays = await publishEvent(signedEvent, relays);
+ const successfulRelays = await publishEvent(signedEvent, relays, ndk);
success = {
relay: successfulRelays[0] || "Unknown relay",
@@ -282,7 +284,7 @@
try {
console.log("Search promise created, waiting for result...");
- const result = await searchProfiles(mentionSearch.trim());
+ const result = await searchProfiles(mentionSearch.trim(), ndk);
console.log("Search completed, found profiles:", result.profiles.length);
console.log("Profile details:", result.profiles);
console.log("Community status:", result.Status);
diff --git a/src/lib/components/CommentViewer.svelte b/src/lib/components/CommentViewer.svelte
index 67cda8a..46b444a 100644
--- a/src/lib/components/CommentViewer.svelte
+++ b/src/lib/components/CommentViewer.svelte
@@ -40,7 +40,7 @@
if (!npub) return;
// Force fetch to ensure we get the latest profile data
- const profile = await getUserMetadata(npub, true);
+ const profile = await getUserMetadata(npub, ndk, true);
const newProfiles = new Map(profiles);
newProfiles.set(pubkey, profile);
profiles = newProfiles;
diff --git a/src/lib/components/EventDetails.svelte b/src/lib/components/EventDetails.svelte
index 687b9f8..f812a41 100644
--- a/src/lib/components/EventDetails.svelte
+++ b/src/lib/components/EventDetails.svelte
@@ -196,7 +196,7 @@
return;
}
- getUserMetadata(toNpub(event.pubkey) as string).then((profile) => {
+ getUserMetadata(toNpub(event.pubkey) as string, undefined).then((profile) => {
authorDisplayName =
profile.displayName ||
(profile as any).display_name ||
diff --git a/src/lib/components/EventInput.svelte b/src/lib/components/EventInput.svelte
index b15140c..22759a3 100644
--- a/src/lib/components/EventInput.svelte
+++ b/src/lib/components/EventInput.svelte
@@ -265,6 +265,7 @@
content,
tags,
baseEvent,
+ ndk,
);
console.log("Index event:", indexEvent);
console.log("Section events:", sectionEvents);
diff --git a/src/lib/components/EventSearch.svelte b/src/lib/components/EventSearch.svelte
index 5963bf0..2ae8c9d 100644
--- a/src/lib/components/EventSearch.svelte
+++ b/src/lib/components/EventSearch.svelte
@@ -8,6 +8,7 @@
searchBySubscription,
searchNip05,
} from "$lib/utils/search_utility";
+ import type { SearchCallbacks } from "$lib/utils/search_types";
import { neventEncode, naddrEncode, nprofileEncode } from "$lib/utils";
import { activeInboxRelays, activeOutboxRelays, getNdkContext } from "$lib/ndk";
import { getMatchingTags, toNpub } from "$lib/utils/nostrUtils";
@@ -81,7 +82,7 @@
// AI-NOTE: 2025-01-24 - Core search handlers extracted for better organization
async function handleNip05Search(query: string) {
try {
- const foundEvent = await searchNip05(query);
+ const foundEvent = await searchNip05(query, ndk);
if (foundEvent) {
handleFoundEvent(foundEvent);
updateSearchState(false, true, 1, "nip05");
@@ -96,7 +97,7 @@
async function handleEventSearch(query: string) {
try {
- const foundEvent = await searchEvent(query);
+ const foundEvent = await searchEvent(query, ndk);
if (!foundEvent) {
console.warn("[Events] Event not found for query:", query);
localError = "Event not found";
@@ -505,6 +506,7 @@
const searchPromise = searchBySubscription(
searchType,
searchTerm,
+ ndk,
{
onSecondOrderUpdate: (updatedResult) => {
console.log("EventSearch: Second order update:", updatedResult);
diff --git a/src/lib/components/Navigation.svelte b/src/lib/components/Navigation.svelte
index 186a93f..1d37f14 100644
--- a/src/lib/components/Navigation.svelte
+++ b/src/lib/components/Navigation.svelte
@@ -22,7 +22,7 @@
diff --git a/src/lib/components/Notifications.svelte b/src/lib/components/Notifications.svelte
index 00841f1..7e1a5bd 100644
--- a/src/lib/components/Notifications.svelte
+++ b/src/lib/components/Notifications.svelte
@@ -263,7 +263,7 @@
try {
console.log("Recipient search promise created, waiting for result...");
- const result = await searchProfiles(recipientSearch.trim());
+ const result = await searchProfiles(recipientSearch.trim(), ndk);
console.log("Recipient search completed, found profiles:", result.profiles.length);
console.log("Profile details:", result.profiles);
console.log("Community status:", result.Status);
@@ -388,7 +388,7 @@
// Get relay sets for all recipients and combine them
const relaySetPromises = recipientPubkeys.map(recipientPubkey =>
- getKind24RelaySet(senderPubkey, recipientPubkey)
+ getKind24RelaySet(senderPubkey, recipientPubkey, ndk)
);
const relaySets = await Promise.all(relaySetPromises);
@@ -623,7 +623,7 @@
// Get relay sets for all recipients and combine them
const relaySetPromises = recipientPubkeys.map(recipientPubkey =>
- getKind24RelaySet(senderPubkey, recipientPubkey)
+ getKind24RelaySet(senderPubkey, recipientPubkey, ndk)
);
const relaySets = await Promise.all(relaySetPromises);
diff --git a/src/lib/components/embedded_events/EmbeddedEvent.svelte b/src/lib/components/embedded_events/EmbeddedEvent.svelte
index 37c00a8..eb8a711 100644
--- a/src/lib/components/embedded_events/EmbeddedEvent.svelte
+++ b/src/lib/components/embedded_events/EmbeddedEvent.svelte
@@ -107,7 +107,7 @@
if (event?.pubkey) {
const npub = toNpub(event.pubkey);
if (npub) {
- const userProfile = await getUserMetadata(npub);
+ const userProfile = await getUserMetadata(npub, ndk);
authorDisplayName =
userProfile.displayName ||
(userProfile as any).display_name ||
diff --git a/src/lib/components/embedded_events/EmbeddedSnippets.svelte b/src/lib/components/embedded_events/EmbeddedSnippets.svelte
index a086bad..ed87bdb 100644
--- a/src/lib/components/embedded_events/EmbeddedSnippets.svelte
+++ b/src/lib/components/embedded_events/EmbeddedSnippets.svelte
@@ -104,7 +104,7 @@
if (!npub) return;
// Try cache first
- let profile = await getUserMetadata(npub, false);
+ let profile = await getUserMetadata(npub, ndk, false);
if (profile && (profile.name || profile.displayName || profile.picture)) {
authorProfiles.set(pubkey, profile);
return;
diff --git a/src/lib/components/util/ContainingIndexes.svelte b/src/lib/components/util/ContainingIndexes.svelte
index be06f3e..fb598b5 100644
--- a/src/lib/components/util/ContainingIndexes.svelte
+++ b/src/lib/components/util/ContainingIndexes.svelte
@@ -5,12 +5,14 @@
import { findContainingIndexEvents } from "$lib/utils/event_search";
import { getMatchingTags } from "$lib/utils/nostrUtils";
import { naddrEncode } from "$lib/utils";
- import { activeInboxRelays, activeOutboxRelays } from "$lib/ndk";
+ import { activeInboxRelays, activeOutboxRelays, getNdkContext } from "$lib/ndk";
let { event } = $props<{
event: NDKEvent;
}>();
+ const ndk = getNdkContext();
+
let containingIndexes = $state([]);
let loading = $state(false);
let error = $state(null);
@@ -25,7 +27,7 @@
error = null;
try {
- containingIndexes = await findContainingIndexEvents(event);
+ containingIndexes = await findContainingIndexEvents(event, ndk);
console.log(
"[ContainingIndexes] Found containing indexes:",
containingIndexes.length,
diff --git a/src/lib/components/util/Profile.svelte b/src/lib/components/util/Profile.svelte
index ce2cdc4..8882074 100644
--- a/src/lib/components/util/Profile.svelte
+++ b/src/lib/components/util/Profile.svelte
@@ -235,7 +235,7 @@
// Fallback to getUserMetadata
console.log("Falling back to getUserMetadata");
- const freshProfile = await getUserMetadata(userState.npub, true); // Force fresh fetch
+ const freshProfile = await getUserMetadata(userState.npub, ndk, true); // Force fresh fetch
console.log("Fresh profile data from getUserMetadata:", freshProfile);
// Update the userStore with fresh profile data
@@ -325,7 +325,7 @@
qrCodeDataUrl =
(await generateQrCode(amberSigner.nostrConnectUri)) ?? undefined;
const user = await amberSigner.blockUntilReady();
- await loginWithAmber(amberSigner, user);
+ await loginWithAmber(amberSigner, user, ndk);
showQrCode = false;
} else {
throw new Error("Failed to generate Nostr Connect URI");
@@ -343,7 +343,7 @@
const inputNpub = prompt("Enter your npub (public key):");
if (inputNpub) {
try {
- await loginWithNpub(inputNpub);
+ await loginWithNpub(inputNpub, ndk);
} catch (err: unknown) {
showResultMessage(
`❌ npub login failed: ${err instanceof Error ? err.message : String(err)}`,
@@ -355,7 +355,7 @@
async function handleSignOutClick() {
localStorage.removeItem("amber/nsec");
localStorage.removeItem("alexandria/amber/fallback");
- logoutUser();
+ logoutUser(ndk);
}
function handleViewProfile() {
diff --git a/src/lib/snippets/UserSnippets.svelte b/src/lib/snippets/UserSnippets.svelte
index 417ca63..a4b4a17 100644
--- a/src/lib/snippets/UserSnippets.svelte
+++ b/src/lib/snippets/UserSnippets.svelte
@@ -45,7 +45,7 @@
{/await}
{:else}
- {#await createProfileLinkWithVerification(npub as string, displayText)}
+ {#await createProfileLinkWithVerification(npub as string, displayText, undefined)}