// Live ledger: recent history + SSE stream of new chain events. (async function () { await IAP.renderNav('ledger'); const c = await IAP.getConfig(); IAP.$('contractLink').href = c.explorer ? c.explorer + '/address/' + c.contract : '/contract'; const feed = IAP.$('feed'); const { events } = await (await fetch('/api/feed?n=150')).json(); feed.innerHTML = ''; if (!events.length) feed.innerHTML = '
No activity yet. The first purchase will appear here the moment it lands.
'; for (const ev of events) feed.appendChild(IAP.feedRow(ev, c)); try { const stats = await (await fetch('/api/stats')).json(); IAP.$('statLine').textContent = stats.onchainMembers + ' on-chain member(s)'; } catch (e) {} IAP.adSlot('banner', 'adSlotBanner'); IAP.adSlot('text', 'adSlotText'); const es = new EventSource('/api/feed/live'); es.onopen = () => { const b = IAP.$('liveBadge'); b.textContent = '● live'; }; es.onerror = () => { const b = IAP.$('liveBadge'); b.textContent = 'reconnecting…'; }; 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) {} }; })();