// Boost page: the live POL price for 1..10 Boosts and the Buy button (one-time, never a subscription). (async function () { VAB.renderNav('/boost'); VAB.renderFooter(); VAB.wire('other').catch(() => {}); const $ = VAB.$; const c = await VAB.getConfig().catch(() => ({})); const b = c.boost || { usd: 5, views: 500, maxQty: 10 }; $('bViews').textContent = VAB.n(b.views); $('bViews2').textContent = VAB.n(b.views); $('bDays').textContent = c.deliverDays || 30; for (let i = 1; i <= (b.maxQty || 10); i++) { const o = document.createElement('option'); o.value = i; o.textContent = i + (i === 1 ? ' Boost' : ' Boosts'); $('bQty').appendChild(o); } const live = !!(c.shop && c.shop.live); const me = await VAB.getJSON('/api/me').catch(() => ({})); const qty = () => Number($('bQty').value) || 1; function who() { if (!live) { $('bWho').textContent = 'Boosts open when the contract goes live. Post your free ad now.'; $('bBuy').disabled = true; return; } $('bBuy').disabled = false; $('bWho').textContent = me.signedIn ? 'Signed in as ' + (me.username ? '@' + me.username : VAB.short(me.address)) + '. Pay from this same wallet.' : 'Sign in on My page first, then pay from the same wallet.'; } async function price() { const n = qty(); $('bUsd').textContent = '$' + (b.usd * n); $('bViews2').textContent = VAB.n(b.views * n); if (!live) { $('bPol').textContent = 'paid in POL at the live price'; return; } const q = await VABBuy.quote(n).catch(() => ({ error: 'x' })); $('bPol').textContent = q.error ? 'price unavailable right now' : 'about ' + VABBuy.fmtPol(q.wei, 2) + ' POL at today\'s price'; } who(); await price(); $('bQty').onchange = price; setInterval(price, 60000); let busy = false; $('bBuy').onclick = async () => { if (busy) return; busy = true; $('bBuy').disabled = true; try { if (!me.signedIn) { location.href = '/my'; return; } const before = ((await VAB.getJSON('/api/my')).boosts || []).length; const r = await VABBuy.run({ qty: qty(), done: async () => (((await VAB.getJSON('/api/my')).boosts || []).length > before) }); VAB.status((r.recorded ? 'Your Boost is live: your ad is starred on the ticker and its views are being delivered. Follow it on My page.' : 'Paid and confirmed. Your Boost shows on My page within a few minutes.') + (r.link ? ' Transaction: ' + r.link : ''), 'ok'); } catch (e) { VAB.status(String(e && e.message || e).slice(0, 400), 'err'); } finally { busy = false; who(); } }; })();