// 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 => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[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 = 'Founder badge (cosmetic): accounts whose earliest signed-in visit (' + esc(f.field) + ') is before ' + esc(f.launchAtCT) + ' Central. ' + '' + (f.qualify || 0) + ' 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 = 'Launch week contest: ' + 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 ? '' + r.standings.map(x => '').join('') + '
#MemberPays toSales$Places?
' + x.rank + '' + esc(x.name) + ' ' + esc(x.email) + '#' + x.memberId + '' + x.sales + '$' + x.usd + '' + (x.qualifies ? 'yes' : 'no') + '
' : '

No counted sales in the window yet.

'; $('lwPayouts').innerHTML = (r.payouts || []).length ? '

Payout records (frozen ' + new Date(r.frozen.at).toLocaleString('en-US', { timeZone: 'America/Chicago' }) + ' CT)

' + r.payouts.map(x => '').join('') + '
PlaceMemberPOLStateTx
' + x.place + '' + esc(x.name) + ' #' + x.memberId + '' + esc(x.pol) + '' + esc(x.state) + (x.note ? ' ' + esc(x.note) + '' : '') + '' + (x.tx ? 'tx' : '') + '
' : ''; $('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(); })();