Files
vbb/public/assets/splash.js
T
martbost aee1ccc36a VBB purchases live + weekly prize payouts (Marty 2026-11-14: "why does it say 'coming soon' on all the stuff in it? Shouldn't it all be live already?")
Buying (VBBShop 0x36F6...07D7): Packages page has live Buy buttons for the 10 and 40 credit packs (USD price + live POL from quoteWei, SafePal or any other crypto wallet, one-time, never a subscription, where the payment goes); My Banners has "Add the banner look ($2)" on each waiting or in-loop banner (SKU 3, ref = banner id) and a 40-character teaser editor once it has the look. POST /api/my/order builds the member's buy() call on the server (fresh keeper voucher when the hub knows their sponsor, else no sponsor); the page checks the connected wallet is the member's VBB account (explains how to switch if not), checks the balance, sends with Polygon's fee floor (/api/gas), waits on /api/tx, nudges the watcher (/api/my/paid) and polls until the credits or the look arrive. Public: /api/quote, /api/gas, /api/tx/<hash>; /api/config has shop {live, contract} + explorer. The banner look on the loop: double border + star, hover teaser (always shown on touch screens; default = the link's site). Only Tokens still says coming soon. wallet.js gains sendTx/waitTx/balance (DLB flow).

Weekly prize payouts (prize.js): each Central-time week's pot = 10% of its VBBShop sales (usdCents of Purchase events by block time), $20 floor (company top-up shown to admin), $50 cap internal, half per board, 50/30/20. Every Monday the app prepares last week's plan (winners, wallets, USD; POL quoted live from the Chainlink feed the contract uses). /admin "Approve and pay" (two clicks): refuses unless PRIZE_KEY is the contract's prizeWallet(), the feed is fresh and the wallet holds the POL + gas (says how much more to send); then once per week (docstore.claim in MySQL + plan status), consecutive nonces, each hash saved as sent, stops at the first unclear send (never auto-retried), receipts watched. Ties: earlier to reach the count wins (leaderboards use the same rule). A winner that cannot be paid (the prize or company wallet) is skipped and the rest move up; an unfilled place stays in the prize wallet. /leaders shows past winners with transaction links. Posts nothing anywhere. Compose passes PRIZE_KEY.

Tests: smoke 192/192 (stand-in chain answers quoteWei + receipts: quote, order calldata + voucher, look purchase, teaser, prizes API, UI Buy buttons). New qa/chain.mjs on a local anvil with the real VBBShop + mock feed: buy -> Purchase -> credits, voucher binds sponsor, 30/10/60 split, overpay refunded, banner look; prize prepare -> short refusal -> pay 6 transfers exact POL -> paid once: 29/29. common.js?v=3, vbb.css?v=4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 09:47:58 -06:00

66 lines
4.3 KiB
JavaScript

// The splash: the loop grid, the next-shift bar, the waiting queue, and this visitor's verified visit.
(async function () {
VBB.renderNav('/'); VBB.renderFooter();
const $ = VBB.$, esc = VBB.esc;
const c = await VBB.getConfig().catch(() => ({}));
document.querySelectorAll('[data-k=perShift]').forEach(el => { el.textContent = c.perShift || 10; });
document.querySelectorAll('[data-k=views]').forEach(el => { el.textContent = VBB.n(c.viewsPerCycle || 150); });
let lastLoop = null, known = new Set(), firstPaint = true;
function render(d) {
const pct = Math.min(100, Math.round(d.progress / d.perShift * 100));
$('prog').innerHTML = d.progress + '<small> / ' + d.perShift + '</small>';
$('bar').style.width = pct + '%'; $('barWrap').setAttribute('aria-valuemax', d.perShift); $('barWrap').setAttribute('aria-valuenow', d.progress);
$('progLbl').textContent = d.held ? 'bar full: the next banner posted shifts the loop' : 'verified visitors toward the next shift';
const t = d.today || {};
$('today').textContent = VBB.n(t.shifts) + ' shifts and ' + VBB.n(t.cycles) + ' cycles today';
// the loop
const ids = d.loop.map(x => x.id + (x.look ? '*' + x.teaser : '')).join(','); // a new banner look repaints too
if (ids !== lastLoop) {
lastLoop = ids; const g = $('loop'); g.innerHTML = '';
const full = d.loop.length >= d.loopSize;
d.loop.forEach((t, i) => {
const last = full && i === d.loop.length - 1;
const el = VBB.tile(t, { pos: last ? 'NEXT OUT' : String(i + 1), cls: (last ? 'next' : '') + (!firstPaint && !known.has(t.id) ? ' fresh' : '') });
g.appendChild(el); known.add(t.id);
});
for (let i = d.loop.length; i < d.loopSize; i++) {
const a = document.createElement('a'); a.className = 'tile open'; a.href = '/my';
a.innerHTML = '<b>+</b>Open place<br>post yours'; g.appendChild(a);
}
firstPaint = false;
}
$('loopInfo').textContent = d.loop.length + ' of ' + d.loopSize + ' places filled';
// the queue
const q = $('queue'); q.innerHTML = '';
d.queue.forEach((t, i) => q.appendChild(VBB.tile(t, { pos: '#' + (i + 1) })));
$('queueEmpty').hidden = d.waiting > 0;
$('queueInfo').textContent = d.waiting ? VBB.n(d.waiting) + ' waiting' + (d.waiting > d.queue.length ? ', first ' + d.queue.length + ' shown' : '') : '';
}
async function load() { const d = await VBB.getJSON('/api/splash'); if (!d.error) render(d); }
await load(); setInterval(load, 8000);
// ---- this visit: a ticket now, redeemed once the page has been visible for visitSeconds ----
const note = $('visitNote');
const qs = new URLSearchParams(location.search);
const src = document.referrer || ''; // inside a traffic-exchange frame this is the exchange: the traffic source
const start = await VBB.post('/api/visit/start', { ref: qs.get('ref') || '', src }).catch(() => ({}));
if (!start || !start.ticket) { note.textContent = 'Share the loop: every verified visitor moves it forward.'; return; }
if (start.already) { note.textContent = 'Your visit already counted today. Thanks for pushing the loop.'; note.className = 'visit-note ok'; return; }
const need = (start.seconds || 6) * 1000;
let visible = 0, since = document.visibilityState === 'visible' ? Date.now() : 0, sent = false;
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') since = Date.now();
else if (since) { visible += Date.now() - since; since = 0; }
});
const timer = setInterval(async () => {
const v = visible + (since ? Date.now() - since : 0);
const left = Math.max(0, Math.ceil((need - v) / 1000));
if (left > 0) { note.textContent = 'Your visit counts toward the next shift in ' + left + ' second' + (left === 1 ? '' : 's') + '.'; return; }
if (sent) return; sent = true; clearInterval(timer);
const r = await VBB.post('/api/visit/seen', { ticket: start.ticket, visibleMs: v }).catch(() => ({}));
if (r.counted) { note.className = 'visit-note ok'; note.textContent = r.shifted ? 'Counted, and your visit shifted the loop!' : 'Counted. You pushed the loop one step closer to the next shift.'; load(); }
else note.textContent = r.why === 'already' ? 'Your visit already counted today. Thanks for pushing the loop.' : 'Thanks for visiting the loop.';
}, 500);
})();