aee1ccc36a
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>
50 lines
3.2 KiB
JavaScript
50 lines
3.2 KiB
JavaScript
// Packages: live POL prices from the contract, Buy buttons for the post credit packs (one-time, never a subscription).
|
|
(async function () {
|
|
VBB.renderNav('/packages'); VBB.renderFooter();
|
|
const $ = VBB.$;
|
|
const c = await VBB.getConfig().catch(() => ({}));
|
|
const money = v => '$' + (Number.isInteger(v) ? v : Number(v).toFixed(2));
|
|
if (c.lookUsd) $('pkLook').textContent = money(c.lookUsd) + ' per banner';
|
|
const packs = (c.packs || []).slice(0, 2);
|
|
packs.forEach((p, i) => { const el = $('pkPack' + i); if (!el) return;
|
|
el.querySelector('[data-pk=credits]').textContent = VBB.n(p.credits); el.querySelector('[data-pk=usd]').textContent = money(p.usd); });
|
|
const live = !!(c.shop && c.shop.live);
|
|
let me = await VBB.getJSON('/api/me').catch(() => ({}));
|
|
function who() {
|
|
if (!live) { $('pkWho').textContent = 'Purchases are paused right now. Check back soon.'; return; }
|
|
if (me.signedIn) { $('pkWho').textContent = 'Signed in as ' + (me.username ? '@' + me.username : VBB.short(me.address)) + '. Pay from this same wallet (' + VBB.short(me.address) + ') and the credits land on your account.'; $('pkSign').hidden = true; }
|
|
else { $('pkWho').textContent = 'Sign in first, so your credits land on your account. Then pay from the same wallet.'; $('pkSign').hidden = false; }
|
|
}
|
|
who();
|
|
$('pkSignBtn').onclick = async () => {
|
|
try { VBB.status('Check your wallet for the sign-in message.'); await VBBWallet.signIn(); me = await VBB.getJSON('/api/me'); VBB.status('Signed in.', 'ok'); who(); }
|
|
catch (e) { VBB.status(String(e && e.message || e).slice(0, 300), 'err'); }
|
|
};
|
|
async function prices() {
|
|
if (!live) return;
|
|
for (let i = 0; i < packs.length; i++) {
|
|
const el = $('pkPack' + i); if (!el) continue;
|
|
const q = await VBBBuy.quote(packs[i].sku, 1).catch(() => ({ error: 'x' }));
|
|
el.querySelector('[data-pk=pol]').textContent = q.error ? 'price unavailable' : 'about ' + VBBBuy.fmtPol(q.wei, 2) + ' POL right now';
|
|
}
|
|
}
|
|
await prices(); setInterval(prices, 60000);
|
|
let busy = false;
|
|
packs.forEach((p, i) => {
|
|
const el = $('pkPack' + i); if (!el) return; const btn = el.querySelector('[data-pk=buy]');
|
|
btn.textContent = 'Buy ' + VBB.n(p.credits) + ' credits'; btn.disabled = !live;
|
|
btn.onclick = async () => {
|
|
if (busy) return; busy = true; document.querySelectorAll('[data-pk=buy]').forEach(b => { b.disabled = true; });
|
|
try {
|
|
const before = (await VBB.getJSON('/api/my')).credits;
|
|
if (before == null) throw new Error('Sign in first, so the credits land on your account.');
|
|
const r = await VBBBuy.run({ sku: p.sku, qty: 1, done: async () => { const d = await VBB.getJSON('/api/my'); return d.credits >= before + p.credits; } });
|
|
const tx = r.link ? ' Transaction: ' + r.link : '';
|
|
VBB.status(r.credited ? VBB.n(p.credits) + ' post credits added to your account. Post your banners on My Banners.' + tx
|
|
: 'Paid and confirmed. Your credits are on the way and appear on My Banners within a few minutes.' + tx, 'ok');
|
|
} catch (e) { VBB.status(String(e && e.message || e).slice(0, 400), 'err'); }
|
|
finally { busy = false; document.querySelectorAll('[data-pk=buy]').forEach(b => { b.disabled = !live; }); }
|
|
};
|
|
});
|
|
})();
|