Design pass v1: DeFi-flash visual system with real on-chain counters
Aurora ground, glass panels, gradient pill CTAs, Sora display face, live money ticker, stat band fed by chain totals (tallied in the indexer with one-time backfill), format showcase, Branded Voice FAQ accordions. CSP extended for Google Fonts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -173,6 +173,7 @@ function decodeLog(log) {
|
||||
function loadState() {
|
||||
try { state = JSON.parse(fs.readFileSync(STATE_FILE, 'utf8')); } catch (e) { state = null; }
|
||||
if (!state || state.v !== 1) state = { v: 1, lastBlock: getConfig().deployBlock - 1, events: [] };
|
||||
if (!state.totals) { for (const ev of state.events) tally(ev); saveState(); } // one-time backfill
|
||||
}
|
||||
function saveState() {
|
||||
try {
|
||||
@@ -194,6 +195,7 @@ async function tail() {
|
||||
const ev = decodeLog(lg);
|
||||
if (!ev) continue;
|
||||
state.events.push(ev);
|
||||
tally(ev);
|
||||
if (onEvent) { try { onEvent(ev); } catch (e) { console.error('chain onEvent', e.message); } }
|
||||
}
|
||||
if (state.events.length > KEEP_EVENTS) state.events = state.events.slice(-KEEP_EVENTS);
|
||||
@@ -205,6 +207,19 @@ async function tail() {
|
||||
}
|
||||
function recentEvents(n) { return state ? state.events.slice(-(n || 100)).reverse() : []; }
|
||||
|
||||
// running totals for the public counters — every number provable on-chain
|
||||
function tally(ev) {
|
||||
if (!state.totals) state.totals = { purchases: 0, paidInWei: '0', payouts: 0, payoutWei: '0', activations: 0 };
|
||||
const t = state.totals;
|
||||
if (ev.type === 'Purchase') { t.purchases += 1; t.paidInWei = (BigInt(t.paidInWei) + BigInt(ev.paidWei)).toString(); }
|
||||
if (ev.type === 'TierPaid') { t.payouts += 1; t.payoutWei = (BigInt(t.payoutWei) + BigInt(ev.amountWei)).toString(); }
|
||||
if (ev.type === 'AwardPaid') { t.payouts += 1; t.payoutWei = (BigInt(t.payoutWei) + BigInt(ev.amountWei)).toString(); }
|
||||
if (ev.type === 'MemberActivated') t.activations += 1;
|
||||
}
|
||||
function totals() {
|
||||
return state && state.totals ? state.totals : { purchases: 0, paidInWei: '0', payouts: 0, payoutWei: '0', activations: 0 };
|
||||
}
|
||||
|
||||
function init(opts) {
|
||||
if (opts && opts.onEvent) onEvent = opts.onEvent;
|
||||
getConfig(); loadState();
|
||||
@@ -213,4 +228,4 @@ function init(opts) {
|
||||
}
|
||||
|
||||
module.exports = { init, getConfig, reloadConfig, memberIdByAccount, memberCount, member,
|
||||
product, productCount, quoteWei, creditBalance, catalog, recentEvents, rpc };
|
||||
product, productCount, quoteWei, creditBalance, catalog, recentEvents, totals, rpc };
|
||||
|
||||
Reference in New Issue
Block a user