// The small pages: transplanted, ledger, contract, promote (one file; each part runs only on its own page).
(async function () {
const $ = YPB.$, esc = YPB.esc, path = location.pathname.replace(/\/$/, '');
const c = await YPB.getConfig().catch(() => ({}));
if (path === '/transplanted') {
const d = await YPB.getJSON('/api/transplanted');
$('inReview').textContent = d.inReview ? d.inReview + ' more ' + (d.inReview === 1 ? 'packet is' : 'packets are') + ' in review now.' : '';
$('tList').innerHTML = (d.items || []).length ? d.items.map(x => YPB.packetCard(x, { place: 'transplanted' })).join('') : '
Nothing transplanted yet. The first packet to reach ' + YPB.n(c.reviewSaves) + ' saved IDs goes to review.
';
YPB.decorate(); return;
}
if (path === '/ledger') {
const d = await YPB.getJSON('/api/ledger?n=100');
const t = d.totals || {};
$('ledgerStats').innerHTML = [['Spotlights', YPB.n(t.spotlights)], ['Paid in, USD', YPB.usd(t.usdCents)], ['Paid in, POL', YPB.polOf(t.weiPaid)], ['Paid to sponsor lines, POL', YPB.polOf(t.levelsWei)]].map(s => '' + s[1] + ' ' + s[0] + '
').join('');
const who = (n, a) => n ? '@' + esc(n) : esc(YPB.short(a));
$('rows').innerHTML = (d.items || []).length ? d.items.map(x => '' + esc(YPB.when(x.at)) + (d.explorer ? 'tx ' : '') + ' ' + who(x.buyerName, x.buyer) + ' ' + (x.packet ? '' + esc(x.packet.name) + ' ' : '') + ' ' + YPB.usd(x.usdCents) + ' ' + YPB.polOf(x.weiPaid) + ' POL '
+ x.pays.map(p => esc(p.label) + ': ' + YPB.polOf(p.wei) + ' POL' + (p.kind ? ' to ' + who(p.name, p.to) : '') + (p.failed ? ' (waiting to claim)' : '')).join(' ') + ' ' + YPB.n(x.delivery.delivered) + ' / ' + YPB.n(x.delivery.views) + '' + esc(x.delivery.status) + ' ').join('')
: '' + (d.contract ? 'No Spotlights yet.' : 'No Spotlights yet: the YPBShop contract is not deployed. Every payment will show here with its transaction.') + ' ';
return;
}
if (path === '/contract') {
const d = await YPB.getJSON('/api/contract');
const lv = (d.split || {}).levelBps || [];
const company = YPB.pct(10000 - lv.reduce((t, x) => t + x, 0));
const rows = [
['Status', d.deployed ? 'Deployed on Polygon' : 'Not deployed yet. These are the planned values; nothing can be bought until it is.'],
['Address', d.address ? '' + esc(d.address) + ' ' + (d.explorer ? ' (Polygonscan )' : '') : 'not deployed'],
['Verified source', d.verified && (d.verified.sourcify || d.verified.polygonscan) ? [d.verified.polygonscan ? 'Polygonscan' : '', d.verified.sourcify ? 'Sourcify' : ''].filter(Boolean).join(' and ') : 'after deploy'],
['Split', lv.map((b, i) => 'level ' + (i + 1) + ' ' + YPB.pct(b)).join(', ') + ', company ' + company + ' (immutable)'],
['Spotlight', d.sku ? YPB.usd(d.sku.usdCents) + ' for ' + YPB.n(d.sku.views) + ' views' + (d.sku.active ? '' : ' (switched off)') : '$' + (d.spotlight || {}).usd + ' for ' + YPB.n((d.spotlight || {}).views) + ' views (planned)'],
['Price changes', 'wait ' + d.skuDelayHours + ' hours on chain' + (d.pendingSku ? '. Pending: ' + YPB.usd(d.pendingSku.usdCents) + ' for ' + YPB.n(d.pendingSku.views) + ' views, from ' + YPB.when(d.pendingSku.eta * 1000) : '')],
['Company wallet', '' + esc(d.company || '') + ' '],
['Owner', d.owner ? '' + esc(d.owner) + ' (' + esc(d.ownerNote) + ')' : esc(d.ownerNote) + ' (after deploy)'],
['Paused', d.deployed ? (d.paused ? 'yes (new Spotlights stopped; claims stay open)' : 'no') : 'n/a']];
if (d.error) rows.push(['Note', esc(d.error)]);
$('cBox').innerHTML = '' + rows.map(r => '' + r[0] + ' ' + r[1] + ' ').join('') + '
';
return;
}
if (path === '/promote') {
const me = await YPB.getJSON('/api/me');
const k = await YPB.getJSON('/api/promo-kit' + (me.signedIn && me.username ? '?u=' + encodeURIComponent(me.username) : ''));
const link = (k.links || [])[0]; $('myLink').textContent = link ? link.tracked || link.url : ''; $('copyLink').onclick = e => YPB.copy($('myLink').textContent, e.target);
const box = t => '' + esc(t) + ' Copy
';
$('lines').innerHTML = (k.lines || []).concat(k.posts || []).map(box).join('');
$('email').innerHTML = '' + esc(k.email.subject) + '
' + box(k.email.body);
$('creatives').innerHTML = (k.creatives || []).length ? k.creatives.map(x => '' + esc(x.angleLabel + ', ' + x.label + ' ' + x.w + 'x' + x.h) + '
' + box(x.html) + '
').join('') : 'Banners are on their way.
';
$('kitNote').textContent = k.note || '';
document.querySelectorAll('[data-copy]').forEach(b => { b.onclick = () => YPB.copy(b.previousElementSibling.textContent, b); });
}
})();