3e0dee517d
weekend.js: the date gate (WEEKEND_NOW test clock), FREE_CREDITS_PER_DAY stays 1. chainskus.js: skus() read every 60 s, so the $10 pack shows what the contract credits (50 once the owner signs setSku, 40 before or after). netdeals.js + /assets/netweekend.js: /api/network-deals and the ribbon; the VBB line is built from live values and drops itself if there is nothing true to say. chatcore render hook, chatbot FACTS/CANNED from live values with a dated weekend fact. qa/weekend.test.mjs 33 pass, chatbot 182, smoke 268. common.js?v=10, my.js?v=6, packages.js?v=2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
3.5 KiB
JavaScript
52 lines
3.5 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';
|
|
// Network Weekend (2026-11-17): the free daily credits as the server grants them today
|
|
if (c.freeCreditsPerDay > 1 && $('pkFree')) $('pkFree').textContent = 'Network Weekend: every network member (InstantAdPay or LinkSpin) gets ' + c.freeCreditsPerDay + ' free post credits each day they sign in, through Monday 11-30, midnight Central.';
|
|
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; }); }
|
|
};
|
|
});
|
|
})();
|