Files
martbost f41d1ef384 Launch week: Founder badge + launch week contest (Marty approved 2026-11-05, PLAN.md options B and C)
Founder badge (cosmetic only: no credits, no POL, no perks, never posted to Telegram)
- Criterion: the account's earliest signed-in visit is before the launch moment (launchAt, default
  2026-11-15T06:00:00-06:00). Field: accounts.firstSeen, else lastSeen. Both are written only by
  accounts.touchSeen() on signed-in requests (dashboard, ping, chat); touchSeen now keeps firstSeen =
  the previous lastSeen on the next visit, so a pre-launch member who signs in again after launch still
  qualifies. Carried-over shells that never signed in have neither field and never qualify.
- Stored flag accounts.founder (JSON + MySQL column). Grant: launchweek.tick every 10 minutes from the
  launch moment, idempotent, one run per 10-minute slot across app copies (marks.claim); founderGrant '0'
  turns it off. Admin preview + "Grant Founder badges now" (refused before launch).
- Shown in the badge strip (on the way before launch, Share works, no Telegram post), wall (wall-founder.js),
  Team rows (my.js + team.js), the Team activity chip, and next to names on /leaderboard. Art:
  /badges/badge-founder.jpg, drawn in code in the existing card layout.

Launch week contest
- Window [launchContestStart or launchAt, launchContestEnd) = Sun Nov 15 6:00 AM to the end of Sat Nov 21,
  Central (end stored exclusive, 2026-11-22T00:00:00-06:00). Count = the weekly board's tier-1 TierPaid
  sales. Never counted: own positions, buys by linked positions (Qualified Start), the admin account and
  overrideHouseIds (as contestants or buyers), launchContestExcludeEmails/Ids. launchContestMinSales 2.
  Ties: sales, dollars, who got there first. Prizes launchContestPrizesPol '10,6,4'.
- Payout only by Admin > Launch week > Pay launch contest: the ranking is frozen on the first press, the
  admin's confirmed list must match it, balance + gas checked first, each place claimed once (marks.claim)
  and written as sending before award(memberId) from the Level 4 override payer wallet
  (override.payerHandle). Records tx hashes; resolve paid-with-tx or retry for blocked/failed/review.
  The prize email + feed line say "Launch week contest prize".
- /leaderboard panel from the launch moment until the prizes are paid; /launch copy states both rules.
- chatbot: CANNED founder-badge + launch-contest, FACTS lines (no amounts quoted before launch).
- qa/launchweek.test.cjs (16 checks: Central window bounds, exclusions, minimum, two-copy payout once,
  frozen result, Founder criterion + grant, touchSeen backfill); run.sh launchweek and in all.
- Versions: my.js?v=20261105fd, team.js?v=20261105fd, wall-founder.js?v=20261105fd,
  admin-launchweek.js?v=20261105lw (wall.js unchanged: the shared policy test pins it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 08:14:28 -06:00

45 lines
4.9 KiB
JavaScript

// Admin > Launch week (2026-11-05): Founder badge preview + grant, launch contest standings and the "Pay launch contest" button.
// The pay button sends real POL from the Level 4 override payer wallet. It shows the frozen ranking and amounts first and
// sends exactly that list; the server refuses if anything changed, and every place is paid at most once.
(function () {
const $ = IAP.$;
if (!$('lwCard')) return;
const esc = s => String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
async function api(path, body) {
const r = await (await fetch(path, body === undefined ? { cache: 'no-store' } : { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) })).json();
if (r.error) throw new Error(r.error === 'auth' ? 'Session expired. Sign in again.' : r.error);
return r;
}
let last = null;
async function load() {
let r; try { r = await api('/api/admin/launch-week'); } catch (e) { $('lwFounder').textContent = 'Could not read launch week: ' + e.message; return; }
last = r;
const f = r.founder || {};
$('lwFounder').innerHTML = '<b>Founder badge</b> (cosmetic): accounts whose earliest signed-in visit (' + esc(f.field) + ') is before ' + esc(f.launchAtCT) + ' Central. '
+ '<b>' + (f.qualify || 0) + '</b> qualify today of ' + (f.accounts || 0) + ' accounts (' + (f.neverSignedIn || 0) + ' never signed in). Granted: ' + (f.granted || 0) + ', still to grant: ' + (f.missing || 0) + '. '
+ (f.launched ? 'Launch has passed; the automatic grant runs every 10 minutes' : 'The automatic grant starts at the launch moment') + (f.autoGrant ? '.' : ' (switched OFF: founderGrant = 0).');
$('lwGrant').hidden = !f.launched;
const w = r.window || {};
$('lwWindow').innerHTML = '<b>Launch week contest</b>: ' + esc(w.startCT) + ' to ' + esc(w.endCT) + ' Central · ' + (w.open ? (w.started ? 'OPEN' : 'not started') : 'CLOSED')
+ ' · minimum ' + r.minSales + ' sales to place · prizes ' + (r.prizes || []).map((p, i) => (i + 1) + ': ' + p + ' POL').join(', ')
+ ' · excluded: ' + esc((r.excluded.emails || []).join(', ')) + ' and member #' + esc((r.excluded.ids || []).join(', #'))
+ ' · payer ' + (r.payer.keyPresent ? esc(r.payer.address) + ' holds ' + esc(r.payer.balancePol || '?') + ' POL' : 'NOT configured');
$('lwStand').innerHTML = (r.standings || []).length ? '<table><tr><th>#</th><th>Member</th><th>Pays to</th><th>Sales</th><th>$</th><th>Places?</th></tr>' + r.standings.map(x => '<tr><td>' + x.rank + '</td><td>' + esc(x.name) + ' <span class="muted">' + esc(x.email) + '</span></td><td>#' + x.memberId + '</td><td>' + x.sales + '</td><td>$' + x.usd + '</td><td>' + (x.qualifies ? 'yes' : 'no') + '</td></tr>').join('') + '</table>' : '<p class="muted">No counted sales in the window yet.</p>';
$('lwPayouts').innerHTML = (r.payouts || []).length ? '<p><b>Payout records</b> (frozen ' + new Date(r.frozen.at).toLocaleString('en-US', { timeZone: 'America/Chicago' }) + ' CT)</p><table><tr><th>Place</th><th>Member</th><th>POL</th><th>State</th><th>Tx</th></tr>' + r.payouts.map(x => '<tr><td>' + x.place + '</td><td>' + esc(x.name) + ' #' + x.memberId + '</td><td>' + esc(x.pol) + '</td><td>' + esc(x.state) + (x.note ? ' <span class="muted">' + esc(x.note) + '</span>' : '') + '</td><td>' + (x.tx ? '<a href="' + esc(x.tx) + '" target="_blank" rel="noopener">tx</a>' : '') + '</td></tr>').join('') + '</table>' : '';
$('lwPay').hidden = !r.canPay || !(r.wouldPay || []).length || (r.payouts || []).length && r.payouts.every(x => x.state === 'paid');
}
$('lwRefresh').addEventListener('click', load);
$('lwGrant').addEventListener('click', async () => {
try { const r = await api('/api/admin/launch-week/founders', {}); IAP.status('Founder badge: granted to ' + (r.granted || 0) + ' accounts' + (r.skipped ? ' (' + r.skipped + ')' : '') + '.', 'ok'); load(); } catch (e) { IAP.status(e.message, 'bad'); }
});
$('lwPay').addEventListener('click', async () => {
await load(); if (!last) return;
const list = last.wouldPay || []; if (!list.length) { IAP.status('Nobody placed: nothing to pay.', 'bad'); return; }
const total = list.reduce((n, x) => n + Number(x.pol), 0);
const text = list.map(x => 'Place ' + x.place + ': ' + x.name + ' (member #' + x.memberId + ', ' + x.sales + ' sales) gets ' + x.pol + ' POL').join('\n') + '\n\nTotal ' + total + ' POL plus gas, sent from the payer wallet with award(memberId). Each place is paid once.';
if (!await IAP.confirmBox(text, { title: 'Pay the launch week contest?', ok: 'Pay ' + total + ' POL', cancel: 'Cancel' })) return;
try { const r = await api('/api/admin/launch-week/pay', { confirm: true, places: list.map(x => ({ place: x.place, memberId: x.memberId, pol: x.pol })) }); IAP.status('Launch contest: ' + (r.paidNow || 0) + ' paid now.', 'ok'); load(); } catch (e) { IAP.status(e.message, 'bad'); load(); }
});
load();
})();