// Live ledger (trust pack): every position with every share paid in the same transaction (sponsor 25%, levels 2-5 5%, with each
// person's place in the buyer's line), who was passed over, the Best Coach pot and the company, plus every Best Coach payout, from
// /api/ledger, refreshed every 30 seconds.
(function () {
FX.renderNav('/ledger'); FX.renderFooter();
const esc = FX.esc;
const pol = w => FX.polOf(w) + ' POL';
const usd = c => '$' + (Number(c || 0) / 100).toFixed(2);
const who = (a, nm) => nm ? '@' + esc(nm) : '' + esc(FX.short(a || '')) + '';
async function load() {
let d; try { d = await FX.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 = '
Positions on-chain' + FX.n(t.positions) + '
'
+ 'To the Best Coach pot' + pol(t.potWei) + '10% of every position
'
+ 'In positions' + usd(t.usdCents) + 'at the price when bought
'
+ 'Withdrawals needed0every share is paid in the same transaction
';
const body = document.querySelector('#rows tbody');
if (!d.items.length) body.innerHTML = '| No positions yet. The first one shows here within a minute of its transaction. |
';
else body.innerHTML = d.items.map(r => {
const link = 'verify';
const pays = (r.pays || []).map(p => p.level === 0 ? '5xYourTeam: ' + pol(p.wei) : p.level === 6 ? 'Best Coach pot: ' + pol(p.wei)
: (p.level === 1 ? 'Sponsor 25%' : 'Level ' + p.level + ' 5%') + ': ' + pol(p.wei) + ' to ' + (p.to ? who(p.to, p.name) : 'sponsor') + (p.depth && p.depth !== p.level ? ' (place ' + p.depth + ')' : '') + (p.failed ? ' (bounced, waiting in the contract for them to claim)' : '')).join('
');
const over = (r.passedOver || []).length ? '
Passed over (no position yet): ' + r.passedOver.map(o => (o.name ? '@' + esc(o.name) : esc(FX.short(o.who))) + ' at place ' + o.depth).join(', ') + '' : '';
return '| ' + FX.when(r.at) + ' | ' + who(r.buyer, r.buyerName) + ' bought ' + esc(r.what) + ' for ' + usd(r.usdCents) + ' | ' + pays + over + ' | ' + link + ' |
';
}).join('');
const pb = document.querySelector('#payouts tbody');
pb.innerHTML = (d.payouts || []).length ? d.payouts.map(p => '| ' + esc(p.week) + ' | #' + esc(p.rank) + ' ' + who(p.coach, p.username) + ' | ' + pol(p.wei) + ' | verify |
').join('')
: '| No Best Coach payouts yet. Each one is listed here with its transaction. |
';
}
load(); setInterval(load, 30000);
})();