aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/app.js6
-rw-r--r--src/features/hats.js9
-rw-r--r--tools/hats-link-test.js46
3 files changed, 60 insertions, 1 deletions
diff --git a/src/app.js b/src/app.js
index 61e2342..0337bd7 100644
--- a/src/app.js
+++ b/src/app.js
@@ -984,7 +984,7 @@ let restoringHistory = false; // true while applying a popstate (suppresses push
// copy it, send it, reload it — the same paths the deep links already open.
// Every other screen keeps whatever path it had (the till at /pos, the
// plain app at /); only a path we set ourselves is taken back to /.
-const OWN_PATH = /^\/(nevent|note|npub|naddr)1[a-z0-9]+\/?$/i;
+const OWN_PATH = /^\/((nevent|note|npub|naddr)1[a-z0-9]+|hats)\/?$/i;
function navUrl(snap) {
try {
const fp = featureHook('navPath', snap); // a feed with a public address
@@ -7215,6 +7215,10 @@ const BOOT_POS = (() => {
} catch { return false; }
})();
if (BOOT_POS) ui.posAtBoot = true;
+// v3.coinos.io/hats: the hat shop, a link to hand someone who asks where
+// the hats are. Opened once a wallet is up (the hats feature's init); the
+// bar says /hats while the shop is on screen, so it can be copied from there.
+try { if (/^\/hats\/?$/i.test(location.pathname)) ui.hatsAtBoot = true; } catch {}
// v3.coinos.io/migrate: a link to hand someone who hasn't found the
// coinos.io move in the UI. Stashed (not just flagged) because the page it
// leads to needs an open wallet and a payment address — a fresh device gets
diff --git a/src/features/hats.js b/src/features/hats.js
index 932f908..a00f285 100644
--- a/src/features/hats.js
+++ b/src/features/hats.js
@@ -481,6 +481,15 @@ export function hatsFeature(ctx) {
node,
h('span', { class: 'ava-hat', style: posStyle(hat), html: hat.art }));
},
+ // A wallet just opened: the /hats link lands in the shop.
+ init() {
+ if (!ui.hatsAtBoot) return;
+ ui.hatsAtBoot = false;
+ ui.screen = 'wallet';
+ openShop();
+ },
+ // ...and the shop's address is /hats for as long as it is on screen
+ navPath(snap) { return snap && snap.screen === 'wallet' && snap.hatShop ? '/hats' : null; },
// The footer's "Show your support" link: straight into the shop.
openHatShop() { openShop(); try { window.scrollTo(0, 0); } catch {} return true; },
// Own-profile editor entry: the door to the shop.
diff --git a/tools/hats-link-test.js b/tools/hats-link-test.js
new file mode 100644
index 0000000..411dbd3
--- /dev/null
+++ b/tools/hats-link-test.js
@@ -0,0 +1,46 @@
+// v3.coinos.io/hats opens the hat shop. "Someone in the coinos group is
+// asking where to get hats. Can we make the hat shop have a linkable url
+// like v3.coinos.io/hats that I can direct him to?" (Adam, 2026-11-22).
+// With a wallet the link lands in the shop; the bar says /hats while the
+// shop is on screen and / again once it is left; someone with no wallet
+// gets the shop after making one.
+// Run: bun tools/hats-link-test.js
+import puppeteer, { seedWords, skipSeedCheck } from './puppeteer.js';
+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: 5348, fetch: (req) => { const p = new URL(req.url).pathname; if (p === '/verify-worker.js' || p.startsWith('/punks')) return new Response(Bun.file('dist' + p)); if (p.startsWith('/hats/')) return Response.json({ owned: [], equipped: null }); return 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();
+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 text = () => page.evaluate(() => document.body.innerText);
+const waitText = async (x, ms = 25000) => { for (let i = 0; i < ms / 250; i++) { if ((await text()).toLowerCase().includes(x.toLowerCase())) return true; await sleep(250); } return false; };
+const path = () => page.evaluate(() => location.pathname);
+try {
+ await page.setViewport({ width: 390, height: 844 });
+ await page.goto('http://localhost:5348/', { waitUntil: 'domcontentloaded' });
+ await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest'));
+ // no wallet yet: the link, then a new wallet, then the shop
+ await page.goto('http://localhost:5348/hats', { waitUntil: 'domcontentloaded' }); await waitText('create a new wallet', 20000); await sleep(400);
+ check('with no wallet the link shows the way in, not the shop', !(await text()).includes('Hat shop'));
+ await click('create a new wallet'); await sleep(600);
+ await seedWords(page);
+ await skipSeedCheck(page);
+ check('...and the shop opens once the wallet is made', await waitText('Hat shop', 25000));
+ // with a wallet: straight in
+ await page.goto('http://localhost:5348/hats', { waitUntil: 'domcontentloaded' });
+ check('with a wallet /hats opens the hat shop', await waitText('Hat shop', 25000));
+ await sleep(600);
+ check('the bar says /hats', (await path()) === '/hats', await path());
+ await page.evaluate(() => [...document.querySelectorAll('button')].find((n) => /\bback\b/i.test(n.textContent))?.click()); await sleep(900);
+ const t = await text();
+ check('Back leaves the shop', !t.includes('Hat shop'));
+ check('...and the bar is / again', (await path()) === '/', await path());
+ check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | '));
+} finally { await browser.close(); server.stop(true); }
+console.log(ok ? '\n✅ /hats opens the hat shop' : '\n❌ failed');
+process.exit(ok ? 0 : 1);