aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-02 14:41:59 -0700
committerAdam Soltys <[email protected]>2026-10-02 14:41:59 -0700
commitdbee3dddba70783aa66b933ee48a187ef758efaa (patch)
treee5f6669c5d263aa7a1fb5aa9699399cb0ed701f6
parentdb8b88b973635b7329cfd5f234c6f8dd6e9e2ccf (diff)
downloadcoinosv3-dbee3dddba70783aa66b933ee48a187ef758efaa.tar.gz
coinosv3-dbee3dddba70783aa66b933ee48a187ef758efaa.zip
Send: a lightning address moves on to the amount by itself
- Pasted with the keyboard (not only the Paste button) it is complete text: it advances at once, as a paste always did through the button. - Typed and then left alone for 0.9s, it is checked quietly (names: our registrar or BIP-353 DNS; zaps: the LNURL-pay endpoint answers) and the form moves on only if something answers. A half-typed domain answers nothing, so it just waits, with no error; finishing it moves on. - tools/send-lnaddr-advance-test.js (live registrar/DNS, [email protected]). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Dmcrt9KyNDKVWFKnb8BREo
-rw-r--r--src/app.js23
-rw-r--r--src/features/names.js8
-rw-r--r--src/features/zaps.js6
-rw-r--r--tools/send-lnaddr-advance-test.js87
4 files changed, 123 insertions, 1 deletions
diff --git a/src/app.js b/src/app.js
index b797d9e..8394561 100644
--- a/src/app.js
+++ b/src/app.js
@@ -5059,6 +5059,13 @@ function destReady(a) {
// to candidates with avatars; picking one runs the same path as pasting.
const sendSearch = { rows: null, sync: null, pick: null, el: null };
let sendRevealTimer = null;
+// A lightning address typed and then left alone: once typing has paused,
+// ask whether it's real (the names and zaps features each know a way), and
+// go on to the amount if anything answers. A half-typed domain answers
+// nothing, so it just waits, with no error.
+let sendPauseTimer = null;
+const LN_ADDRESS_SHAPE = /^[^\s@]+@[^\s@]+\.[a-z]{2,}$/i;
+const SEND_PAUSE_MS = 900;
// With the phone keyboard up, the space under the recipient field is scarce —
// park the field at the top of the view so the candidate list gets what's
// left. Runs on focus and again whenever fresh candidates land (the list
@@ -5132,6 +5139,8 @@ function recipientRow(s, r, i) {
autocapitalize: 'none', autocomplete: 'off', spellcheck: 'false', value: shown,
// one line of text: Enter doesn't break it
onKeydown: (e) => { if (e.key === 'Enter') e.preventDefault(); },
+ // pasted text is complete: it moves on at once, like the Paste button
+ onPaste: () => { r._pasted = true; },
// the delay lets the keyboard start opening (and any render() swap of
// this input) before parkSendField measures the live activeElement.
// warmSearch pre-opens the search transports so the first keystroke's
@@ -5147,7 +5156,19 @@ function recipientRow(s, r, i) {
const hadError = !!ui.sendError;
ui.sendError = ''; // editing the destination starts over — drop stale errors
if (i === 0) sendSearcher.update(v); // candidates render when results land
- if (tryFeature(v, true)) return; // a bolt11 advances to its own confirmation
+ const pasted = r._pasted; r._pasted = false;
+ clearTimeout(sendPauseTimer);
+ if (tryFeature(v, !pasted)) return; // a bolt11 (or anything pasted) advances to its own confirmation
+ if (single && LN_ADDRESS_SHAPE.test(v.trim())) {
+ sendPauseTimer = setTimeout(async () => {
+ if (r.address !== v) return;
+ const answers = featureAll('probeLnAddress', v.trim());
+ if (!answers.length) return;
+ const real = await Promise.any(answers.map((p) => Promise.resolve(p).then((x) => x || Promise.reject()))).then(() => true, () => false);
+ // still the same text, still on this form
+ if (real && r.address === v && ui.tab === 'send' && ui.send === s) tryFeature(v, false);
+ }, SEND_PAUSE_MS);
+ }
// reveal/hide amount + controls as validity flips, an annotation
// (zap button) appears/disappears, or an error clears — but only after
// typing pauses: an immediate render swaps this input for a fresh node,
diff --git a/src/features/names.js b/src/features/names.js
index 8f37b36..7e51c8c 100644
--- a/src/features/names.js
+++ b/src/features/names.js
@@ -923,6 +923,14 @@ export function namesFeature(ctx) {
render: (seg) => namePane(seg),
}];
},
+ // Is a typed name real yet? (the send form asks once typing pauses, and
+ // only moves on when something answers — never on a half-typed domain)
+ async probeLnAddress(text) {
+ const parsed = parsePaymentName(text);
+ if (!parsed) return false;
+ if (OUR_DOMAINS.includes(parsed.domain)) return !!(await registrarLookup(parsed.name, parsed.domain).catch(() => null));
+ return !!(await resolveBip353(parsed.name, parsed.domain).catch(() => null));
+ },
// BEFORE zaps in the registry: a pasted user@domain tries DNS first.
matchSendText(text, typed) {
if (typed) return false; // don't yank the form away mid-keystroke
diff --git a/src/features/zaps.js b/src/features/zaps.js
index a99de94..f0b655a 100644
--- a/src/features/zaps.js
+++ b/src/features/zaps.js
@@ -414,6 +414,12 @@ export function zapsFeature(ctx) {
begin(target, zapDisplay(target, text), tap);
return true;
},
+ // A lightning address is real when its server answers as a pay endpoint.
+ async probeLnAddress(text) {
+ const target = parseZapTarget(text);
+ if (!target || target.kind !== 'lnaddr') return false;
+ return fetchPayParams(target.url).then(() => true, () => false);
+ },
// The typed-lightning-address affordance on the send form.
sendFormNote(a) {
if (!canPay() || !ui.send || ui.send.recipients.length !== 1) return null;
diff --git a/tools/send-lnaddr-advance-test.js b/tools/send-lnaddr-advance-test.js
new file mode 100644
index 0000000..5b79a47
--- /dev/null
+++ b/tools/send-lnaddr-advance-test.js
@@ -0,0 +1,87 @@
+// A lightning address on the Send form moves on to the amount by itself
+// when it's pasted (any paste, not just the Paste button), or typed and left
+// alone a moment — but only once it's real: a half-typed domain just waits,
+// with no error. Uses the live registrar and DNS ([email protected]).
+// Run: bun tools/send-lnaddr-advance-test.js
+import puppeteer from 'puppeteer-core';
+import { generateMnemonic } from '@scure/bip39';
+import { wordlist } from '@scure/bip39/wordlists/english';
+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 html = await buildHtml({ minify: true, pwa: false });
+const server = Bun.serve({ port: 0, fetch: (req) => {
+ const p = new URL(req.url).pathname;
+ if (p.startsWith('/punks') || p === '/verify-worker.js' || p.startsWith('/locales') || /\.js$/.test(p)) { const f = Bun.file('dist' + p); return f.size ? new Response(f) : new Response('', { status: 404 }); }
+ return new Response(html, { headers: { 'content-type': 'text/html' } });
+} });
+const browser = await puppeteer.launch({ executablePath: process.env.CHROME || '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] });
+const ctx = browser.defaultBrowserContext();
+await ctx.overridePermissions(server.url.origin, ['clipboard-read', 'clipboard-write', 'clipboard-sanitized-write']);
+const page = await browser.newPage();
+const errs = []; page.on('pageerror', (e) => errs.push(String(e)));
+const click = (t) => page.evaluate((x) => { const e = [...document.querySelectorAll('button')].find((n) => n.textContent.trim().toLowerCase().includes(x)); if (e) { e.click(); return true; } return false; }, t);
+const state = () => page.evaluate(() => ({
+ amount: !!document.querySelector('input[type=number]'),
+ via: document.querySelector('.send-via')?.innerText || '',
+ field: document.querySelector('textarea.send-dest')?.value ?? null,
+ err: document.querySelector('.notice.err')?.innerText || '',
+ resolving: /looking up|resolving/i.test(document.body.innerText),
+}));
+const freshSend = async () => {
+ await page.evaluate(() => [...document.querySelectorAll('button')].find((b) => b.textContent.trim() === 'Receive')?.click()); await sleep(300);
+ await page.evaluate(() => [...document.querySelectorAll('button')].find((b) => b.textContent.trim() === 'Send')?.click());
+ await page.waitForSelector('textarea.send-dest', { timeout: 10000 });
+ await page.$eval('textarea.send-dest', (e) => { e.value = ''; e.dispatchEvent(new Event('input', { bubbles: true })); }); await sleep(300);
+ await page.focus('textarea.send-dest');
+};
+// resolved: the amount is up and the field still says the name (it went to the person's Ark address underneath)
+const moved = (s) => s.amount && s.field === '[email protected]' && /instantly/i.test(s.via);
+const waitAdvance = async (ms) => { for (let i = 0; i < ms / 250; i++) { const s = await state(); if (moved(s)) return s; await sleep(250); } return state(); };
+try {
+ await page.setViewport({ width: 390, height: 844 });
+ await page.goto(server.url.origin, { waitUntil: 'domcontentloaded' });
+ await sleep(400);
+ await click('create a new wallet'); await sleep(500); await click('to import'); await sleep(400);
+ await page.waitForSelector('textarea'); await page.type('textarea', generateMnemonic(wordlist)); await click('open wallet');
+ // mainnet onboarding: skip the username step (and anything after it)
+ for (let i = 0; i < 80 && !(await page.evaluate(() => [...document.querySelectorAll('button')].some((b) => b.textContent.trim() === 'Send'))); i++) {
+ await page.evaluate(() => [...document.querySelectorAll('button')].find((b) => /^(not now|skip|continue|later)$/i.test(b.textContent.trim()))?.click());
+ await sleep(400);
+ }
+ await sleep(3000); // features (names, zaps, ark) load
+
+ console.log('[pasted with the keyboard]');
+ await freshSend();
+ await page.evaluate(() => navigator.clipboard.writeText('[email protected]'));
+ await page.keyboard.down('Control'); await page.keyboard.press('KeyV'); await page.keyboard.up('Control');
+ let s = await waitAdvance(10000);
+ check('a pasted lightning address goes straight on to the amount', moved(s), JSON.stringify(s));
+
+ console.log('[typed, then left alone]');
+ await freshSend();
+ await page.keyboard.type('[email protected]', { delay: 60 });
+ s = await state();
+ check('nothing happens mid-typing', !s.amount && s.field === '[email protected]', JSON.stringify(s));
+ s = await waitAdvance(10000);
+ check('a moment after typing stops, it moves on by itself', moved(s), JSON.stringify(s));
+
+ console.log('[a half-typed domain]');
+ await freshSend();
+ await page.keyboard.type('[email protected]', { delay: 60 });
+ await sleep(5000);
+ s = await state();
+ check('a domain that answers nothing just waits', !s.amount && s.field === '[email protected]', JSON.stringify(s));
+ check('...with no error on screen', !s.err, s.err);
+ await page.keyboard.type('o', { delay: 60 });
+ s = await waitAdvance(10000);
+ check('finishing it then moves on', moved(s), JSON.stringify(s));
+ check('no page errors', errs.length === 0, errs.join('; ').slice(0, 300));
+} catch (e) {
+ check('run completed', false, e.stack);
+} finally {
+ await browser.close(); server.stop(true);
+}
+console.log(ok ? '\n✅ lightning addresses move on by themselves, but only once real' : '\n❌ failures above');
+process.exit(ok ? 0 : 1);