Files
banner-line/public/assets/ledger.js
T

30 lines
2.5 KiB
JavaScript

// Live ledger (Marty 2026-11-13): /api/ledger, refreshed every 20 s. One row per spot sale: buyer, every member paid, company + fund.
(async () => {
BL.renderNav('/ledger'); BL.renderFooter();
const { $, esc, fmtPol, short } = BL;
const who = (name, addr) => name ? '@' + esc(name) : '<span class="mono">' + esc(short(addr)) + '</span>';
const usd = (wei, rate) => rate ? ' <span class="muted">($' + (Number(BigInt(wei) / 10n ** 12n) / 1e6 * rate).toFixed(2) + ')</span>' : '';
const KIND = { 0: 'bought by', 1: 'bought for', 2: 'gifted by the momentum fund to', 3: 'kept by the momentum fund' };
async function load() {
const d = await BL.getJSON('/api/ledger?n=100'); if (d.error) return;
const t = d.totals || {};
$('totals').innerHTML = [['Spots sold', t.spots || 0], ['Members', t.members || 0], ['POL paid out by the contract', fmtPol(t.paidOutWei || '0', 2)], ['Momentum fund', t.fundWei ? fmtPol(t.fundWei, 2) + ' POL' : '-']]
.map(x => '<div class="stat"><b>' + esc(x[1]) + '</b><span>' + esc(x[0]) + '</span></div>').join('');
const html = d.items.map(it => {
const when = it.at ? new Date(it.at).toLocaleString() : '';
const pays = it.pays.map(p => '<li>' + (p.failed ? 'Bounced (to the fund): ' : '') + (p.role === 'sponsor' ? 'Sponsor' : 'Line ' + p.level + ' (spot #' + (it.spotId - p.level) + ')')
+ ': <b>' + fmtPol(p.wei) + ' POL</b>' + usd(p.wei, it.usd) + ' to ' + who(p.name, p.to) + '</li>').join('');
return '<div class="ledger-row"><div class="row" style="justify-content:space-between"><div><b>Spot #' + it.spotId + '</b> ' + esc(KIND[it.kind] || '') + ' ' + who(it.ownerName, it.owner)
+ ' <span class="muted">$5 = ' + fmtPol(it.valueWei) + ' POL</span></div><span class="muted small">' + esc(when) + '</span></div>'
+ (pays ? '<ul class="pays">' + pays + '</ul>' : '<p class="muted small">No earlier spots or sponsor to pay yet.</p>')
+ '<p class="small muted">Company + momentum fund: ' + fmtPol(it.houseWei) + ' POL' + usd(it.houseWei, it.usd)
+ ' &middot; <a target="_blank" rel="noopener" href="' + esc(d.explorer + '/tx/' + it.tx) + '">Verify on Polygonscan</a></p></div>';
});
$('rows').innerHTML = html.length ? html.slice(0, 10).join('') : '<p class="muted">No spot sales yet.</p>';
$('rows2').innerHTML = html.slice(10).join('');
BL.zone($('zLedger'), 'ledger');
$('upd').textContent = 'Updated ' + new Date().toLocaleTimeString();
}
await load(); setInterval(load, 20000);
})();