diff --git a/public/assets/wallet-screen.js b/public/assets/wallet-screen.js index e53195a..ee3aaa6 100644 --- a/public/assets/wallet-screen.js +++ b/public/assets/wallet-screen.js @@ -8,15 +8,18 @@ try { [D, ME] = await Promise.all([CR.get('/api/my/dashboard'), CR.me()]); } catch (e) { CR.sub('could not load'); return; } try { POS = await CR.get('/api/my/positions'); } catch (e) {} try { E = await CR.get('/api/my/activity'); } catch (e) {} + // dollar value at today's POL price (Marty, 2026-10-22): one cached rate from our own server, US dollars + let U = { usd: 0, at: 0 }; try { U = await CR.get('/api/public/polusd'); } catch (e) {} + const usd = wei => { if (!(U.usd > 0)) return ''; let p = 0; try { p = Number(BigInt(wei || '0') / 10n ** 12n) / 1e6; } catch (e) {} return '≈ $' + (p * U.usd).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); }; const addr = ME.address || ''; const on = !!ME.memberId; CR.sub(addr ? addr.slice(0, 6) + '…' + addr.slice(-4) + (on ? ' · payouts on' : ' · payouts off') : 'no wallet linked'); - $('tiles').innerHTML = [['Paid to this wallet', pol(D.earnedWei || '0') + ' POL', (D.earnCount || 0) + ' transactions'], ['Credits', fmt((D.credits || 0) + (D.earnedCredits || 0)), fmt(D.credits || 0) + ' purchased · ' + fmt(D.earnedCredits || 0) + ' earned'], ['In campaigns', fmt(D.inCampaigns || 0), 'reserved by live campaigns'], ['Qualifying buyers', fmt(D.buyerCount || 0), (D.buyerCount || 0) >= 5 ? 'level 3 open' : (D.buyerCount || 0) >= 2 ? 'level 2 open' : 'level 2 at 2 buyers']] + $('tiles').innerHTML = [['Paid to this wallet', pol(D.earnedWei || '0') + ' POL', (D.earnCount || 0) + ' transactions' + (U.usd > 0 && D.earnedWei && D.earnedWei !== '0' ? ' · ' + usd(D.earnedWei) + ' today' : '')], ['Credits', fmt((D.credits || 0) + (D.earnedCredits || 0)), fmt(D.credits || 0) + ' purchased · ' + fmt(D.earnedCredits || 0) + ' earned'], ['In campaigns', fmt(D.inCampaigns || 0), 'reserved by live campaigns'], ['Qualifying buyers', fmt(D.buyerCount || 0), (D.buyerCount || 0) >= 5 ? 'level 3 open' : (D.buyerCount || 0) >= 2 ? 'level 2 open' : 'level 2 at 2 buyers']] .map(([k, v, n], i) => '
' + k + '' + v + '' + n + '
').join(''); $('walletBox').innerHTML = addr ? '
' + esc(addr) + '
' + (on ? 'PAYOUTS ON · member #' + ME.memberId + '' : 'WALLET LINKED · PAYOUTS OFF
Switch payouts on so the people you bring pay you from their first purchase.
') + '
' : 'No wallet linked yet.
Link one to be paid. Your email account keeps working either way.
'; const pays = E && Array.isArray(E.earnings) ? E.earnings : []; - $('payRows').innerHTML = pays.length ? pays.slice(0, 25).map(x => '
' + new Date((x.ts || 0) * (x.ts > 1e12 ? 1 : 1000)).toLocaleString() + '' + esc(x.buyerName || x.fromName || (x.names && x.buyerId && x.names[x.buyerId] ? '@' + x.names[x.buyerId] : x.buyerId ? 'member #' + x.buyerId : x.type === 'AwardPaid' ? 'award' : 'member')) + '' + (x.tier ? 'L' + x.tier + ' · ' + (x.tier === 1 ? '50%' : x.tier === 2 ? '20%' : '10%') : (x.type === 'AwardPaid' ? 'award' : '')) + '' + (x.priceCents ? '$' + (x.priceCents / 100) : '') + '+' + pol(x.amountWei || '0') + ' POL' + (x.tx ? '' + esc(String(x.tx).slice(0, 10)) + '…' : '') + '
').join('') + $('payRows').innerHTML = pays.length ? pays.slice(0, 25).map(x => '
' + new Date((x.ts || 0) * (x.ts > 1e12 ? 1 : 1000)).toLocaleString() + '' + esc(x.buyerName || x.fromName || (x.names && x.buyerId && x.names[x.buyerId] ? '@' + x.names[x.buyerId] : x.buyerId ? 'member #' + x.buyerId : x.type === 'AwardPaid' ? 'award' : 'member')) + '' + (x.tier ? 'L' + x.tier + ' · ' + (x.tier === 1 ? '50%' : x.tier === 2 ? '20%' : '10%') : (x.type === 'AwardPaid' ? 'award' : '')) + '' + (x.priceCents ? '$' + (x.priceCents / 100) : '') + '+' + pol(x.amountWei || '0') + ' POL' + (U.usd > 0 ? '
' + usd(x.amountWei) + '' : '') + '
' + (x.tx ? '' + esc(String(x.tx).slice(0, 10)) + '…' : '') + '
').join('') : '
No payouts yet. They appear here the moment someone in your line buys.
'; - $('payFoot').textContent = 'every line is a Polygon transaction · nothing is held by the site'; + $('payFoot').textContent = 'every line is a Polygon transaction · nothing is held by the site' + (U.usd > 0 ? ' · 1 POL ≈ $' + U.usd.toFixed(4) + ' at today’s price (updated ' + Math.max(0, Math.round((Date.now() - U.at) / 60000)) + ' min ago); dollar amounts are today’s value, not the value on the payout day' : ''); const rows = Array.isArray(POS) ? POS : (POS && (POS.positions || POS.list)) || []; $('posRows').innerHTML = rows.length ? rows.map(p => '
' + (p.main ? 'Main position' : 'Position') + ' ' + (p.memberId ? '#' + p.memberId : 'not on chain yet') + '
' + esc(String(p.address || '').slice(0, 10)) + '…
' + fmt(p.avail || 0) + '' + (p.memberId ? 'ACTIVE' : 'PENDING') + '
').join('') : '
' + (addr ? 'Main wallet only. Own another wallet? Add it as a position on Credits and buy from it to self-qualify.' : 'No positions yet.') + '
'; diff --git a/public/wallet.html b/public/wallet.html index 60abf2b..282132e 100644 --- a/public/wallet.html +++ b/public/wallet.html @@ -32,6 +32,6 @@ - + diff --git a/server.js b/server.js index 3f9b061..25ebd49 100644 --- a/server.js +++ b/server.js @@ -150,6 +150,7 @@ const videoTokens = persistedMap('video'); // email -> watch-to-earn video token const faucetHits = new Map(); // address -> last faucet ts (rehearsal test-POL faucet rate limit) const visitTokens = persistedMap('visit'); // email -> verified-visit token (dwell + captcha floor) // walk the referral chain upward via sponsorRef (code/username/member id) +const polUsdC = { at: 0, v: 0 }; // /api/public/polusd cache (2026-10-22) async function uplineSlides(email, depth = 3) { const out = []; let cur = await accounts.byEmail(email); @@ -1174,6 +1175,12 @@ const server = http.createServer(async (req, res) => { { const zm = /^\/api\/zone\/click\/([a-f0-9]{12})$/.exec(p); if (zm && req.method === 'GET') { const target = await zones.click(zm[1]); res.writeHead(302, { Location: target || '/', 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer-when-downgrade' }); return res.end(); } } // -- publisher program (2026-10-10): the public offer for site owners who carry zones, and its live "Network right now" // strip (7-day totals from zones.js, cached a minute). App host only; the link and pages domains stay single-purpose. + // Today's POL price in US dollars for the member pages (Marty, 2026-10-22, same as InstantAdPay): the contract's own package + // rate (Chainlink POL/USD), cached 5 minutes here, so browsers never call an outside price service. + if (p === '/api/public/polusd' && req.method === 'GET') { + if (!(polUsdC.at && Date.now() - polUsdC.at < 300000 && polUsdC.v > 0)) { try { const cat = await chain.catalog(); const pk = (cat.products || cat).find(x => x.costWei); const v = pk ? (pk.priceCents / 100) / (Number(BigInt(pk.costWei)) / 1e18) : 0; if (v > 0) { polUsdC.v = v; polUsdC.at = Date.now(); } } catch (e) {} } + return json(res, 200, { usd: polUsdC.v || 0, at: polUsdC.at || Date.now() }, { 'Cache-Control': 'public, max-age=60' }); + } if (p === '/api/public/publishers' && req.method === 'GET') return json(res, 200, zones.publisherPublic(), { 'Cache-Control': 'public, max-age=60' }); if (p === '/publishers' && (req.method === 'GET' || req.method === 'HEAD') && !isPagesHost(req) && !isLinkHost(req)) return sendFile(res, path.join(PUBLIC_DIR, 'publishers.html')); { const wm = /^\/welcome\/([a-f0-9]{48})$/.exec(p); if (wm && (req.method === 'GET' || req.method === 'POST')) { // one-time tester sign-in link