// Live ledger (trust pack 2026-11-14): purchases with their split and weekly prize payouts from /api/ledger, refreshed every 30 s.
(function () {
VBB.renderNav('/ledger'); VBB.renderFooter();
const esc = VBB.esc;
const pol = w => { try { const v = BigInt(w || 0); const n = Number(v / 10n ** 12n) / 1e6; return (n >= 100 ? n.toFixed(2) : n.toFixed(4)) + ' POL'; } catch (e) { return '0 POL'; } };
const usd = c => '$' + (Number(c || 0) / 100).toFixed(2);
const when = t => t ? new Date(t).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT' : '';
const who = (a, n) => n ? '@' + esc(n) : '' + esc(VBB.short(a || '')) + '';
const ROLE = { sponsor: 'Sponsor 30%', prize: 'Prize pot 10%', company: 'Viral Banner Blitz' };
async function load() {
let d; try { d = await VBB.getJSON('/api/ledger?n=100'); } catch (e) { return; } if (!d || !d.items) return;
const ex = d.explorer || 'https://polygonscan.com'; const t = d.totals || {};
document.getElementById('totals').innerHTML = '
' + VBB.n(t.purchases) + 'purchases on-chain
'
+ '' + pol(t.sponsorWei) + 'paid to sponsors, same transaction
'
+ '' + VBB.n(t.prizePayouts) + 'weekly prize payouts
'
+ '0withdrawals needed: every purchase pays out in the same transaction
';
const body = document.querySelector('#rows tbody');
if (!d.items.length) { body.innerHTML = '| No purchases yet. The first one will show here within a minute of its transaction. |
'; return; }
body.innerHTML = d.items.map(r => {
const link = 'Polygonscan';
if (r.kind === 'prize') {
const place = ['1st', '2nd', '3rd'][r.place - 1] || '#' + r.place;
return '| ' + when(r.at) + ' | Prize ' + esc(r.name) + ', ' + place + ' place, ' + (r.board === 'sources' ? 'most traffic sources' : 'most verified visitors') + ' (week of ' + esc(r.week) + ') | '
+ '' + esc(r.pol) + ' POL ($' + Number(r.usd).toFixed(2) + ') from the prize wallet' + (r.confirmed ? '' : ' (confirming)') + ' | ' + link + ' |
';
}
const pays = (r.pays || []).map(p => esc(ROLE[p.role] || p.role) + ': ' + pol(p.wei) + (p.role === 'sponsor' ? ' to ' + who(p.to, p.name) : '') + (p.failed ? ' (bounced, waiting in the contract for them to claim)' : '')).join('
');
return '| ' + when(r.at) + ' | Purchase ' + who(r.buyer, r.buyerName) + ' bought ' + esc(r.what) + ' for ' + usd(r.usdCents) + ' | ' + pays + ' | ' + link + ' |
';
}).join('');
}
load(); setInterval(load, 30000);
})();