feat(feed): read-only Nostr feed at /feed + a "Join us" Nostr link

The Smirk square, served from relay.smirk.cash. Because the relay is
premium-post gated, the feed is self-curating — general notes (kind 1) come
only from premium members. v1 is read-only (subscribe + render); composing
arrives with the wallet's Nostr dapp-api scope. Adds nostr-tools and a Nostr
icon beside Telegram/Discord that links to the feed.
This commit is contained in:
jwinterm
2026-07-03 07:41:57 -04:00
parent d25d54c942
commit 60e24e456e
4 changed files with 250 additions and 1 deletions
+133
View File
@@ -0,0 +1,133 @@
'use client';
/**
* feed.smirk.cash — a public, read-only window into the Smirk Nostr square.
*
* The relay (wss://relay.smirk.cash) is premium-post gated, so general notes
* (kind 1) come only from members who hold premium — the feed is self-curating.
* This v1 is read-only; composing/replying arrives once the wallet's dapp-api
* exposes a Nostr sign scope (see the monorepo roadmap).
*/
import { useEffect, useMemo, useState } from 'react';
import { SimplePool, nip19, type Event as NostrEvent } from 'nostr-tools';
const RELAY = 'wss://relay.smirk.cash';
function shortNpub(pubkeyHex: string): string {
try {
const npub = nip19.npubEncode(pubkeyHex);
return `${npub.slice(0, 12)}…${npub.slice(-6)}`;
} catch {
return `${pubkeyHex.slice(0, 8)}…`;
}
}
function relativeTime(unixSeconds: number): string {
const s = Math.max(0, Math.floor(Date.now() / 1000) - unixSeconds);
if (s < 60) return `${s}s`;
if (s < 3600) return `${Math.floor(s / 60)}m`;
if (s < 86400) return `${Math.floor(s / 3600)}h`;
return `${Math.floor(s / 86400)}d`;
}
export default function FeedPage(): React.ReactElement {
const [events, setEvents] = useState<NostrEvent[]>([]);
const [status, setStatus] = useState<'connecting' | 'live' | 'empty'>('connecting');
useEffect(() => {
const pool = new SimplePool();
const seen = new Set<string>();
const sub = pool.subscribeMany(
[RELAY],
{ kinds: [1], limit: 100 },
{
onevent(ev: NostrEvent) {
if (seen.has(ev.id)) return;
seen.add(ev.id);
setStatus('live');
setEvents((prev) =>
[...prev, ev]
.sort((a, b) => b.created_at - a.created_at)
.slice(0, 200),
);
},
oneose() {
setStatus((s) => (s === 'connecting' ? 'empty' : s));
},
},
);
return () => {
sub.close();
pool.close([RELAY]);
};
}, []);
const dot = useMemo(() => {
if (status === 'live') return { color: '#4ade80', label: 'live' };
if (status === 'empty') return { color: '#71717a', label: 'quiet' };
return { color: '#fbeb0a', label: 'connecting' };
}, [status]);
return (
<main className="min-h-screen bg-black text-zinc-200">
<div className="mx-auto max-w-2xl px-4 py-10">
<header className="mb-8 text-center">
<a href="/" className="inline-block">
<span className="text-[#fbeb0a] font-bold text-2xl tracking-wide">
SMIRK FEED
</span>
</a>
<p className="mt-2 text-sm text-zinc-500">
The self-sovereign Smirk square, on{' '}
<span className="text-zinc-400">relay.smirk.cash</span>
</p>
<div className="mt-3 inline-flex items-center gap-2 text-xs text-zinc-500">
<span
className="inline-block h-2 w-2 rounded-full"
style={{ backgroundColor: dot.color }}
/>
{dot.label}
</div>
</header>
{status !== 'live' && events.length === 0 ? (
<div className="rounded-xl border border-zinc-800 bg-zinc-950 p-8 text-center">
<p className="text-zinc-400">
{status === 'connecting'
? 'Connecting to the relay…'
: 'No posts yet.'}
</p>
<p className="mt-2 text-sm text-zinc-600">
Posts from Smirk premium members appear here.
</p>
</div>
) : (
<ul className="space-y-3">
{events.map((ev) => (
<li
key={ev.id}
className="rounded-xl border border-zinc-800 bg-zinc-950 p-4"
>
<div className="mb-1 flex items-center justify-between text-xs">
<span className="font-mono text-[#fbeb0a]">
{shortNpub(ev.pubkey)}
</span>
<span className="text-zinc-600">{relativeTime(ev.created_at)}</span>
</div>
<p className="whitespace-pre-wrap break-words text-sm text-zinc-200">
{ev.content}
</p>
</li>
))}
</ul>
)}
<footer className="mt-10 text-center text-xs text-zinc-600">
<a href="/" className="hover:text-zinc-400">
← smirk.cash
</a>
</footer>
</div>
</main>
);
}
+10
View File
@@ -228,6 +228,16 @@ export default function Home() {
<path d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z"/>
</svg>
</a>
<a
href="/feed"
className="text-zinc-500 hover:text-[#fbeb0a] transition-colors"
title="Nostr feed (self-sovereign)"
>
<svg className="w-6 h-6" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<circle cx="12" cy="12" r="2" fill="currentColor" stroke="none" />
<path d="M7.5 16.5a6 6 0 0 1 0-9M4.7 19.3a10 10 0 0 1 0-14.6M16.5 7.5a6 6 0 0 1 0 9M19.3 4.7a10 10 0 0 1 0 14.6" />
</svg>
</a>
</div>
</div>
)}