3c52e2704a
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
26 lines
1.5 KiB
JavaScript
26 lines
1.5 KiB
JavaScript
// Live ledger: recent history + SSE stream of new chain events (feed rows from common.js; no shared nav, 2026-10-07).
|
|
(async function () {
|
|
const $ = id => document.getElementById(id);
|
|
const c = await IAP.getConfig();
|
|
if (c.explorer && c.contract) $('contractLink').href = c.explorer + '/address/' + c.contract;
|
|
const feed = $('feed');
|
|
try {
|
|
const { events } = await (await fetch('/api/feed?n=150')).json();
|
|
feed.innerHTML = '';
|
|
if (!events.length) feed.innerHTML = '<div class="row muted">No activity yet. The first purchase will appear here the moment it lands.</div>';
|
|
for (const ev of events) feed.appendChild(IAP.feedRow(ev, c));
|
|
} catch (e) { feed.innerHTML = '<div class="row muted">Could not read the chain just now. Refresh in a minute.</div>'; }
|
|
try {
|
|
const stats = await (await fetch('/api/stats')).json();
|
|
$('statLine').innerHTML = 'members on-chain <b>' + Number(stats.onchainMembers || 0).toLocaleString() + '</b> · packages bought <b>' + Number(stats.purchases || 0).toLocaleString() + '</b>';
|
|
} catch (e) {}
|
|
IAP.adSlot('banner', 'adSlotBanner');
|
|
IAP.adSlot('text', 'adSlotText');
|
|
const es = new EventSource('/api/feed/live');
|
|
es.onopen = () => { $('liveBadge').textContent = 'live'; $('liveDot').className = 'dot'; };
|
|
es.onerror = () => { $('liveBadge').textContent = 'reconnecting'; $('liveDot').className = 'dot off'; };
|
|
es.onmessage = m => {
|
|
try { const ev = JSON.parse(m.data); feed.prepend(IAP.feedRow(ev, c)); while (feed.children.length > 200) feed.removeChild(feed.lastChild); } catch (e) {}
|
|
};
|
|
})();
|