Files
viraladblitz/public/assets/my.js
T
martbost d611c4b251 Restyle ViralAdBlitz to the approved "daylight cyberpunk" look (Marty 2026-11-14)
Replaces the dark ink-green/amber newsroom look Marty rejected as too dark.
Look only: routes, ids, copy facts and the trust pack are unchanged.

- vab.css rewritten around CSS variables: #EAF0FF ground, white clipped
  cards, royal #0A1F6B bands/ticker, #0A2FA8 hero panels with network
  lines, red pill CTA, gold Boost/boosted, Barlow Condensed / Chakra Petch /
  Inter / JetBrains Mono. [hidden] now always wins over display rules.
- Front page: slanted hero, ribbon, green-check list, rising bars, three
  YOUR AD screens, gold chips; board tabs (verified clicks / on the wire /
  boosted, from data the page already has); Boost band; ledger chips.
- Member page: own ad as a hero panel, level rows with LEVEL chips, royal
  join bar. Rows are now labelled LEVEL 1 to LEVEL 5 in display order
  (Marty's decision); the real place is kept in the API as depth.
- My page becomes the dashboard: side menu, stat cards, my-ad card with
  LIVE/BOOSTED badges and a folded editor, line bars, Boost ring, recent
  activity, payouts. All figures from /api/my, nothing estimated.
- Boost, ledger, contract, promote, legal and admin pages restyled; 404 too.
- Default JOIN_URL is now https://instantadpay.com/join/{ref} (no ref
  falls back to the InstantAdPay home page).
- New mark, icon, OG image, 21 kit creatives and 3 proof cards
  (royal/daylight/navy) rendered by tools/art.mjs; asset tags bumped to v=4.
- smoke.mjs: new headline, level/depth and join URL checks, UI_FONTS=1.

Tests: qa/smoke.mjs 162/162, qa/chain.mjs 20/20 (local anvil).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:17:30 -06:00

103 lines
12 KiB
JavaScript

// My page (the member dashboard): sign in (network or wallet), post or edit the one free text ad, the member's page link, their
// line, Boost delivery, recent activity and what the contract has paid them. Every figure comes from /api/my; nothing is estimated.
(async function () {
VAB.renderNav('/my'); VAB.renderFooter(); VAB.wire('other').catch(() => {});
const $ = VAB.$, esc = VAB.esc;
const c = await VAB.getConfig().catch(() => ({}));
const me = await VAB.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 VAB.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) { $('viaIap').hidden = true; $('viaLs').hidden = true; }
if (c.joinUrl) $('joinLink').href = c.joinUrl;
$('viaWallet').onclick = async () => {
try { VAB.status('Check your wallet for the sign-in message.'); await VABWallet.signIn(); location.reload(); }
catch (e) { VAB.status(String(e && e.message || e).slice(0, 300), 'err'); }
};
return;
}
$('signout').onclick = async () => { await VAB.post('/api/auth/logout'); location.reload(); };
const counter = (inp, out, max) => { const f = () => { out.textContent = inp.value.length + ' / ' + max; }; inp.addEventListener('input', f); f(); };
const copyText = (t, b) => { const o = b.textContent; try { navigator.clipboard.writeText(t); b.textContent = 'Copied'; setTimeout(() => { b.textContent = o; }, 1400); } catch (e) {} };
const ex = c.explorer || 'https://polygonscan.com';
const vlink = tx => '<a href="' + esc(ex) + '/tx/' + esc(tx) + '" target="_blank" rel="noopener">verify</a>';
const stat = (label, val, note, cls) => '<div class="stat' + (cls ? ' ' + cls : '') + '"><span>' + label + '</span><b>' + val + '</b>' + (note ? '<em>' + note + '</em>' : '') + '</div>';
let counted = false;
async function load() {
const d = await VAB.getJSON('/api/my'); if (d.error) { VAB.status(d.error, 'err'); return; }
$('dash').hidden = false;
const a = d.ad; const lim = c.ad || { headline: 60, line: 90 };
const name = d.username ? '@' + d.username : VAB.short(d.address);
const boosts = d.boosts || [];
const active = boosts.filter(b => b.status === 'delivering');
$('dHello').textContent = 'Welcome back, ' + name;
$('whoVia').textContent = d.netVerified ? 'Signed in through the network' : 'Signed in with your wallet';
$('whoName').textContent = name; $('whoAddr').textContent = VAB.short(d.address);
// stat cards (lifetime figures of the member's own ad, Boost delivery, contract payouts)
const bv = boosts.reduce((s, b) => s + (b.views || 0), 0), bd = boosts.reduce((s, b) => s + Math.min(b.delivered || 0, b.views || 0), 0);
$('stats').innerHTML = stat('Verified views of your ad', VAB.n(a ? a.views : 0), 'real visitors, once a day each')
+ stat('Verified clicks', VAB.n(a ? a.vclicks : 0), 'never your own', 'red')
+ stat('Boost views delivered', VAB.n(bd), boosts.length ? 'of ' + VAB.n(bv) + ' guaranteed' : 'no Boost yet', 'blue')
+ stat('Paid to your wallet', VAB.polOf(d.earned && d.earned.wei) + ' POL', 'straight from the contract', 'dark');
// the page link
$('pageCard').innerHTML = d.page
? '<div class="hd"><h2>Your page</h2></div><p>Share it anywhere. It shows your ad and the five people above you, and everyone who joins through it shows your ad on their page.</p><p class="mono" style="overflow-wrap:anywhere;margin:0"><a id="pageLink" href="' + esc(d.page) + '" target="_blank" rel="noopener">' + esc(d.page) + '</a></p><div class="row" style="margin:0"><button class="btn-line" type="button" id="copyPage">Copy my link</button><a class="btn-soft" href="/promote">Promo kit</a></div>'
: '<div class="hd"><h2>Your page</h2></div><p>Your page address uses your network username. Sign in through InstantAdPay or LinkSpin once and it is set.</p>';
if ($('copyPage')) $('copyPage').onclick = () => copyText(d.page, $('copyPage'));
$('copyTop').hidden = !d.page; $('copyTop').onclick = () => copyText(d.page, $('copyTop'));
// my text ad: badges, preview, the form (folded behind "Edit ad" once the ad exists)
$('adBadges').innerHTML = a ? (a.status === 'live' ? '<span class="chip live">LIVE</span>' : '<span class="chip idle">' + esc(a.status.toUpperCase()) + '</span>') + (active.length ? ' <span class="chip gold">★ BOOSTED</span>' : '') : '';
$('adPrev').innerHTML = a ? '<div class="adprev' + (active.length ? ' star' : '') + '">' + (active.length ? '<span class="tag">★ BOOSTED</span>' : '') + '<b>' + esc(a.headline) + '</b><span>' + esc(a.line1) + '</span>' + (a.line2 ? '<span>' + esc(a.line2) + '</span>' : '') + '<a href="' + esc(a.link) + '" target="_blank" rel="noopener nofollow">' + esc(a.link.replace(/^https?:\/\//, '').slice(0, 60)) + '</a></div>'
+ '<div class="row" style="margin-top:14px"><button type="button" class="btn-line" id="editAd">Edit ad</button>' + (d.page ? '<a class="btn-soft" href="' + esc(d.page) + '" target="_blank" rel="noopener">Preview my page</a>' : '') + '</div>' : '';
if (!d.netVerified) {
$('adNote').innerHTML = 'Text ads are free for network members. This wallet is not in the network yet: <a href="' + esc(d.joinUrl) + '" target="_blank" rel="noopener">join InstantAdPay free</a>, link this wallet there, then sign in here through InstantAdPay.';
$('adForm').hidden = true; if ($('editAd')) $('editAd').hidden = true;
} else {
$('adForm').hidden = !!a; $('adNote').hidden = !!a;
if ($('editAd')) $('editAd').onclick = () => { const h = !$('adForm').hidden; $('adForm').hidden = h; $('adNote').hidden = h; $('editAd').textContent = h ? 'Edit ad' : 'Close the editor'; if (!h) $('fHead').focus(); };
if (a) { $('adHead').textContent = 'My text ad'; $('fHead').value = a.headline; $('fL1').value = a.line1; $('fL2').value = a.line2 || ''; $('fLink').value = a.link; $('adSave').textContent = 'Save changes'; }
if (!counted) { counter($('fHead'), $('cHead'), lim.headline); counter($('fL1'), $('cL1'), lim.line); counter($('fL2'), $('cL2'), lim.line); counted = true; }
else ['fHead', 'fL1', 'fL2'].forEach(id => $(id).dispatchEvent(new Event('input')));
}
// the line: the people above, nearest first (their ads show on this member's page)
$('line').innerHTML = (d.line || []).length ? '<p class="small" style="margin:0 0 14px">The people above you in the network, nearest first. Your page shows the first five who have an ad here, and your ad shows on the page of everyone you bring in.</p><div class="lbars">'
+ d.line.map(x => '<div class="lbar' + (x.hasAd ? ' has' : '') + '"><span class="k">PLACE ' + x.depth + '</span><span class="who2"><b>' + (x.username ? '@' + esc(x.username) : 'a member') + '</b><span class="bar"><i style="width:' + (x.hasAd ? 100 : 0) + '%"></i></span></span><span class="pill' + (x.hasAd ? ' on' : '') + '">' + (x.hasAd ? 'ad live' : 'no ad yet') + '</span></div>').join('') + '</div>'
: '<p class="small">' + (d.lineOk === false ? 'The network line could not be read just now. Try again in a minute.' : 'No sponsor line is known for you in the network yet.') + '</p>';
// Boosts: the ring for the Boost being delivered now, then every Boost with its delivery
const ring = b => { const pct = Math.min(100, Math.round((b.delivered || 0) / b.views * 100)); return '<div class="ring"><svg width="96" height="96" viewBox="0 0 36 36" role="img" aria-label="' + VAB.n(b.delivered) + ' of ' + VAB.n(b.views) + ' views delivered"><circle cx="18" cy="18" r="15.9" fill="none" stroke="#23409F" stroke-width="3.5"/><circle cx="18" cy="18" r="15.9" fill="none" stroke="#3D8BFF" stroke-width="3.5" stroke-dasharray="' + pct + ' 100" pathLength="100" transform="rotate(-90 18 18)"/></svg><div><b>' + VAB.n(b.delivered) + ' / ' + VAB.n(b.views) + '</b><span>views delivered on your active Boost</span></div></div>'; };
$('boosts').innerHTML = (boosts.length ? (active.length ? ring(active[active.length - 1]) : '')
+ '<div class="bl">' + boosts.map(b => '<div style="flex-direction:column;align-items:stretch"><div style="display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap"><span>' + VAB.when(b.at) + ' · ' + VAB.n(b.views) + ' guaranteed views</span><span class="pill' + (b.status === 'delivered' ? ' done' : ' on') + '">' + esc(b.status.replace(/-/g, ' ')) + '</span></div>'
+ '<div class="meter"><i style="width:' + Math.min(100, Math.round(b.delivered / b.views * 100)) + '%"></i></div><span>' + VAB.n(b.delivered) + ' of ' + VAB.n(b.views) + ' delivered' + (b.nas ? ' (' + VAB.n(b.nas) + ' through Network Ad Space)' : '') + (b.dueAt && b.status === 'delivering' ? ' · on-site until ' + VAB.when(b.dueAt) : '') + '</span></div>').join('') + '</div>'
+ '<p class="small">Anything not delivered on ViralAdBlitz in ' + (c.deliverDays || 30) + ' days is finished through Network Ad Space.</p>'
: '<h2>No Boost yet</h2><p class="small">A Boost is $' + (c.boost ? c.boost.usd : 5) + ' once and buys ' + VAB.n(c.boost ? c.boost.views : 500) + ' guaranteed network views for your ad, plus a starred spot on the ticker.</p>');
$('boostMore').textContent = boosts.length ? 'Add another Boost, $' + (c.boost ? c.boost.usd : 5) : 'Boost my ad, $' + (c.boost ? c.boost.usd : 5);
// recent activity: real events only (payouts to this wallet, this member's Boosts, the ad going live)
const ev = [];
for (const x of (d.earned && d.earned.items) || []) ev.push({ at: x.at, cls: 'red', h: 'Level ' + x.level + ' paid you ' + VAB.polOf(x.wei) + ' POL', s: (x.buyerName ? '@' + esc(x.buyerName) : 'Someone in your team') + ' bought a Boost' + (x.failed ? ' (waiting in the contract for you to claim)' : '') + ' · ' + vlink(x.tx) });
for (const b of boosts) ev.push({ at: b.at, cls: 'gold', h: 'You bought a Boost', s: VAB.n(b.views) + ' guaranteed views · ' + esc(b.status.replace(/-/g, ' ')) });
if (a && a.createdAt) ev.push({ at: a.createdAt, cls: '', h: 'Your text ad went live', s: 'On your page and your team\'s pages' });
ev.sort((x, y) => (y.at || 0) - (x.at || 0));
$('acts').innerHTML = ev.length ? ev.slice(0, 6).map(e => '<div class="act ' + e.cls + '"><i></i><div><b>' + e.h + '</b><span>' + VAB.when(e.at) + ' · ' + e.s + '</span></div></div>').join('') : '<p class="small">Nothing yet. Post your free text ad to get started.</p>';
// what the contract paid
$('earned').innerHTML = (d.earned && d.earned.items.length) ? d.earned.items.map(x => '<div class="lrow"><span class="small muted">' + VAB.when(x.at) + '</span><span style="flex:1;min-width:140px">Level ' + x.level + ' share from ' + (x.buyerName ? '@' + esc(x.buyerName) : 'a Boost') + (x.failed ? ' (waiting in the contract for you to claim)' : '') + '</span><b class="mono">' + VAB.polOf(x.wei) + ' POL</b><span class="small">' + vlink(x.tx) + '</span></div>').join('')
: '<p class="small">Nothing yet. The contract pays a level share in the same transaction when someone in your team buys a Boost, if you have bought one yourself. Advertising, not income. Nothing is promised.</p>';
}
$('adForm').addEventListener('submit', async e => {
e.preventDefault(); $('adSave').disabled = true; VAB.status('Checking your link...');
const r = await VAB.post('/api/my/ad', { headline: $('fHead').value, line1: $('fL1').value, line2: $('fL2').value, link: $('fLink').value });
$('adSave').disabled = false;
if (r.error) return VAB.status(r.error, 'err');
VAB.status(r.created ? 'Posted. Your ad is live on your page and on your team\'s pages.' : 'Saved. Your ad shows the new text everywhere.', 'ok');
load();
});
await load();
})();