From 9484c2b29a621a4413b91a88391d4f299d3323a2 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 17 Aug 2026 23:54:04 -0700 Subject: The claim field greets you by name: your nostr username arrives pre-filled when the registrar confirms it's free (or already yours) — editable, never auto-claimed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01JtaatFfAbx91Nh3xqKVqKz --- src/features/names.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/features') diff --git a/src/features/names.js b/src/features/names.js index 73e34de..d3971a4 100644 --- a/src/features/names.js +++ b/src/features/names.js @@ -262,7 +262,31 @@ export function namesFeature(ctx) { // ---- UI --------------------------------------------------------------- + // Suggest the identity's own nostr username as the claim default — nobody + // should have to retype who they already are — but only when that name is + // actually free on the registrar (or already theirs to retake). + let suggestedFor = null; + function suggestName() { + const me = (hook('nostrLoginIdentity') || {}).pubkey || (wallet.nostrPubkey && wallet.nostrPubkey()); + if (!me || suggestedFor === me || ui.nameClaim) return; + suggestedFor = me; + (async () => { + try { + const prof = hook('cachedProfile', me); + const cand = String((prof && prof.name) || '').toLowerCase().replace(/[^a-z0-9._-]/g, '').slice(0, 30); + if (!cand || /^npub1/.test(cand)) return; + const r = await withTimeout( + fetch(`${REGISTRAR}/name/${encodeURIComponent(cand)}?domain=${encodeURIComponent(DOMAIN())}`).then((x) => x.json()), + 8000, 'registrar'); + const free = r && r.taken === false; + const mine = r && r.taken && r.pubkey === me; + if ((free || mine) && !ui.nameClaim) { ui.nameClaim = cand; render(); } + } catch {} + })(); + } + function claimForm(big) { + suggestName(); return h('div', { class: 'col', style: 'gap:8px;width:100%' }, ui.nameClaimError ? h('div', { class: 'notice err' }, ui.nameClaimError) : null, h('div', { class: 'row gap6' }, -- cgit v1.2.3