aboutsummaryrefslogtreecommitdiffstats
path: root/src/features
diff options
context:
space:
mode:
Diffstat (limited to 'src/features')
-rw-r--r--src/features/names.js37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/features/names.js b/src/features/names.js
index a8d762e..970a690 100644
--- a/src/features/names.js
+++ b/src/features/names.js
@@ -49,7 +49,18 @@ export function namesFeature(ctx) {
});
const j = await r.json();
if (!r.ok || j.error) throw new Error(j.error || `registrar refused (${r.status})`);
+ const prev = load().name;
save({ name, domain: DOMAIN, uri, updated: Date.now() });
+ if (prev && prev !== name) {
+ const bye = wallet.nostrSign({
+ kind: AUTH_KIND, created_at: Math.floor(Date.now() / 1000), tags: [],
+ content: JSON.stringify({ action: 'delete', name: prev, domain: DOMAIN }),
+ });
+ fetch(`${REGISTRAR}/register`, {
+ method: 'DELETE', headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ auth: bye }),
+ }).catch(() => {});
+ }
return j;
}
@@ -80,12 +91,19 @@ export function namesFeature(ctx) {
} catch {}
}
- // The record must track the wallet: re-register when the ark address moved.
+ // Everyone gets an address without being asked: the default username is a
+ // prefix of the wallet's npub — unique, boring, and free. Custom names are
+ // an optional change (and may cost something one day, to keep squatters
+ // out), so nothing here ever blocks the wallet.
async function refresh() {
try {
if (!available()) { checked = true; render(); return; }
let st = load();
if (!st.name) { await lookupMine(); st = load(); }
+ if (!st.name) {
+ const npub = wallet.nostrNpub && wallet.nostrNpub();
+ if (npub) { await claim(npub.slice(0, 20)); st = load(); }
+ }
checked = true;
render();
if (!st.name) return;
@@ -177,6 +195,10 @@ export function namesFeature(ctx) {
h('button', { class: 'btn-ghost btn-sm', onClick: async () => {
await release(); toast(t('namesReleased')); render();
} }, t('namesRelease'))),
+ h('details', { class: 'small faint' },
+ h('summary', {}, t('namesCustom')),
+ h('p', { style: 'margin:4px 0' }, t('namesCustomHow')),
+ claimForm(false)),
(() => {
const code = hook('nwcOfferString');
return code ? h('details', { class: 'small faint' },
@@ -225,19 +247,6 @@ export function namesFeature(ctx) {
render: (seg) => namePane(seg),
}];
},
- // New wallets must pick a username before using the wallet; imported
- // seeds recover theirs from the registrar and skip straight through.
- onboardingView() {
- if (!available() || !checked) return null;
- if (load().name || ui.namesLater) return null;
- return h('div', { class: 'card col', style: 'gap:12px' },
- h('h2', { style: 'margin:0' }, t('namesOnboardTitle')),
- h('p', { class: 'muted', style: 'margin:0' }, t('namesOnboardDesc')),
- claimForm(true),
- ui.nameClaimError
- ? h('button', { class: 'linklike small', onClick: () => { ui.namesLater = true; render(); } }, t('namesOnboardLater'))
- : 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