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>
This commit is contained in:
@@ -13,12 +13,50 @@
|
||||
['Shifts today', s.today.shifts], ['Cycles today', s.today.cycles], ['Visitors today', s.today.visits], ['Cycles total', s.totals.cycles], ['Views recorded', VBB.n(s.ledger.views)], ['Views credited', VBB.n(s.ledger.credited)], ['Members', s.members]]
|
||||
.map(x => '<div class="stat"><b>' + esc(x[1]) + '</b><span>' + esc(x[0]) + '</span></div>').join('');
|
||||
$('aRaw').textContent = JSON.stringify(s, null, 2);
|
||||
prizes(); setInterval(prizes, 30000);
|
||||
const l = await get('/api/admin/ledger?n=300');
|
||||
const who = r => r.username ? '@' + r.username : VBB.short(r.address || r.owner);
|
||||
$('aMembers').innerHTML = l.members && l.members.length ? '<table class="t"><tr><th>Member</th><th class="n">Cycles</th><th class="n">Views</th></tr>' + l.members.map(m => '<tr><td>' + esc(who(m)) + '</td><td class="n">' + m.cycles + '</td><td class="n">' + VBB.n(m.views) + '</td></tr>').join('') + '</table>' : '<p class="muted">No cycles yet.</p>';
|
||||
$('aLedger').innerHTML = l.entries && l.entries.length ? '<table class="t"><tr><th>When (CT)</th><th>Entry</th><th>Banner</th><th>Member</th><th class="n">Views</th><th>Status</th></tr>'
|
||||
+ l.entries.map(e => '<tr><td>' + esc(new Date(e.at).toLocaleString('en-US', { timeZone: 'America/Chicago' })) + '</td><td class="mono">' + esc(e.id) + '</td><td>#' + e.bannerId + '</td><td>' + esc(who(e)) + '</td><td class="n">' + VBB.n(e.views) + '</td><td>' + esc(e.status) + '</td></tr>').join('') + '</table>' : '<p class="muted">The ledger is empty.</p>';
|
||||
}
|
||||
// ---- weekly prize payouts: review, then "Approve and pay" (two clicks), once per week ----
|
||||
const pst = { prepared: 'Waiting for approval', nothing: 'No winners', paying: 'Paying', sent: 'Sent, confirming', paid: 'Paid', partial: 'Partly paid: check below', 'claimed-elsewhere': 'Claimed elsewhere: check the wallet' };
|
||||
async function prizes() {
|
||||
const z = await get('/api/admin/prizes'); if (z.error) return;
|
||||
const cur = z.current || {};
|
||||
$('pzNow').innerHTML = '<p class="small">This week (' + esc(z.week) + '): sales $' + VBB.n(cur.salesUsd) + ' in ' + VBB.n(cur.purchases) + ' purchases, 10% = $' + VBB.n(cur.shareUsd) + ', pot $' + VBB.n(cur.potUsd)
|
||||
+ (cur.topUpUsd > 0 ? ' (company top-up $' + VBB.n(cur.topUpUsd) + ')' : '') + (cur.atCap ? ' (at the cap)' : '') + '. Prize key: ' + (z.prize.keyOn ? esc(VBB.short(z.prize.keyAddress)) : 'not set') + '.</p>';
|
||||
const tx = h => z.explorer ? '<a target="_blank" rel="noopener" href="' + esc(z.explorer + '/tx/' + h) + '">' + esc(h.slice(0, 10)) + '...</a>' : esc(h);
|
||||
$('pzWeeks').innerHTML = (z.weeks || []).map(w => {
|
||||
const q = w.quote || {};
|
||||
const lines = w.transfers.map((t, i) => '<tr><td>' + esc(t.board) + '</td><td>' + t.place + '</td><td>' + esc(t.name) + '<br><span class="mono small">' + esc(t.address) + '</span></td><td class="n">' + VBB.n(t.count) + '</td><td class="n">$' + VBB.n(t.usd) + '</td><td class="n">'
|
||||
+ esc(t.pol || (q.lines && q.lines[i] ? q.lines[i].pol : '')) + '</td><td>' + esc(t.status || '') + (t.tx ? ' ' + tx(t.tx) : '') + (t.error ? '<br><span class="small">' + esc(t.error) + '</span>' : '') + '</td></tr>').join('');
|
||||
let foot = '';
|
||||
if (w.status === 'prepared') {
|
||||
foot = q.error ? '<p class="note err">' + esc(q.error) + '</p>'
|
||||
: '<p class="small">POL at $' + Number(q.priceUsd).toFixed(4) + '. Needs ' + esc(q.totalPol) + ' POL + about ' + esc(q.gasPol) + ' POL gas. Prize wallet ' + esc(VBB.short(q.contractPrizeWallet || '')) + ' holds ' + esc(q.balancePol) + ' POL.'
|
||||
+ (BigInt(q.shortWei || 0) > 0n ? ' <b>Short by ' + esc(q.shortPol) + ' POL.</b>' : '') + (q.keyMatches ? '' : ' <b>PRIZE_KEY is missing or is not the prize wallet.</b>') + '</p>'
|
||||
+ '<button class="btn small" data-pay="' + esc(w.week) + '">Approve and pay</button>';
|
||||
}
|
||||
return '<div class="card" style="margin:12px 0"><h3>Week of ' + esc(w.week) + ': ' + esc(pst[w.status] || w.status) + '</h3><p class="small">Sales $' + VBB.n(w.salesUsd) + ', pot $' + VBB.n(w.potUsd) + ', paying $' + VBB.n(w.payUsd)
|
||||
+ (w.unfilledUsd > 0 ? ', $' + VBB.n(w.unfilledUsd) + ' unfilled (stays in the prize wallet)' : '') + (w.payment && w.payment.priceUsd ? ', paid at $' + Number(w.payment.priceUsd).toFixed(4) + '/POL' : '') + '</p>'
|
||||
+ (w.transfers.length ? '<div class="scroll"><table class="t"><tr><th>Board</th><th>#</th><th>Winner</th><th class="n">Count</th><th class="n">USD</th><th class="n">POL</th><th>Status</th></tr>' + lines + '</table></div>' : '<p class="muted">Nobody on the leaderboards that week.</p>') + foot + '</div>';
|
||||
}).join('') || '<p class="muted">No weeks prepared yet.</p>';
|
||||
document.querySelectorAll('[data-pay]').forEach(b => {
|
||||
b.onclick = async () => {
|
||||
const wk = b.dataset.pay;
|
||||
if (!b.dataset.armed) { b.dataset.armed = '1'; b.textContent = 'Click again to send the POL for ' + wk; setTimeout(() => { if (b.isConnected) { delete b.dataset.armed; b.textContent = 'Approve and pay'; } }, 8000); return; }
|
||||
b.disabled = true; b.textContent = 'Sending...';
|
||||
const r = await VBB.getJSON('/api/admin/prizes/pay', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-admin-token': tok }, body: JSON.stringify({ week: wk, confirm: wk }) });
|
||||
VBB.status(r.error || 'Payout sent for the week of ' + wk + '. Receipts confirm below.', r.error ? 'err' : 'ok'); prizes();
|
||||
};
|
||||
});
|
||||
}
|
||||
$('pzPrep').onclick = async () => {
|
||||
const r = await VBB.getJSON('/api/admin/prizes/prepare', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-admin-token': tok }, body: '{}' });
|
||||
VBB.status(r.error || 'Prepared the week of ' + r.week + '.', r.error ? 'err' : 'ok'); prizes();
|
||||
};
|
||||
$('tokBtn').onclick = () => { tok = $('tok').value.trim(); open(); };
|
||||
$('tok').addEventListener('keydown', e => { if (e.key === 'Enter') $('tokBtn').click(); });
|
||||
if (tok) open();
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// One-time purchases through VBBShop (Packages page + My Banners). The server builds the buy() call for the signed-in member
|
||||
// (POST /api/my/order, with a fresh sponsor voucher when the network knows their sponsor); the member's own wallet sends it.
|
||||
// The wallet that pays must be the member's VBB account: credits go to the paying wallet. After the transaction confirms the
|
||||
// page waits for the purchase watcher to credit it (it reads only confirmed blocks).
|
||||
window.VBBBuy = (function () {
|
||||
const fmtPol = (wei, d) => { const s = (BigInt(wei) * 10n ** BigInt(d || 4) / 10n ** 18n).toString().padStart((d || 4) + 1, '0'); return s.slice(0, -(d || 4)) + '.' + s.slice(-(d || 4)); };
|
||||
const short = a => VBB.short(a);
|
||||
async function quote(sku, qty) { return VBB.getJSON('/api/quote?sku=' + sku + '&qty=' + (qty || 1)); }
|
||||
|
||||
// o: { sku, qty, ref, done(check) -> bool (credits arrived?), say(msg, cls) }
|
||||
async function run(o) {
|
||||
const say = o.say || VBB.status;
|
||||
const c = await VBB.getConfig();
|
||||
if (!c.shop || !c.shop.live) throw new Error('Purchases are not open right now.');
|
||||
const me = await VBB.getJSON('/api/me');
|
||||
if (!me.signedIn) throw new Error('Sign in first (My Banners), so the credits land on your account.');
|
||||
say('Connecting your wallet...');
|
||||
const addr = String(await VBBWallet.activeAddress(await VBBWallet.connect()) || '').toLowerCase();
|
||||
if (!addr) throw new Error('No wallet connected. Tap Buy again and pick SafePal or any other crypto wallet.');
|
||||
if (addr !== me.address) {
|
||||
throw new Error('Your wallet is connected as ' + short(addr) + ', but your Viral Banner Blitz account is ' + short(me.address)
|
||||
+ '. Purchases are credited to the wallet that pays, so switch your wallet app to ' + short(me.address)
|
||||
+ ', or sign out and sign in with ' + short(addr) + '.');
|
||||
}
|
||||
const od = await VBB.post('/api/my/order', { sku: o.sku, qty: o.qty || 1, ref: o.ref || 0 });
|
||||
if (od.error) throw new Error(od.error);
|
||||
const value = BigInt(od.value);
|
||||
try {
|
||||
const bal = await VBBWallet.balance(addr);
|
||||
if (bal < value) throw new Error('This wallet holds ' + fmtPol(bal) + ' POL. The purchase needs about ' + fmtPol(value) + ' POL plus a little gas. Add POL on Polygon and try again.');
|
||||
} catch (e) { if (/holds/.test(e.message)) throw e; }
|
||||
say('Confirm the payment in your wallet: about ' + fmtPol(value) + ' POL ($' + od.usd + '). Anything above the exact price comes straight back in the same transaction.');
|
||||
const hash = await VBBWallet.sendTx(od.to, od.data, od.value);
|
||||
const link = c.explorer ? c.explorer + '/tx/' + hash : '';
|
||||
say('Payment sent. Waiting for the Polygon network to confirm it...');
|
||||
const r = await VBBWallet.waitTx(hash);
|
||||
if (r.status !== '0x1') throw new Error('The transaction did not go through, so nothing was charged except gas. ' + (link ? 'Details: ' + link : ''));
|
||||
VBB.post('/api/my/paid', {}).catch(() => {});
|
||||
say('Confirmed on Polygon. Your purchase shows up here within about a minute, once the network has a few more blocks on top of it.', 'ok');
|
||||
// the watcher credits after its confirmations: poll the account
|
||||
for (let i = 0; i < 72; i++) {
|
||||
await new Promise(res => setTimeout(res, 5000));
|
||||
if (i % 4 === 3) VBB.post('/api/my/paid', {}).catch(() => {});
|
||||
try { if (await o.done()) return { hash, link, credited: true }; } catch (e) {}
|
||||
}
|
||||
return { hash, link, credited: false };
|
||||
}
|
||||
return { run, quote, fmtPol };
|
||||
})();
|
||||
@@ -72,10 +72,11 @@ window.VBB = (function () {
|
||||
tick(); setInterval(tick, 25000);
|
||||
}
|
||||
function tile(t, extra) {
|
||||
const a = document.createElement('a'); a.className = 'tile' + (extra && extra.cls ? ' ' + extra.cls : '');
|
||||
const a = document.createElement('a'); a.className = 'tile' + (t.look ? ' look' : '') + (extra && extra.cls ? ' ' + extra.cls : '');
|
||||
a.href = t.href; a.target = '_blank'; a.rel = 'noopener';
|
||||
a.innerHTML = '<img alt="' + esc(t.owner ? 'Banner by ' + t.owner : 'Member banner #' + t.id) + '" width="125" height="125" loading="lazy" referrerpolicy="no-referrer">'
|
||||
+ (extra && extra.pos ? '<span class="pos">' + esc(extra.pos) + '</span>' : '') + (t.owner ? '<span class="who">' + esc(t.owner) + '</span>' : '');
|
||||
if (t.look && t.teaser) { const s = document.createElement('span'); s.className = 'teaser'; s.textContent = t.teaser; a.appendChild(s); a.title = t.teaser; }
|
||||
const img = a.querySelector('img'); img.src = t.img; img.onerror = () => { img.onerror = null; img.src = '/art/tile-fallback.svg'; };
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
(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; displayed only, no payout code yet
|
||||
// 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>';
|
||||
@@ -20,4 +20,16 @@
|
||||
: '<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;
|
||||
}
|
||||
})();
|
||||
|
||||
+29
-2
@@ -45,7 +45,33 @@
|
||||
const where = b => b.state === 'queued' ? '<span class="pill queued">Waiting</span><br>Number ' + b.position + ' of ' + b.of + ' in line'
|
||||
: b.state === 'loop' ? '<span class="pill loop">In the loop</span><br>Place ' + b.place + ' of ' + b.of + ', rides out in about ' + b.shiftsToRideOut + ' shift' + (b.shiftsToRideOut === 1 ? '' : 's')
|
||||
: '<span class="pill cycled">Cycled</span><br>' + (b.cycledAt ? new Date(b.cycledAt).toLocaleString() : '');
|
||||
// banner look (SKU 3): buy it for a banner that is waiting or in the loop; with the look, edit its hover teaser
|
||||
let buying = false, editing = false;
|
||||
function lookRow(row, b) {
|
||||
if (b.look) {
|
||||
row.innerHTML = '<span class="pill look">Banner look</span><input maxlength="40" aria-label="Hover teaser for banner #' + b.id + '"><button class="btn sec small">Save teaser</button>';
|
||||
const inp = row.querySelector('input'); inp.value = b.teaser; inp.placeholder = b.teaserDefault || 'Your teaser line';
|
||||
inp.addEventListener('focus', () => { editing = true; }); inp.addEventListener('blur', () => { editing = false; });
|
||||
row.querySelector('button').onclick = async () => {
|
||||
const r = await VBB.post('/api/my/banners/' + b.id + '/teaser', { teaser: inp.value });
|
||||
editing = false; VBB.status(r.error || 'Teaser saved: "' + r.teaser + '" shows when someone points at your banner.', r.error ? 'err' : 'ok');
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (b.state === 'cycled' || !shopLive) return;
|
||||
row.innerHTML = '<button class="btn amber small">Add the banner look ($' + (c.lookUsd || 2) + ')</button>';
|
||||
row.querySelector('button').onclick = async () => {
|
||||
if (buying) return; buying = true; document.querySelectorAll('.look-row .btn.amber').forEach(x => { x.disabled = true; });
|
||||
try {
|
||||
const r = await VBBBuy.run({ sku: c.lookSku || 3, qty: 1, ref: b.id, done: async () => { const m = await VBB.getJSON('/api/my'); return (m.banners || []).some(x => x.id === b.id && x.look); } });
|
||||
VBB.status(r.credited ? 'Banner #' + b.id + ' now has the look in the loop. Write its teaser line below the banner.' : 'Paid and confirmed. The look appears on banner #' + b.id + ' within a few minutes.', 'ok');
|
||||
} catch (e) { VBB.status(String(e && e.message || e).slice(0, 400), 'err'); }
|
||||
finally { buying = false; load(); }
|
||||
};
|
||||
}
|
||||
const shopLive = !!(c.shop && c.shop.live);
|
||||
async function load() {
|
||||
if (buying || editing) return;
|
||||
const d = await VBB.getJSON('/api/my');
|
||||
if (d.error) return VBB.status(d.error, 'err');
|
||||
$('dash').hidden = false;
|
||||
@@ -56,12 +82,13 @@
|
||||
$('creditNote').textContent = !d.netVerified ? 'Free daily credits are for network members. Sign in through InstantAdPay or LinkSpin, or make a free InstantAdPay account with this wallet, and your free credit arrives each day you sign in. You can have up to ' + d.maxQueued + ' banners waiting at once.' : (d.grantedNow ? 'Your free credit for today was just added. ' : d.freeToday ? 'Today\'s free credit is in. ' : '')
|
||||
+ 'One free credit arrives each day you sign in (they bank up to ' + d.freeCreditCap + '). You can have up to ' + d.maxQueued + ' banners waiting at once.';
|
||||
$('postBtn').disabled = d.credits < 1;
|
||||
if (d.credits < 1) VBB.status('You have used your credits. Come back tomorrow for a free one.');
|
||||
if (d.credits < 1) $('creditNote').textContent += (shopLive ? ' Out of credits: get a pack on the Packages page, or come back tomorrow for a free one.' : '');
|
||||
$('mine').innerHTML = d.banners.length ? '' : '<p class="muted">No banners yet. Post your first one above.</p>';
|
||||
for (const b of d.banners) {
|
||||
const el = document.createElement('div'); el.className = 'item';
|
||||
el.innerHTML = '<img alt="Banner #' + b.id + '" width="72" height="72"><div class="s">' + where(b) + '<br><a target="_blank" rel="noopener"></a><br><span class="muted">' + VBB.n(b.clicks) + ' clicks</span></div>';
|
||||
el.innerHTML = '<img alt="Banner #' + b.id + '" width="72" height="72"><div class="s">' + where(b) + '<br><a target="_blank" rel="noopener"></a><br><span class="muted">' + VBB.n(b.clicks) + ' clicks</span><div class="look-row"></div></div>';
|
||||
el.querySelector('img').src = b.img; const a = el.querySelector('a'); a.href = b.link; a.textContent = b.link.replace(/^https:\/\//, '').slice(0, 60);
|
||||
lookRow(el.querySelector('.look-row'), b);
|
||||
$('mine').appendChild(el);
|
||||
}
|
||||
$('share').value = d.share;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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; }); }
|
||||
};
|
||||
});
|
||||
})();
|
||||
@@ -15,7 +15,7 @@
|
||||
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).join(',');
|
||||
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;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
if (c.perShift) set('perShift', c.perShift);
|
||||
if (c.viewsPerCycle != null) set('views', VBB.n(c.viewsPerCycle));
|
||||
if (c.visitSeconds) set('secs', c.visitSeconds);
|
||||
// planned package prices from config (Marty 2026-11-13); still coming soon, nothing is sold here
|
||||
// package prices from config (the Packages page has its own script, packages.js, with the Buy buttons)
|
||||
const money = v => '$' + (Number.isInteger(v) ? v : Number(v).toFixed(2));
|
||||
const pp = document.getElementById('pkPacks');
|
||||
if (pp && c.packs && c.packs.length) pp.innerHTML = c.packs.map(p => '<li>' + VBB.n(p.credits) + ' post credits for ' + money(p.usd) + '</li>').join('');
|
||||
|
||||
@@ -158,3 +158,17 @@ footer.foot a{color:var(--amber)} footer.foot p{margin:6px 0}
|
||||
/* network zones (2026-11-14): neutral class names, centered, small label */
|
||||
.net-zone{display:flex;flex-direction:column;align-items:center;gap:4px;margin:18px auto;max-width:100%;overflow:hidden}
|
||||
.net-zone-label{font:700 10.5px var(--mono);letter-spacing:.1em;text-transform:uppercase;color:var(--faint)}
|
||||
/* banner look (SKU 3, 2026-11-14): a bright double border + a teaser line on hover (always shown on touch screens) */
|
||||
.tile.look{border:3px solid var(--hot);box-shadow:0 0 0 3px var(--amber),5px 5px 0 3px var(--ink);animation:lookglow 2.4s ease-in-out infinite}
|
||||
@keyframes lookglow{50%{box-shadow:0 0 0 3px var(--sky),5px 5px 0 3px var(--ink)}}
|
||||
.tile.look::after{content:"\2605";position:absolute;right:4px;top:3px;font:700 13px/1 var(--body);color:var(--amber);-webkit-text-stroke:1px var(--ink)}
|
||||
.tile .teaser{position:absolute;left:0;right:0;bottom:0;padding:6px 6px 7px;background:var(--hot);color:#fff;font:700 11px/1.25 var(--body);text-align:center;transform:translateY(100%);transition:transform .18s ease;white-space:normal;overflow:hidden;max-height:60%}
|
||||
.tile.look:hover .teaser,.tile.look:focus-visible .teaser{transform:none}
|
||||
.tile.look:hover .who,.tile.look:focus-visible .who{opacity:0}
|
||||
@media (hover:none){.tile.look .teaser{transform:none;font-size:9.5px;padding:3px 4px}}
|
||||
.pk-usd{margin:2px 0 8px}.pk-usd b{font:800 22px/1.1 var(--disp)}
|
||||
.pk-intro{text-align:center}
|
||||
.mine .item .look-row{display:flex;gap:6px;flex-wrap:wrap;align-items:center;margin-top:6px}
|
||||
.mine .item .look-row input{flex:1;min-width:120px;background:var(--panel);border:2px solid var(--ink);border-radius:8px;padding:6px 8px;font:13px var(--body)}
|
||||
.pill.look{background:var(--hot);color:#fff}
|
||||
.past{display:grid;gap:12px}.past .wk{background:var(--bg2);border:var(--edge);border-radius:14px;padding:12px 14px}
|
||||
|
||||
+36
-2
@@ -1,5 +1,6 @@
|
||||
// Viral Banner Blitz wallet sign-in: Downline Banners' wallet.js (same AppKit build, chain guard, dead-session recovery)
|
||||
// with the buy functions removed. VBB v1 only signs a free sign-in message; it never sends a transaction.
|
||||
// with its buy flow (2026-11-14): sendTx() hard-guards the chain, sets Polygon's fee floor from /api/gas and recovers a dead
|
||||
// WalletConnect session once; waitTx() polls /api/tx; balance() is the pre-flight check. The page builds the call on the server.
|
||||
window.VBBWallet = (function () {
|
||||
const pad = v => BigInt(v).toString(16).padStart(64, '0');
|
||||
const padAddr = a => { if (!a) return pad(0); if (!/^0x[0-9a-fA-F]{40}$/.test(a)) throw new Error('Bad address: ' + a); return a.slice(2).toLowerCase().padStart(64, '0'); };
|
||||
@@ -186,6 +187,39 @@ window.VBBWallet = (function () {
|
||||
return r;
|
||||
}
|
||||
|
||||
async function sendTx(to, data, valueHex) {
|
||||
const c = await VBB.getConfig();
|
||||
const addr = await connect();
|
||||
const wantNum = Number(c.chainId);
|
||||
let cur; try { cur = await eth().request({ method: 'eth_chainId' }); } catch (e) {}
|
||||
if (!isNaN(chainNum(cur)) && chainNum(cur) !== wantNum) {
|
||||
await ensureChain(c);
|
||||
try { cur = await eth().request({ method: 'eth_chainId' }); } catch (e) {}
|
||||
if (!isNaN(chainNum(cur)) && chainNum(cur) !== wantNum)
|
||||
throw new Error('Your wallet is on the wrong network. Switch it to ' + (c.chainName || 'Polygon') + ', then try again.');
|
||||
}
|
||||
const tx = { from: await activeAddress(addr), to, data };
|
||||
if (valueHex) tx.value = valueHex;
|
||||
try { const g = await (await fetch('/api/gas')).json(); if (g && g.maxPriorityFeePerGas && g.maxFeePerGas) { tx.maxPriorityFeePerGas = g.maxPriorityFeePerGas; tx.maxFeePerGas = g.maxFeePerGas; } } catch (e) {}
|
||||
try { return await eth().request({ method: 'eth_sendTransaction', params: [tx] }); }
|
||||
catch (e) {
|
||||
if (!isDead(e)) throw e;
|
||||
tx.from = await freshConnect(c);
|
||||
return eth().request({ method: 'eth_sendTransaction', params: [tx] });
|
||||
}
|
||||
}
|
||||
async function waitTx(hash) {
|
||||
for (let i = 0; i < 120; i++) {
|
||||
try { const r = await (await fetch('/api/tx/' + hash)).json(); if (r.found) return r; } catch (e) { /* app switch on a phone: keep polling */ }
|
||||
await new Promise(res => setTimeout(res, 2500));
|
||||
}
|
||||
throw new Error('Still waiting for the transaction. Check it on the explorer; your credits arrive once it confirms.');
|
||||
}
|
||||
async function balance(addr) {
|
||||
await connect();
|
||||
return BigInt(await eth().request({ method: 'eth_getBalance', params: [addr || currentAddress(), 'latest'] }));
|
||||
}
|
||||
|
||||
async function disconnect() {
|
||||
// AppKit's disconnect can hang on the WalletConnect relay (esp. mobile) —
|
||||
// never block on it, so the UI can't get stuck "disconnecting".
|
||||
@@ -195,5 +229,5 @@ window.VBBWallet = (function () {
|
||||
}
|
||||
|
||||
function walletName() { try { const w = modal && modal.getWalletInfo && modal.getWalletInfo(); return (w && w.name) || ''; } catch (e) { return ''; } }
|
||||
return { connect, signIn, disconnect, address: currentAddress, activeAddress, pickAccount, walletName };
|
||||
return { connect, signIn, sendTx, waitTx, balance, disconnect, address: currentAddress, activeAddress, pickAccount, walletName };
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user