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>
103 lines
8.3 KiB
JavaScript
103 lines
8.3 KiB
JavaScript
// My Banners: sign in (network or wallet), credits, post a banner, banner states, share link, cycle rewards.
|
|
(async function () {
|
|
VBB.renderNav('/my'); VBB.renderFooter();
|
|
const $ = VBB.$, esc = VBB.esc;
|
|
const c = await VBB.getConfig().catch(() => ({}));
|
|
const me = await VBB.getJSON('/api/me');
|
|
if (!me.signedIn) {
|
|
// signed in on InstantAdPay already? one quick hop there and back signs you in here too
|
|
try { const ss = await VBB.getJSON('/api/sso/status'); if (ss && ss.check) { location.replace('/sso/start?mode=check&via=iap&to=' + encodeURIComponent('/my')); return; } } catch (e) {}
|
|
$('signin').hidden = false;
|
|
if (!c.sso) { $('ssoIap').hidden = true; $('ssoLs').hidden = true; }
|
|
$('signBtn').onclick = async () => {
|
|
try { VBB.status('Check your wallet for the sign-in message.'); await VBBWallet.signIn(); location.reload(); }
|
|
catch (e) { VBB.status(String(e && e.message || e).slice(0, 300), 'err'); }
|
|
};
|
|
return;
|
|
}
|
|
$('outBtn').onclick = async () => { await VBB.post('/api/auth/logout'); location.reload(); };
|
|
|
|
let uploaded = '';
|
|
function preview(src) { const p = $('preview'); p.innerHTML = src ? '<img alt="Preview" width="125" height="125">' : '125 x 125<br>preview'; if (src) p.querySelector('img').src = src; }
|
|
$('img').addEventListener('input', () => { uploaded = ''; $('fileNote').textContent = ''; const v = $('img').value.trim(); preview(/^https:\/\//.test(v) ? v : ''); });
|
|
$('file').addEventListener('change', async e => {
|
|
const f = e.target.files[0]; if (!f) return;
|
|
if (f.size > 100 * 1024) { VBB.status('That file is ' + Math.ceil(f.size / 1024) + ' KB. The limit is 100 KB.', 'err'); return; }
|
|
$('fileNote').textContent = 'Uploading...';
|
|
const r = await VBB.getJSON('/api/my/upload', { method: 'POST', headers: { 'Content-Type': 'application/octet-stream' }, body: f });
|
|
e.target.value = '';
|
|
if (r.error) { $('fileNote').textContent = ''; VBB.status(r.error, 'err'); return; }
|
|
uploaded = r.img; $('img').value = ''; $('fileNote').textContent = 'Uploaded: ' + f.name; preview(r.img); VBB.status('');
|
|
});
|
|
$('postBtn').onclick = async () => {
|
|
const img = uploaded || $('img').value.trim();
|
|
if (!img) return VBB.status('Add an image address or upload a file.', 'err');
|
|
$('postBtn').disabled = true; VBB.status('Checking your image and link...');
|
|
const r = await VBB.post('/api/my/banners', { img, link: $('link').value.trim() });
|
|
$('postBtn').disabled = false;
|
|
if (r.error) return VBB.status(r.error, 'err');
|
|
uploaded = ''; $('img').value = ''; $('link').value = ''; $('fileNote').textContent = ''; preview('');
|
|
VBB.status(r.banner.state === 'loop' ? 'Posted. Your banner went straight into the loop.' : 'Posted. Your banner is number ' + r.banner.position + ' in line.', 'ok');
|
|
load();
|
|
};
|
|
$('copyBtn').onclick = () => { $('share').select(); try { navigator.clipboard.writeText($('share').value); } catch (e) { document.execCommand('copy'); } VBB.status('Link copied.', 'ok'); };
|
|
|
|
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;
|
|
$('me').textContent = d.username ? '@' + d.username + ' (' + VBB.short(d.address) + ')' : d.address;
|
|
const live = d.banners.filter(b => b.state !== 'cycled').length, cyc = d.banners.filter(b => b.state === 'cycled').length;
|
|
$('stats').innerHTML = [['Post credits', d.credits], ['Banners waiting or in the loop', live], ['Banners cycled', cyc], ['Network ad views earned', VBB.n(d.rewardViews)]]
|
|
.map(x => '<div class="stat"><b>' + esc(x[1]) + '</b><span>' + esc(x[0]) + '</span></div>').join('');
|
|
$('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) $('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 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;
|
|
$('weekStats').innerHTML = [['Verified visitors you sent this week', d.week.visitors], ['Traffic sources this week', d.week.sources]]
|
|
.map(x => '<div class="stat"><b>' + esc(x[1]) + '</b><span>' + esc(x[0]) + '</span></div>').join('');
|
|
$('rewards').innerHTML = d.rewards.length ? '<table class="t"><tr><th>When</th><th>Banner</th><th class="n">Network ad views</th><th>Status</th></tr>'
|
|
+ d.rewards.map(e => '<tr><td>' + esc(new Date(e.at).toLocaleString()) + '</td><td>#' + e.bannerId + '</td><td class="n">' + VBB.n(e.views) + '</td><td>' + (e.status === 'recorded' ? 'Recorded' : esc(e.status)) + '</td></tr>').join('') + '</table>'
|
|
: '<p class="muted">No cycles yet. Your first reward appears when one of your banners rides out of the loop.</p>';
|
|
}
|
|
load(); setInterval(load, 30000);
|
|
})();
|