From 2cd42f811d33a74c3ca28094176c009c0388da9b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 23 Nov 2026 09:22:47 -0700 Subject: A coinos name has a public pay page: v3.coinos.io//receive. "The old Coinos I could point this link onto my website give people the ability to Donate/Pay in Bitcoin and Lighting - https://coinos.io/JuryImagePro/receive - I'm not seeing an option to do this thru V3, am I missing something?" (JuryImagePro, relayed by Adam 2026-11-23). v3 had no page a visitor could pay a name from: tapping pay on a profile asks a visitor to sign in. //receive and //pay now open a small page of their own (dist/pay/index.html from src/pay-page.js, 39 KB, not the app): the name's face, a LNURL QR any Lightning wallet can pay with an amount picked there, the address to copy, and a form for a set amount and a note that makes an invoice (QR, copy, open in wallet). When coinos' node minted the invoice the page says Paid once it settles (LUD-21 verify, coinosv3-server e40c5eb); when the recipient's own wallet minted it, the page says to pay it from the wallet. ?amount= fills in the amount. Lightning only: a v3 name publishes no on-chain address. Receive → More options → Payment page shows the link with Copy and Open page. nginx on cs routes the two paths to the page; the service worker leaves them alone. New pay-page-test (set amount + note, Paid, no-verify invoice, minimum, unknown name) and names-pay-page-link-test pass; names-invoice-expiry, features-smoke and feature-registry-check pass. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6Upic5L6MMJzkTn8zg --- src/features/names.js | 20 ++++++ src/i18n.js | 4 ++ src/pay-page.html | 67 ++++++++++++++++++ src/pay-page.js | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 281 insertions(+) create mode 100644 src/pay-page.html create mode 100644 src/pay-page.js (limited to 'src') diff --git a/src/features/names.js b/src/features/names.js index e1f23ce..701b474 100644 --- a/src/features/names.js +++ b/src/features/names.js @@ -889,6 +889,23 @@ export function namesFeature(ctx) { h('p', { class: 'small muted', style: 'margin:0' }, t('namesZapCodeHow'))); } + // The public pay page (v3.coinos.io//receive, src/pay-page.js): the + // link a website puts behind its Donate button, as coinos.io//receive + // was on the old coinos. coinos.io names only: the page pays those. + function payPagePane() { + const st = load(); + const domain = st.domain || DOMAIN(); + if (!st.name || (domain !== 'coinos.io' && domain !== 'staging.coinos.io')) return h('div', { class: 'small muted' }, t('namesNeedArk')); + const host = domain === 'staging.coinos.io' ? location.origin : 'https://v3.coinos.io'; + const link = `${host}/${st.name}/receive`; + return h('div', { class: 'col', style: 'gap:10px;width:100%;align-items:center' }, + h('div', { class: 'addr-box break', style: 'width:100%' }, link), + h('div', { class: 'row gap6' }, + copyBtn(link, t('copy')), + h('button', { class: 'btn-ghost btn-sm', onClick: () => window.open(link, '_blank', 'noopener') }, t('namesPageOpen'))), + h('p', { class: 'small muted', style: 'margin:0' }, t('namesPageHow'))); + } + // ---- more options ------------------------------------------------------- // The address covers almost everyone; behind one link live the other codes // a payer might insist on. @@ -901,6 +918,7 @@ export function namesFeature(ctx) { h('strong', { class: 'small' }, label), h('span', { class: 'small muted' }, how)); return h('div', { class: 'list', style: 'width:100%' }, + opt('page', t('namesMorePage'), t('namesMorePageHow')), opt('bolt11', t('namesMoreBolt11'), t('namesMoreBolt11How')), opt('bolt12', t('namesMoreBolt12'), t('namesMoreBolt12How'), loadOffers), opt('ark', t('namesMoreArk'), t('namesMoreArkHow')), @@ -927,12 +945,14 @@ export function namesFeature(ctx) { ark: t('namesMoreArk'), clink: t('namesMoreClink'), ownnode: t('namesOwnNode'), + page: t('namesMorePage'), }; const body = ui.namesMore === 'bolt11' ? invoicePane() : ui.namesMore === 'bolt12' ? offerPane() : ui.namesMore === 'ark' ? arkPane() : ui.namesMore === 'clink' ? clinkPane() : ui.namesMore === 'ownnode' ? ownNodeSection() + : ui.namesMore === 'page' ? payPagePane() : menuPane(); return h('div', { class: 'col', style: 'gap:10px;width:100%' }, h('div', { class: 'row between', style: 'align-items:baseline' }, diff --git a/src/i18n.js b/src/i18n.js index 76efc72..e3a1ad7 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -1613,6 +1613,10 @@ const STR = { namesMoreArkHow: 'Get paid directly from any Ark wallet', namesMoreClink: 'Nostr offer (CLINK)', namesMoreClinkHow: 'A static code Nostr wallets can pay', + namesMorePage: 'Payment page', + namesMorePageHow: 'A link for your website: anyone can pay you over Lightning', + namesPageHow: 'Put this link behind a "Donate" or "Pay in Bitcoin" button. Whoever opens it can pay you over Lightning from any wallet, no account needed. Add ?amount=5000 to the link to fill in an amount.', + namesPageOpen: 'Open page', namesMoreOnchain: 'Bitcoin address (on-chain)', namesMoreOnchainHow: 'Switch to Savings for a regular on-chain address', namesInvAmountPh: 'Amount (sats)', diff --git a/src/pay-page.html b/src/pay-page.html new file mode 100644 index 0000000..87c4739 --- /dev/null +++ b/src/pay-page.html @@ -0,0 +1,67 @@ + + + + + + +Pay with Lightning · coinos + + + + + +
+ + +
Pay with Lightning
+
+
+

Loading…

+ +
+ + + diff --git a/src/pay-page.js b/src/pay-page.js new file mode 100644 index 0000000..d34b1a5 --- /dev/null +++ b/src/pay-page.js @@ -0,0 +1,190 @@ +// v3.coinos.io//receive (and //pay): a page anyone can open to +// pay a coinos name over Lightning, no wallet of their own on this site +// needed. The link a shop or a blog puts behind its "Donate / Pay in +// Bitcoin" button, as coinos.io//receive was on the old coinos +// ("The old Coinos I could point this link onto my website ... I'm not +// seeing an option to do this thru V3", JuryImagePro, relayed by Adam +// 2026-11-23). +// +// Its own small page, not the app: a visitor from a website should not +// boot a whole wallet to see a QR code. Everything comes from the names +// registrar's public LNURL-pay endpoints; the invoice is minted by the +// recipient's wallet when it is open, by coinos' node otherwise (forwarded +// on settle). Only the second can be watched (LUD-21 verify), so the page +// says "Paid" when it can and otherwise leaves it to the payer's wallet. +// +// On-chain is not offered: a v3 name publishes no on-chain address. + +import { bech32 } from '@scure/base'; +import { qrSvg } from './qr.js'; + +const REGISTRAR = 'https://names.coinos.io'; +const DOMAIN = /(^|\.)staging\./.test(location.hostname) ? 'staging.coinos.io' : 'coinos.io'; +const PROFILE_RELAYS = ['wss://relay.coinos.io', 'wss://purplepag.es', 'wss://relay.damus.io']; + +const $ = (id) => document.getElementById(id); +const el = (tag, attrs = {}, ...kids) => { + const n = document.createElement(tag); + for (const [k, v] of Object.entries(attrs)) { + if (v == null || v === false) continue; + if (k.startsWith('on')) n.addEventListener(k.slice(2).toLowerCase(), v); + else if (k === 'html') n.innerHTML = v; + else n.setAttribute(k, v === true ? '' : v); + } + for (const k of kids.flat()) if (k != null && k !== false) n.append(k); + return n; +}; +const fmt = (n) => Number(n).toLocaleString('en-US'); + +const m = location.pathname.match(/^\/([A-Za-z0-9_][A-Za-z0-9._-]{0,29})\/(?:receive|pay)\/?$/); +const name = m ? m[1].toLowerCase() : ''; +const address = `${name}@${DOMAIN}`; +const lnurlpUrl = `${REGISTRAR}/lnurlp/${encodeURIComponent(name)}?domain=${encodeURIComponent(DOMAIN)}`; +const params = new URLSearchParams(location.search); + +let payReq = null; // the name's LNURL-pay answer +let watch = null; // the verify poll for the invoice on screen + +async function getJson(url, ms = 10000) { + const r = await fetch(url, { signal: AbortSignal.timeout(ms) }); + const j = await r.json().catch(() => null); + if (!r.ok || !j || j.status === 'ERROR') throw new Error((j && j.reason) || `HTTP ${r.status}`); + return j; +} + +// The name's face: its nostr profile, best effort. The page works without it. +function fetchProfile(pk) { + return new Promise((resolve) => { + let best = null, left = PROFILE_RELAYS.length; + const socks = []; + const done = () => { for (const s of socks) try { s.close(); } catch {} resolve(best); }; + const timer = setTimeout(done, 2500); + for (const url of PROFILE_RELAYS) { + let ws; + try { ws = new WebSocket(url); } catch { if (!--left) { clearTimeout(timer); done(); } continue; } + socks.push(ws); + ws.onopen = () => ws.send(JSON.stringify(['REQ', 'p', { kinds: [0], authors: [pk], limit: 1 }])); + ws.onmessage = (e) => { + let msg; try { msg = JSON.parse(e.data); } catch { return; } + if (msg[0] === 'EVENT' && msg[2]?.pubkey === pk && (!best || msg[2].created_at > best.created_at)) best = msg[2]; + if (msg[0] === 'EOSE' || msg[0] === 'CLOSED') { ws.close(); if (!--left) { clearTimeout(timer); done(); } } + }; + ws.onerror = () => { if (!--left) { clearTimeout(timer); done(); } }; + } + }); +} + +async function copy(text, btn) { + try { await navigator.clipboard.writeText(text); } catch { + const ta = el('textarea', {}, text); document.body.append(ta); ta.select(); + try { document.execCommand('copy'); } catch {} ta.remove(); + } + const was = btn.textContent; + btn.textContent = 'Copied'; + setTimeout(() => { btn.textContent = was; }, 1500); +} + +function qrBox(data, label) { + return el('a', { class: 'qr', href: data, 'aria-label': label, html: qrSvg(data, { ec: 'L', mode: /^[0-9A-Z $%*+\-./:]+$/.test(data) ? 'Alphanumeric' : undefined }) }); +} + +function stopWatch() { if (watch) { clearInterval(watch); watch = null; } } + +// The start: the name's own QR (any amount, picked in the payer's wallet) +// and a form for a set amount. +function showStart() { + stopWatch(); + const lnurl = bech32.encode('lnurl', bech32.toWords(new TextEncoder().encode(lnurlpUrl)), 2000).toUpperCase(); + const minSat = Math.ceil((payReq.minSendable || 1000) / 1000); + const maxSat = Math.floor((payReq.maxSendable || 1e11) / 1000); + const amount = el('input', { id: 'amount', type: 'text', inputmode: 'numeric', placeholder: 'Amount in sats', autocomplete: 'off', value: params.get('amount') || null }); + const note = payReq.commentAllowed ? el('input', { id: 'note', type: 'text', maxlength: String(payReq.commentAllowed), placeholder: 'Note (optional)', value: params.get('memo') || params.get('note') || null }) : null; + const err = el('div', { class: 'err', id: 'err' }); + const go = el('button', { class: 'primary', type: 'submit' }, 'Create invoice'); + const form = el('form', { + class: 'amount-form', + onSubmit: async (e) => { + e.preventDefault(); + err.textContent = ''; + const sat = Number(String(amount.value).replace(/[\s,_]/g, '')); + if (!Number.isInteger(sat) || sat < minSat) { err.textContent = `Enter at least ${fmt(minSat)} sats.`; amount.focus(); return; } + if (sat > maxSat) { err.textContent = `At most ${fmt(maxSat)} sats.`; amount.focus(); return; } + go.disabled = true; go.textContent = 'Creating invoice…'; + try { await createInvoice(sat, note ? note.value.trim() : ''); } catch (x) { + err.textContent = 'Could not create an invoice: ' + (x.message || x); + } finally { go.disabled = false; go.textContent = 'Create invoice'; } + }, + }, el('label', { for: 'amount' }, 'Pay a set amount'), amount, note, go, err); + const copyBtn = el('button', { class: 'ghost', type: 'button', onClick: (e) => copy(address, e.currentTarget) }, 'Copy address'); + $('body').replaceChildren( + el('div', { class: 'card' }, + qrBox('lightning:' + lnurl, 'Open in a Lightning wallet'), + el('p', { class: 'hint' }, 'Scan with any Lightning wallet and pick the amount there.'), + el('div', { class: 'row' }, el('code', { class: 'addr' }, address), copyBtn)), + el('div', { class: 'card' }, form)); +} + +async function createInvoice(sat, comment) { + const u = new URL(payReq.callback); + u.searchParams.set('amount', String(sat * 1000)); + if (comment) u.searchParams.set('comment', comment); + const j = await getJson(u.toString(), 30000); + if (!j.pr) throw new Error('no invoice came back'); + showInvoice(sat, j.pr, j.verify || null); +} + +function showInvoice(sat, pr, verify) { + stopWatch(); + const status = el('div', { class: 'status', id: 'status' }, verify ? 'Waiting for payment…' : 'Pay it from your Lightning wallet.'); + const copyBtn = el('button', { class: 'ghost', type: 'button', onClick: (e) => copy(pr, e.currentTarget) }, 'Copy invoice'); + const open = el('a', { class: 'button primary', href: 'lightning:' + pr }, 'Open in wallet'); + const back = el('button', { class: 'link', type: 'button', onClick: showStart }, '← Another amount'); + $('body').replaceChildren(el('div', { class: 'card', id: 'invoice' }, + el('div', { class: 'big' }, fmt(sat), el('span', {}, ' sats')), + qrBox('lightning:' + pr.toUpperCase(), 'Open in a Lightning wallet'), + el('div', { class: 'row' }, copyBtn, open), + status, back)); + if (!verify) return; + const started = Date.now(); + watch = setInterval(async () => { + if (Date.now() - started > 15 * 60_000) { stopWatch(); status.textContent = 'This invoice has expired.'; return; } + try { + const v = await getJson(verify, 8000); + if (v.settled) { stopWatch(); paid(sat); } + } catch {} + }, 3000); +} + +function paid(sat) { + $('body').replaceChildren(el('div', { class: 'card done', id: 'paid' }, + el('div', { class: 'tick', 'aria-hidden': 'true' }, '✓'), + el('div', { class: 'big' }, 'Paid'), + el('p', {}, `${fmt(sat)} sats sent to ${address}. Thank you!`), + el('button', { class: 'link', type: 'button', onClick: showStart }, 'Pay again'))); +} + +async function main() { + if (!name) { $('body').replaceChildren(el('div', { class: 'card' }, el('p', {}, 'No such page.'))); return; } + $('who').textContent = address; + document.title = `Pay ${address}`; + let rec = null; + try { + [payReq, rec] = await Promise.all([getJson(lnurlpUrl), getJson(`${REGISTRAR}/name/${encodeURIComponent(name)}?domain=${encodeURIComponent(DOMAIN)}`).catch(() => null)]); + } catch (x) { + $('body').replaceChildren(el('div', { class: 'card' }, el('p', { class: 'err' }, + /unknown address/i.test(x.message) ? `${address} is not a coinos address.` : `Could not reach ${address} right now. Try again in a moment.`))); + return; + } + showStart(); + const pk = rec && /^[0-9a-f]{64}$/.test(rec.pubkey || '') ? rec.pubkey : null; + if (!pk) return; + $('profile-link').href = '/' + name; + const ev = await fetchProfile(pk); + let p = null; try { p = ev && JSON.parse(ev.content); } catch {} + if (!p) return; + const shown = String(p.display_name || p.name || '').trim().slice(0, 60); + if (shown) { $('display').textContent = shown; document.title = `Pay ${shown}`; } + if (/^https:\/\//.test(p.picture || '')) { const img = $('avatar'); img.src = p.picture; img.hidden = false; } +} + +main(); -- cgit v1.2.3