Files
vbb/public/assets/leaders.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

36 lines
3.6 KiB
JavaScript

// Weekly leaderboards: top 10 by verified visitors sent, top 10 by distinct traffic sources (Central time week).
(async function () {
VBB.renderNav('/leaders'); VBB.renderFooter();
const $ = VBB.$, esc = VBB.esc;
// weekly prize pot (Marty 2026-11-13): grows with sales from a floor; paid each Monday after an admin approves it (prize.js)
const c = await VBB.getConfig().catch(() => ({}));
const pz = c.prizes || {}; const place = ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th'];
const plist = (title, arr) => '<div><h3>' + title + '</h3><ul class="pk-list">' + arr.map((v, i) => '<li>' + place[i] + ': $' + VBB.n(v) + ' in POL</li>').join('') + '</ul></div>';
if ((pz.visitors || []).length || (pz.sources || []).length) {
$('pz').innerHTML = ((pz.visitors || []).length ? plist('Most visitors sent', pz.visitors) : '') + ((pz.sources || []).length ? plist('Most traffic sources', pz.sources) : '');
if (pz.pot) $('potLbl').textContent = 'Prize pot this week: ' + (pz.atFloor ? 'at least ' : '') + '$' + VBB.n(pz.pot) + ', and it grows with sales. Half goes to each leaderboard, paid in POL to the top three (dollar value, converted to POL).';
$('prizes').hidden = false;
}
const d = await VBB.getJSON('/api/leaders');
if (d.error) return VBB.status(d.error, 'err');
const wk = new Date(d.week + 'T12:00:00Z').toLocaleDateString('en-US', { month: 'long', day: 'numeric', timeZone: 'UTC' });
$('weekLbl').textContent = 'Week of Monday ' + wk + ', Central time. Resets every Monday at 12:00 AM. Only verified visitors count: a real browser, on the page a few seconds, once a day per visitor.';
const table = (rows, main) => rows.length ? '<table class="t"><tr><th>#</th><th>Member</th><th class="n">' + (main === 'visitors' ? 'Visitors' : 'Sources') + '</th><th class="n">' + (main === 'visitors' ? 'Sources' : 'Visitors') + '</th></tr>'
+ rows.map((r, i) => '<tr><td><span class="rank">' + (i + 1) + '</span></td><td>' + esc(r.name) + '</td><td class="n"><b>' + VBB.n(r[main]) + '</b></td><td class="n">' + VBB.n(main === 'visitors' ? r.sources : r.visitors) + '</td></tr>').join('') + '</table>'
: '<p class="muted">Nobody yet this week. Share your link from <a href="/my">My Banners</a> and take the top spot.</p>';
$('lbVisitors').innerHTML = table(d.visitors, 'visitors');
$('lbSources').innerHTML = table(d.sources, 'sources');
// past weeks: winners and their payment transactions
const pr = await VBB.getJSON('/api/prizes').catch(() => ({}));
if (pr.past && pr.past.length) {
const bn = { visitors: 'Most visitors sent', sources: 'Most traffic sources' };
$('past').innerHTML = pr.past.map(w => {
const day = new Date(w.week + 'T12:00:00Z').toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric', timeZone: 'UTC' });
const rows = w.winners.map(x => '<tr><td>' + esc(bn[x.board] || x.board) + '</td><td><span class="rank">' + x.place + '</span></td><td>' + esc(x.name) + '</td><td class="n">$' + VBB.n(x.usd) + '</td><td class="n">' + esc(x.pol) + ' POL</td><td>'
+ (pr.explorer ? '<a target="_blank" rel="noopener" href="' + esc(pr.explorer + '/tx/' + x.tx) + '">' + (x.confirmed ? 'Paid' : 'Sent') + '</a>' : esc(x.tx.slice(0, 10))) + '</td></tr>').join('');
return '<div class="wk"><h3>Week of ' + esc(day) + '</h3><p class="muted small">Prize pot $' + VBB.n(w.potUsd) + (w.priceUsd ? ', POL at $' + Number(w.priceUsd).toFixed(4) : '') + '</p><div class="scroll"><table class="t"><tr><th>Board</th><th>#</th><th>Member</th><th class="n">USD</th><th class="n">POL</th><th>Transaction</th></tr>' + rows + '</table></div></div>';
}).join('');
$('pastCard').hidden = false;
}
})();