diff options
| -rw-r--r-- | src/features/messages.js | 16 | ||||
| -rw-r--r-- | src/i18n.js | 1 | ||||
| -rw-r--r-- | src/style.css | 2 | ||||
| -rw-r--r-- | tools/zap-receipt-row-test.js | 71 |
4 files changed, 87 insertions, 3 deletions
diff --git a/src/features/messages.js b/src/features/messages.js index abbbf74..d4d5c43 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -9304,6 +9304,12 @@ export function messagesFeature(ctx) { } function noteRow(pk, ev, name, { open = true, focus = false, joined = false } = {}) { + // A zap receipt (9735, or coinos's 9737) reached as a reply or through a + // reaction to it — some clients let you react to a zap — is the zap, not + // a post by the lightning server that signed it: the zapper's face and + // name, what they sent, what they said with it. + const zapRec = ev.kind === 9735 || ev.kind === 9737; + if (zapRec) { const z = zapperOf(ev); if (z) { pk = z; name = displayName(z); } } // NOT prefetchProfilePage: that fetches the author's whole page — their // kind 0, their relay list, their last thirty notes — and a feed row is // not a profile tap. Twenty rows meant sixty requests, which is how the @@ -9314,9 +9320,9 @@ export function messagesFeature(ctx) { // An event of a kind this app has no renderer for (a chess game, kind // 64, reached through a reaction to it) is shown as what its author's // client said it is (NIP-31 alt), never as raw content dressed as a post. - const foreign = ev.kind !== 1 && ev.kind !== ARTICLE && ev.kind !== POLL && ev.kind !== COMMENT; + const foreign = ev.kind !== 1 && ev.kind !== ARTICLE && ev.kind !== POLL && ev.kind !== COMMENT && !zapRec; const altText = foreign ? ((ev.tags.find((x) => x[0] === 'alt') || [])[1] || t('noteForeignKind', { kind: ev.kind })) : null; - const isReply = ev.kind === COMMENT || (!foreign && ev.tags.some((x) => x[0] === 'e')); + const isReply = ev.kind === COMMENT || (!foreign && !zapRec && ev.tags.some((x) => x[0] === 'e')); const canZap = canZapPk(pk); // an optimistic post mid-publish: visible but not yet a real event — // dimmed, and no thread/reply/zap until its signed self takes over @@ -9368,7 +9374,11 @@ export function messagesFeature(ctx) { style: 'flex-shrink:0', onClick: (e) => { e.stopPropagation(); ui.noteSheet = ev; render(); }, }, '\u22ef')), - foreign + zapRec + ? h('div', { class: 'note-text', style: 'white-space:pre-wrap;overflow-wrap:anywhere' }, + h('span', { class: 'note-zap-line' }, '\u26a1 ' + t('zapRowText', { n: receiptSats(ev).toLocaleString() })), + zapText(ev) ? h('div', {}, ...noteBody(zapText(ev))) : null) + : foreign ? h('div', { class: 'note-text small muted', style: 'white-space:pre-wrap;overflow-wrap:anywhere' }, (ev.kind === 64 ? '\u265f ' : '') + altText) : h('div', { class: 'note-text', style: 'white-space:pre-wrap;overflow-wrap:anywhere' }, ...(ev.kind === ARTICLE ? (open ? [articleCard(ev)] : articleBody(ev)) : noteBody(shownTranslation(ev)?.text ?? noteText(ev), 0, noteEmojiTags(ev)))), foreign || pending ? null : translateLine(ev), diff --git a/src/i18n.js b/src/i18n.js index 9df0127..9c3efe3 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -595,6 +595,7 @@ const STR = { arkFeeService: 'Service fee', arkCoinsExpired: 'expired', noteForeignKind: 'A kind {kind} event this app doesn’t show.', + zapRowText: 'zapped {n} sats', pollVoter: '{n} vote', pollVoters: '{n} votes', pollMulti: 'Pick any', diff --git a/src/style.css b/src/style.css index a3abb75..4df04d7 100644 --- a/src/style.css +++ b/src/style.css @@ -1622,3 +1622,5 @@ body::after { cursor: pointer; text-decoration: underline; text-underline-offset: 2px; min-height: 0; } .note-translate-btn:hover { color: var(--ink); } +/* a zap receipt shown as a row: what was sent, in the zap colour */ +.note-zap-line { color: #e6a800; font-weight: 650; } diff --git a/tools/zap-receipt-row-test.js b/tools/zap-receipt-row-test.js new file mode 100644 index 0000000..c89e351 --- /dev/null +++ b/tools/zap-receipt-row-test.js @@ -0,0 +1,71 @@ +// A zap receipt opened as a note (someone reacted to a zap, and the reaction +// was followed) reads as the zap: the zapper's name, the amount, what they +// said — not "a kind 9735 event this app doesn't show" by the LNURL server. +// Run: bun tools/zap-receipt-row-test.js +import puppeteer from './puppeteer.js'; +import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure'; +import { neventEncode } from 'nostr-tools/nip19'; +import { buildHtml } from '../build.js'; +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +let ok = true; +const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; }; +const key = () => { const sk = generateSecretKey(); return { sk, pk: getPublicKey(sk) }; }; +const AUTHOR = key(), ZAPPER = key(), SERVER = key(); +const now = Math.floor(Date.now() / 1000); +const POST = finalizeEvent({ kind: 1, created_at: now - 600, tags: [], content: 'GM, a post worth zapping' }, AUTHOR.sk); +const request = finalizeEvent({ kind: 9734, created_at: now - 300, content: 'great post!', tags: [['e', POST.id], ['p', AUTHOR.pk], ['amount', '21000']] }, ZAPPER.sk); +const RECEIPT = finalizeEvent({ kind: 9735, created_at: now - 299, content: '', tags: [['e', POST.id], ['p', AUTHOR.pk], ['description', JSON.stringify(request)]] }, SERVER.sk); +const PROFILES = [ + finalizeEvent({ kind: 0, created_at: now - 10, tags: [], content: JSON.stringify({ name: 'Zapper Zed' }) }, ZAPPER.sk), + finalizeEvent({ kind: 0, created_at: now - 10, tags: [], content: JSON.stringify({ name: 'Lightning Server' }) }, SERVER.sk), +]; +const FX = [POST, RECEIPT, ...PROFILES]; + +const html = await buildHtml({ minify: true, pwa: false }); +const server = Bun.serve({ port: 0, fetch: () => new Response(html, { headers: { 'content-type': 'text/html' } }) }); +const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] }); +const page = await browser.newPage(); +await page.evaluateOnNewDocument((fx) => { + const fits = (ev, f) => (!f.kinds || f.kinds.includes(ev.kind)) && (!f.ids || f.ids.includes(ev.id)) && (!f.authors || f.authors.includes(ev.pubkey)) + && (!f['#e'] || ev.tags.some((t) => t[0] === 'e' && f['#e'].includes(t[1]))); + const Real = window.WebSocket; + window.WebSocket = function (...a) { + const ws = new Real(...a); + const send = ws.send.bind(ws); + ws.send = (data) => { + try { + const m = JSON.parse(data); + if (m[0] === 'REQ') { + const out = fx.filter((ev) => m.slice(2).some((f) => fits(ev, f))); + setTimeout(() => { + for (const e of out) ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EVENT', m[1], e]) })); + ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EOSE', m[1]]) })); + }, 0); + return; + } + if (m[0] === 'EVENT') return; + } catch {} + return send(data); + }; + return ws; + }; + window.WebSocket.prototype = Real.prototype; Object.assign(window.WebSocket, Real); +}, FX); +const errs = []; +page.on('pageerror', (e) => errs.push(String(e))); +const text = () => page.evaluate(() => document.body.innerText); +const waitText = async (x, ms = 20000) => { for (let i = 0; i < ms / 250; i++) { if ((await text()).includes(x)) return true; await sleep(250); } return false; }; + +try { + await page.setViewport({ width: 390, height: 844 }); + await page.goto(server.url.href + neventEncode({ id: RECEIPT.id, author: SERVER.pk, kind: 9735 }), { waitUntil: 'domcontentloaded' }); + check('the receipt opens as a zap: amount', await waitText('zapped 21 sats', 20000)); + await waitText('Zapper Zed', 8000); // the zapper's profile, once it lands + const row = await page.evaluate((id) => { const r = document.querySelector(`[data-zap-post="${id}"]`); return r ? r.innerText : ''; }, RECEIPT.id); + check('...with what the zapper said', /great post!/.test(row), row.replace(/\n+/g, ' | ').slice(0, 160)); + check('...under the zapper\'s name, not the server\'s', /Zapper Zed/.test(row) && !/Lightning Server/.test(row)); + check('...and never "this app doesn\'t show"', !/doesn’t show|doesn't show/.test(await text())); + check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | ')); +} finally { await browser.close(); server.stop(true); } +console.log(ok ? '\n✅ a zap receipt reads as the zap' : '\n❌ failed'); +process.exit(ok ? 0 : 1); |
