8e6d2f9cd0
Member swap: My Banners shows "Swap image or link" on a banner that is waiting or in the loop, usable once (then "Swap used"). POST /api/my/banners/<id>/swap changes the image and/or link (or a Banner Spin to another of the member's own 125x125/250x250 spins via lsspins), same checks as a new post (checkLink, probeLink, upload/https image checks); id, place, clicks and loop progress stay. Logged on the banner (swaps: old/new image + link, time). No withdraw, removal or refund for members.
Admin takedown: /admin finds banners (#id, wallet, username), POST /api/admin/banners/<id>/takedown {reason required, credit: back|none}. The banner is hidden at once (splash loop + waiting line show a house tile in its place, /go goes home, no look/teaser/swap); its place rides out on time so nobody moves, then it ends with no cycle, no network views, no prize count. My Banners shows "Taken down" with the reason. Restore reverses a given credit (when the owner still holds one) and, if its place rode out meanwhile, records the cycle then. Admin ledger: GET /api/admin/actions (who, when, reason, credit decision).
Chatbot: CANNED 'swap' + FACTS line (KNOWLEDGE_DATE already 2026-11-15), chat-qa entry. my.js?v=4, admin.js?v=3, vbb.css?v=8.
Tests: smoke section 15 (swap once, refused twice, keeps place, bad link/image refused, spin swap, takedown credit back vs none, others keep places, ride-out without a cycle, restore, admin ledger, phone UI): 308/308 with the committed networksso.js; chatbot.test 182/182; qa:chain 49/49.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
114 lines
12 KiB
JavaScript
114 lines
12 KiB
JavaScript
// 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 => '<div class="stat"><b>' + esc(x[1]) + '</b><span>' + esc(x[0]) + '</span></div>').join('');
|
|
$('aRaw').textContent = JSON.stringify(s, null, 2);
|
|
prizes(); setInterval(prizes, 30000); actions();
|
|
const l = await get('/api/admin/ledger?n=300');
|
|
const who = r => r.username ? '@' + r.username : VBB.short(r.address || r.owner);
|
|
$('aMembers').innerHTML = l.members && l.members.length ? '<table class="t"><tr><th>Member</th><th class="n">Cycles</th><th class="n">Views</th></tr>' + l.members.map(m => '<tr><td>' + esc(who(m)) + '</td><td class="n">' + m.cycles + '</td><td class="n">' + VBB.n(m.views) + '</td></tr>').join('') + '</table>' : '<p class="muted">No cycles yet.</p>';
|
|
$('aLedger').innerHTML = l.entries && l.entries.length ? '<table class="t"><tr><th>When (CT)</th><th>Entry</th><th>Banner</th><th>Member</th><th class="n">Views</th><th>Status</th></tr>'
|
|
+ l.entries.map(e => '<tr><td>' + esc(new Date(e.at).toLocaleString('en-US', { timeZone: 'America/Chicago' })) + '</td><td class="mono">' + esc(e.id) + '</td><td>#' + e.bannerId + '</td><td>' + esc(who(e)) + '</td><td class="n">' + VBB.n(e.views) + '</td><td>' + esc(e.status) + '</td></tr>').join('') + '</table>' : '<p class="muted">The ledger is empty.</p>';
|
|
}
|
|
// ---- 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 = '<p class="small">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') + '.</p>';
|
|
const tx = h => z.explorer ? '<a target="_blank" rel="noopener" href="' + esc(z.explorer + '/tx/' + h) + '">' + esc(h.slice(0, 10)) + '...</a>' : esc(h);
|
|
$('pzWeeks').innerHTML = (z.weeks || []).map(w => {
|
|
const q = w.quote || {};
|
|
const lines = w.transfers.map((t, i) => '<tr><td>' + esc(t.board) + '</td><td>' + t.place + '</td><td>' + esc(t.name) + '<br><span class="mono small">' + esc(t.address) + '</span></td><td class="n">' + VBB.n(t.count) + '</td><td class="n">$' + VBB.n(t.usd) + '</td><td class="n">'
|
|
+ esc(t.pol || (q.lines && q.lines[i] ? q.lines[i].pol : '')) + '</td><td>' + esc(t.status || '') + (t.tx ? ' ' + tx(t.tx) : '') + (t.error ? '<br><span class="small">' + esc(t.error) + '</span>' : '') + '</td></tr>').join('');
|
|
let foot = '';
|
|
if (w.status === 'prepared') {
|
|
foot = q.error ? '<p class="note err">' + esc(q.error) + '</p>'
|
|
: '<p class="small">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 ? ' <b>Short by ' + esc(q.shortPol) + ' POL.</b>' : '') + (q.keyMatches ? '' : ' <b>PRIZE_KEY is missing or is not the prize wallet.</b>') + '</p>'
|
|
+ '<button class="btn small" data-pay="' + esc(w.week) + '">Approve and pay</button>';
|
|
}
|
|
return '<div class="card" style="margin:12px 0"><h3>Week of ' + esc(w.week) + ': ' + esc(pst[w.status] || w.status) + '</h3><p class="small">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' : '') + '</p>'
|
|
+ (w.transfers.length ? '<div class="scroll"><table class="t"><tr><th>Board</th><th>#</th><th>Winner</th><th class="n">Count</th><th class="n">USD</th><th class="n">POL</th><th>Status</th></tr>' + lines + '</table></div>' : '<p class="muted">Nobody on the leaderboards that week.</p>') + foot + '</div>';
|
|
}).join('') || '<p class="muted">No weeks prepared yet.</p>';
|
|
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();
|
|
};
|
|
// ---- banner takedown / restore (Marty 2026-11-15): reason required, credit back or none; restore takes a given credit back ----
|
|
const send = (u, body) => VBB.getJSON(u, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-admin-token': tok }, body: JSON.stringify(body) });
|
|
const ct = t => t ? new Date(t).toLocaleString('en-US', { timeZone: 'America/Chicago' }) + ' CT' : '';
|
|
async function actions() {
|
|
const a = await get('/api/admin/actions?n=200'); if (a.error) return;
|
|
$('aActions').innerHTML = a.actions.length ? '<table class="t"><tr><th>When (CT)</th><th>Action</th><th>Banner</th><th>Owner</th><th>By</th><th>Reason</th><th>Credit</th></tr>'
|
|
+ a.actions.map(e => '<tr><td>' + esc(ct(e.at)) + '</td><td>' + esc(e.action) + (e.cycleRecorded ? ' (cycle recorded)' : '') + '</td><td>#' + e.bannerId + '</td><td>' + esc(e.username ? '@' + e.username : VBB.short(e.owner)) + '</td><td>' + esc(e.by) + '</td><td>' + esc(e.reason || '') + '</td><td>' + esc(e.credit) + '</td></tr>').join('') + '</table>'
|
|
: '<p class="muted">No takedowns yet.</p>';
|
|
}
|
|
async function findBanners() {
|
|
const q = $('bnQ').value.trim(); if (!q) return;
|
|
const d = await get('/api/admin/banners?q=' + encodeURIComponent(q));
|
|
if (d.error) { $('bnList').innerHTML = '<p class="note err small">' + esc(d.error) + '</p>'; return; }
|
|
$('bnList').innerHTML = '';
|
|
for (const b of d.banners) {
|
|
const el = document.createElement('div'); el.className = 'adm-b';
|
|
const st = b.down ? 'TAKEN DOWN ' + ct(b.down.at) + ' by ' + b.down.by + ': ' + b.down.reason + (b.down.creditBack ? ' (credit given back)' : ' (no credit)') + '. Slot: ' + b.state
|
|
: b.state === 'queued' ? 'Waiting #' + b.position + ' of ' + b.of : b.state === 'loop' ? 'In the loop, place ' + b.place + ' of ' + b.of : b.state;
|
|
el.innerHTML = '<img alt="Banner #' + b.id + '" width="72" height="72"><div class="s"><b>#' + b.id + '</b> ' + esc(b.username ? '@' + b.username : '') + ' <span class="mono small">' + esc(b.owner) + '</span><br>'
|
|
+ esc(st) + '<br>Link: <span class="mono small">' + esc(b.link) + '</span><br><span class="muted small">' + VBB.n(b.clicks) + ' clicks. Posted ' + esc(ct(b.createdAt)) + '.'
|
|
+ (b.swaps.length ? ' Swapped ' + esc(ct(b.swaps[0].at)) + ' from ' + esc(b.swaps[0].old.link) + '.' : '') + (b.downs.length ? ' Restored before: ' + b.downs.length + 'x.' : '') + '</span><div class="act"></div></div>';
|
|
el.querySelector('img').src = b.img;
|
|
const act = el.querySelector('.act');
|
|
if (b.down) {
|
|
act.innerHTML = '<div class="field"><label>Why restore (optional)</label><input class="rs"></div><button class="btn small">Restore this banner' + (b.down.creditBack ? ' (takes the credit back)' : '') + '</button>';
|
|
act.querySelector('button').onclick = async () => {
|
|
const r = await send('/api/admin/banners/' + b.id + '/restore', { reason: act.querySelector('.rs').value });
|
|
VBB.status(r.error || ('Banner #' + b.id + ' restored.' + (r.creditReversed ? ' The credit was taken back.' : r.creditAlreadyUsed ? ' The owner already used the credit, so it was not taken back.' : '') + (r.cycle ? ' Its place had ridden out, so its cycle is recorded now.' : '')), r.error ? 'err' : 'ok');
|
|
findBanners(); actions();
|
|
};
|
|
} else if (b.state === 'queued' || b.state === 'loop') {
|
|
act.innerHTML = '<div class="field"><label>Reason (the owner sees it)</label><textarea class="why" maxlength="300"></textarea></div>'
|
|
+ '<div class="row"><label class="small"><input type="radio" name="cr' + b.id + '" value="back"> Credit back</label><label class="small"><input type="radio" name="cr' + b.id + '" value="none"> No credit</label>'
|
|
+ '<button class="btn small">Take down</button></div>';
|
|
const bt = act.querySelector('button');
|
|
bt.onclick = async () => {
|
|
const reason = act.querySelector('.why').value.trim(); const c = act.querySelector('input[type=radio]:checked');
|
|
if (reason.length < 3) return VBB.status('Write the reason first.', 'err');
|
|
if (!c) return VBB.status('Choose credit back or no credit.', 'err');
|
|
if (!bt.dataset.armed) { bt.dataset.armed = '1'; bt.textContent = 'Click again to take down #' + b.id; setTimeout(() => { if (bt.isConnected) { delete bt.dataset.armed; bt.textContent = 'Take down'; } }, 8000); return; }
|
|
const r = await send('/api/admin/banners/' + b.id + '/takedown', { reason, credit: c.value });
|
|
VBB.status(r.error || ('Banner #' + b.id + ' taken down' + (c.value === 'back' ? ', credit given back.' : ', no credit.')), r.error ? 'err' : 'ok');
|
|
findBanners(); actions();
|
|
};
|
|
}
|
|
$('bnList').appendChild(el);
|
|
}
|
|
}
|
|
$('bnFind').onclick = findBanners;
|
|
$('bnQ').addEventListener('keydown', e => { if (e.key === 'Enter') findBanners(); });
|
|
$('tokBtn').onclick = () => { tok = $('tok').value.trim(); open(); };
|
|
$('tok').addEventListener('keydown', e => { if (e.key === 'Enter') $('tokBtn').click(); });
|
|
if (tok) open();
|
|
})();
|