diff --git a/src/hooks/goals.ts b/src/hooks/goals.ts index cee6762..e06cd98 100644 --- a/src/hooks/goals.ts +++ b/src/hooks/goals.ts @@ -37,8 +37,9 @@ export function useZaps(goal: NostrEvent, leaveOpen = false) { ); } -export function useZapGoal(host: string, link: NostrLink, leaveOpen = false) { +export function useZapGoal(host: string, link?: NostrLink, leaveOpen = false) { const sub = useMemo(() => { + if (!link) return null; const b = new RequestBuilder(`goals:${host.slice(0, 12)}`); b.withOptions({ leaveOpen }); b.withFilter() diff --git a/src/index.tsx b/src/index.tsx index 60cb3c3..1c35a46 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -11,7 +11,7 @@ import { RootPage } from "pages/root"; import { TagPage } from "pages/tag"; import { LayoutPage } from "pages/layout"; import { ProfilePage } from "pages/profile-page"; -import { StreamPage } from "pages/stream-page"; +import { StreamPageHandler } from "pages/stream-page"; import { ChatPopout } from "pages/chat-popout"; import { LoginStore } from "login"; import { StreamProvidersPage } from "pages/providers"; @@ -54,7 +54,7 @@ const router = createBrowserRouter([ }, { path: "/:id", - element: , + element: , }, { path: "/providers/:id?", diff --git a/src/pages/stream-page.tsx b/src/pages/stream-page.tsx index 01ac6b3..33f32b5 100644 --- a/src/pages/stream-page.tsx +++ b/src/pages/stream-page.tsx @@ -1,6 +1,6 @@ import "./stream-page.css"; -import { parseNostrLink, TaggedRawEvent } from "@snort/system"; -import { unwrap } from "@snort/shared"; +import { NostrLink, NostrPrefix, TaggedRawEvent, tryParseNostrLink } from "@snort/system"; +import { fetchNip05Pubkey } from "@snort/shared"; import { useLocation, useNavigate, useParams } from "react-router-dom"; import { Helmet } from "react-helmet"; @@ -10,6 +10,7 @@ import { findTag, getEventFromLocationState, getHost, + hexToBech32, } from "utils"; import { Profile, getName } from "element/profile"; import { LiveChat } from "element/live-chat"; @@ -32,6 +33,7 @@ import { isContentWarningAccepted, } from "element/content-warning"; import { useCurrentStreamFeed } from "hooks/current-stream-feed"; +import { useEffect, useState } from "react"; function ProfileInfo({ ev, goal }: { ev?: NostrEvent; goal?: TaggedRawEvent }) { const login = useLogin(); @@ -111,14 +113,41 @@ function ProfileInfo({ ev, goal }: { ev?: NostrEvent; goal?: TaggedRawEvent }) { ); } -export function StreamPage() { +export function StreamPageHandler() { const params = useParams(); const location = useLocation(); const evPreload = getEventFromLocationState(location.state); - const link = parseNostrLink(unwrap(params.id)); + const [link, setLink] = useState(); + + useEffect(() => { + if (params.id) { + const parsedLink = tryParseNostrLink(params.id); + if (parsedLink) { + setLink(parsedLink); + } else { + const [handle, domain] = (params.id.includes("@") ? params.id : `${params.id}@zap.stream`).split("@"); + fetchNip05Pubkey(handle, domain).then(d => { + if (d) { + setLink({ + id: d, + type: NostrPrefix.PublicKey, + encode: () => hexToBech32(NostrPrefix.PublicKey, d) + } as NostrLink); + } + }) + } + } + }, [params.id]); + + if (link) { + return + } +} + +export function StreamPage({ link, evPreload }: { evPreload?: NostrEvent, link: NostrLink }) { const ev = useCurrentStreamFeed(link, true, evPreload); const host = getHost(ev); - const goal = useZapGoal(host, link, true); + const goal = useZapGoal(host, createNostrLink(ev), true); const title = findTag(ev, "title"); const summary = findTag(ev, "summary");