Files
viraladblitz/public/assets/buy.js
T
Marty Bostick 001878bdae ViralAdBlitz v1 (viraladblitz.com rebuild, Marty approved 2026-11-14): the network's text-ad home, local build, not deployed
- Free text ad for network members (InstantAdPay / LinkSpin sign-in or wallet, membership through the hub), one per member
- Member pages viraladblitz.com/<username>: own ad + the first 5 people above in the hub line with a live ad (by place) + 2 Boosted places
- Front page: amber ticker (Boosted starred), Top ads this week by verified clicks, today's numbers, ledger, contract proof
- Verified visitors / views / clicks (ticket + dwell + per-visitor dedupe + per-connection cap + bot filter, owner excluded)
- Boost $5 = 500 guaranteed views through VABShop: keeper-signed EIP-712 line voucher from the hub line, watcher, delivery
  counted per verified view with an audit row each, Network Ad Space text-ad finishing after 30 days (vabnas.js)
- Trust pack: /ledger, /contract, toasts, Telegram card per Boost (once), Terms / Earnings Disclaimer / Privacy (TrustClickz),
  network footer from the hub with tracked links, promo kit (21 creatives) + /promote, LinkSpin zone placeholders, hub report
- Old YFW links via the oldrefs map (admin load route); docstore MySQL documents + row tables
- qa/smoke.mjs 162/162 (stand-in hub, chain, Telegram, NAS; Playwright desktop + phone), qa/chain.mjs 20/20 (real VABShop on anvil)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 13:52:03 -06:00

40 lines
3.1 KiB
JavaScript

// One-time Boosts through VABShop. The server builds the buy() call for the signed-in member (POST /api/my/order, with a fresh
// line voucher when the member's sponsor line is not on the contract yet); the member's own wallet sends it. The wallet that
// pays must be the member's ViralAdBlitz account. After the transaction confirms the page waits for the watcher to record it.
window.VABBuy = (function () {
const fmtPol = (wei, d) => { const k = d || 4; const s = (BigInt(wei) * 10n ** BigInt(k) / 10n ** 18n).toString().padStart(k + 1, '0'); return s.slice(0, -k) + '.' + s.slice(-k); };
async function quote(qty) { return VAB.getJSON('/api/quote?qty=' + (qty || 1)); }
// o: { qty, done() -> bool (the Boost shows on /api/my), say(msg, cls) }
async function run(o) {
const say = o.say || VAB.status;
const c = await VAB.getConfig();
if (!c.shop || !c.shop.live) throw new Error('Boosts are not open right now.');
const me = await VAB.getJSON('/api/me');
if (!me.signedIn) throw new Error('Sign in on My page first, so the Boost lands on your ad.');
say('Connecting your wallet...');
const addr = String(await VABWallet.activeAddress(await VABWallet.connect()) || '').toLowerCase();
if (!addr) throw new Error('No wallet connected. Tap Boost again and pick SafePal or any other crypto wallet.');
if (addr !== me.address) throw new Error('Your wallet is connected as ' + VAB.short(addr) + ', but your ViralAdBlitz account is ' + VAB.short(me.address) + '. A Boost goes to the wallet that pays, so switch your wallet app to ' + VAB.short(me.address) + ', or sign out and sign in with ' + VAB.short(addr) + '.');
const od = await VAB.post('/api/my/order', { qty: o.qty || 1 });
if (od.error) throw new Error(od.error);
const value = BigInt(od.value);
try { const bal = await VABWallet.balance(addr); if (bal < value) throw new Error('This wallet holds ' + fmtPol(bal) + ' POL. The Boost 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 VABWallet.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 VABWallet.waitTx(hash);
if (r.status !== '0x1') throw new Error('The transaction did not go through, so nothing was charged except gas. ' + (link ? 'Details: ' + link : ''));
VAB.post('/api/my/paid', {}).catch(() => {});
say('Confirmed on Polygon. Your Boost shows on My page within about a minute.', 'ok');
for (let i = 0; i < 72; i++) {
await new Promise(res => setTimeout(res, 5000));
if (i % 4 === 3) VAB.post('/api/my/paid', {}).catch(() => {});
try { if (await o.done()) return { hash, link, recorded: true }; } catch (e) {}
}
return { hash, link, recorded: false };
}
return { run, quote, fmtPol };
})();