// Admin: status + the cycle reward ledger, read with the ADMIN_TOKEN (kept in this tab only). (function () { VBB.renderNav(''); const $ = VBB.$, esc = VBB.esc; let tok = ''; try { tok = sessionStorage.getItem('vbb.admin') || ''; } catch (e) {} const get = u => VBB.getJSON(u, { headers: { 'x-admin-token': tok } }); async function open() { const s = await get('/api/admin/status'); if (s.error) { VBB.status('That token was not accepted.', 'err'); return; } try { sessionStorage.setItem('vbb.admin', tok); } catch (e) {} $('tokCard').hidden = true; $('adm').hidden = false; VBB.status(''); $('aStats').innerHTML = [['Loop filled', s.loop.filled + ' / ' + s.loop.size], ['Waiting', s.queue.length], ['Next shift', s.progress + ' / ' + s.config.perShift + (s.held ? ' (held)' : '')], ['Shifts today', s.today.shifts], ['Cycles today', s.today.cycles], ['Visitors today', s.today.visits], ['Cycles total', s.totals.cycles], ['Views recorded', VBB.n(s.ledger.views)], ['Views credited', VBB.n(s.ledger.credited)], ['Members', s.members]] .map(x => '
| Member | Cycles | Views |
|---|---|---|
| ' + esc(who(m)) + ' | ' + m.cycles + ' | ' + VBB.n(m.views) + ' |
No cycles yet.
'; $('aLedger').innerHTML = l.entries && l.entries.length ? '| When (CT) | Entry | Banner | Member | Views | Status |
|---|---|---|---|---|---|
| ' + esc(new Date(e.at).toLocaleString('en-US', { timeZone: 'America/Chicago' })) + ' | ' + esc(e.id) + ' | #' + e.bannerId + ' | ' + esc(who(e)) + ' | ' + VBB.n(e.views) + ' | ' + esc(e.status) + ' |
The ledger is empty.
'; } // ---- weekly prize payouts: review, then "Approve and pay" (two clicks), once per week ---- const pst = { prepared: 'Waiting for approval', nothing: 'No winners', paying: 'Paying', sent: 'Sent, confirming', paid: 'Paid', partial: 'Partly paid: check below', 'claimed-elsewhere': 'Claimed elsewhere: check the wallet' }; async function prizes() { const z = await get('/api/admin/prizes'); if (z.error) return; const cur = z.current || {}; $('pzNow').innerHTML = 'This week (' + esc(z.week) + '): sales $' + VBB.n(cur.salesUsd) + ' in ' + VBB.n(cur.purchases) + ' purchases, 10% = $' + VBB.n(cur.shareUsd) + ', pot $' + VBB.n(cur.potUsd) + (cur.topUpUsd > 0 ? ' (company top-up $' + VBB.n(cur.topUpUsd) + ')' : '') + (cur.atCap ? ' (at the cap)' : '') + '. Prize key: ' + (z.prize.keyOn ? esc(VBB.short(z.prize.keyAddress)) : 'not set') + '.
'; const tx = h => z.explorer ? '' + esc(h.slice(0, 10)) + '...' : esc(h); $('pzWeeks').innerHTML = (z.weeks || []).map(w => { const q = w.quote || {}; const lines = w.transfers.map((t, i) => '' + esc(q.error) + '
' : 'POL at $' + Number(q.priceUsd).toFixed(4) + '. Needs ' + esc(q.totalPol) + ' POL + about ' + esc(q.gasPol) + ' POL gas. Prize wallet ' + esc(VBB.short(q.contractPrizeWallet || '')) + ' holds ' + esc(q.balancePol) + ' POL.' + (BigInt(q.shortWei || 0) > 0n ? ' Short by ' + esc(q.shortPol) + ' POL.' : '') + (q.keyMatches ? '' : ' PRIZE_KEY is missing or is not the prize wallet.') + '
' + ''; } return 'Sales $' + VBB.n(w.salesUsd) + ', pot $' + VBB.n(w.potUsd) + ', paying $' + VBB.n(w.payUsd) + (w.unfilledUsd > 0 ? ', $' + VBB.n(w.unfilledUsd) + ' unfilled (stays in the prize wallet)' : '') + (w.payment && w.payment.priceUsd ? ', paid at $' + Number(w.payment.priceUsd).toFixed(4) + '/POL' : '') + '
' + (w.transfers.length ? '| Board | # | Winner | Count | USD | POL | Status |
|---|
Nobody on the leaderboards that week.
') + foot + 'No weeks prepared yet.
'; document.querySelectorAll('[data-pay]').forEach(b => { b.onclick = async () => { const wk = b.dataset.pay; if (!b.dataset.armed) { b.dataset.armed = '1'; b.textContent = 'Click again to send the POL for ' + wk; setTimeout(() => { if (b.isConnected) { delete b.dataset.armed; b.textContent = 'Approve and pay'; } }, 8000); return; } b.disabled = true; b.textContent = 'Sending...'; const r = await VBB.getJSON('/api/admin/prizes/pay', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-admin-token': tok }, body: JSON.stringify({ week: wk, confirm: wk }) }); VBB.status(r.error || 'Payout sent for the week of ' + wk + '. Receipts confirm below.', r.error ? 'err' : 'ok'); prizes(); }; }); } $('pzPrep').onclick = async () => { const r = await VBB.getJSON('/api/admin/prizes/prepare', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-admin-token': tok }, body: '{}' }); VBB.status(r.error || 'Prepared the week of ' + r.week + '.', r.error ? 'err' : 'ok'); prizes(); }; $('tokBtn').onclick = () => { tok = $('tok').value.trim(); open(); }; $('tok').addEventListener('keydown', e => { if (e.key === 'Enter') $('tokBtn').click(); }); if (tok) open(); })();