edaf98c8f6
Watershed look from the approved mockup (hero, topo pattern, icons). Network sign-in through the hub, hub membership, activity ping. Reshare links per member per ad with branch/step tracking; family-tree dashboard (branch, step, reshares, views, clicks, sign-ups, Boosts). Verified views earn ad credits for the branch's resharer (L3). L2 sign-up pipeline (hub-new, confirmed email, not self device/IP, throwaway block, daily cap, fraud score) with keeper-signed reward vouchers and a pending-rewards ledger; payouts OFF (REWARD_PAYOUTS). L1 Boosts through VASShop with signed orders naming the sponsor line and the resharer. Trust pack, chatbot, promo kit, PolHunter embed. All numbers are PROPOSALS until Marty sets them. qa/e2e.mjs 59/59 on a local anvil chain, chatbot test 108/108. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
3.1 KiB
JavaScript
40 lines
3.1 KiB
JavaScript
// One-time Boosts through VASShop. The server builds the signed buy() call for the signed-in member (POST /api/my/order: the hub sponsor line + the resharer whose link they came through)
|
|
// 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 ViralAdSource account. After the transaction confirms the page waits for the watcher to record it.
|
|
window.VASBuy = (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 VAS.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 || VAS.status;
|
|
const c = await VAS.getConfig();
|
|
if (!c.shop || !c.shop.live) throw new Error('Boosts are not open right now.');
|
|
const me = await VAS.getJSON('/api/me');
|
|
if (!me.signedIn) throw new Error('Sign in on My ad tree first, so the Boost lands on your ad.');
|
|
say('Connecting your wallet...');
|
|
const addr = String(await VASWallet.activeAddress(await VASWallet.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 ' + VAS.short(addr) + ', but your ViralAdSource account is ' + VAS.short(me.address) + '. A Boost goes to the wallet that pays, so switch your wallet app to ' + VAS.short(me.address) + ', or sign out and sign in with ' + VAS.short(addr) + '.');
|
|
const od = await VAS.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 VASWallet.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 VASWallet.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 VASWallet.waitTx(hash);
|
|
if (r.status !== '0x1') throw new Error('The transaction did not go through, so nothing was charged except gas. ' + (link ? 'Details: ' + link : ''));
|
|
VAS.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) VAS.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 };
|
|
})();
|