From 16ec626d2cc635f3b4ec2ccc089392e91d337252 Mon Sep 17 00:00:00 2001 From: martbost Date: Thu, 22 Oct 2026 08:21:29 -0500 Subject: [PATCH] =?UTF-8?q?Dollar=20value=20at=20today's=20POL=20price=20o?= =?UTF-8?q?n=20the=20member's=20own=20pages=20(Marty,=202026-10-22,=20Bria?= =?UTF-8?q?n's=20ask;=20US=20dollars,=20not=20a=20dollar=20token):=20/api/?= =?UTF-8?q?public/polusd=20serves=20the=20contract's=20own=20package=20rat?= =?UTF-8?q?e=20(Chainlink=20POL/USD)=20cached=205=20min=20on=20the=20serve?= =?UTF-8?q?r;=20Overview=20'POL=20earned'=20shows=20'=E2=89=88=20$x.xx=20t?= =?UTF-8?q?oday',=20every=20Earnings=20line=20gets=20'=E2=89=88=20$x.xx',?= =?UTF-8?q?=20and=20a=20note=20under=20Earnings=20gives=20the=20rate,=20wh?= =?UTF-8?q?en=20it=20was=20updated,=20and=20that=20it=20is=20today's=20val?= =?UTF-8?q?ue,=20not=20the=20payout-day=20value.=20Browser=20re-reads=20at?= =?UTF-8?q?=20most=20every=202=20min;=20no=20outside=20price=20service.=20?= =?UTF-8?q?QA=20member=20walk=200=20bugs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- public/assets/my.js | 25 +++++++++++++++++++++++++ public/my.html | 5 +++-- server.js | 5 ++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/public/assets/my.js b/public/assets/my.js index 25d0989..0e2391b 100644 --- a/public/assets/my.js +++ b/public/assets/my.js @@ -686,6 +686,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str $('dbCredits').textContent = ((d.credits || 0) + earnedAv).toLocaleString(); $('dbCreditsSub').textContent = (d.credits || 0).toLocaleString() + ' purchased' + (d.creditedCredits ? ' (' + d.creditedCredits.toLocaleString() + ' credited to you)' : '') + ' · ' + earnedAv.toLocaleString() + ' earned' + (inCamp ? ' · ' + inCamp.toLocaleString() + ' in campaigns' : ''); $('dbEarned').textContent = IAP.fmtPol(d.earnedWei || '0'); + usdRate().then(r => { const el = $('dbEarnedUsd'); if (el) el.textContent = r.usd > 0 && d.earnedWei && d.earnedWei !== '0' ? usdOf(d.earnedWei, r) + ' today' : ''; }); $('dbBuyers').textContent = d.buyerCount || 0; if (d.buyerCountPositions) { const sub = $('dbBuyersSub'); if (sub) sub.textContent = '+' + d.buyerCountPositions + ' on your linked positions (count toward badges; levels pay on your main position)'; } $('dbTeam').textContent = (d.referrals || []).length; // trend chips: only real, computable facts @@ -939,6 +940,24 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str } } + // Dollar value at today's POL price (Marty, 2026-10-22): one cached rate from our own server (5 min there, 2 min here), + // shown as "≈ $x.xx" next to POL amounts on the member's own pages. It is today's value, not the value on the payout day. + let USD = null; + async function usdRate() { + if (USD && Date.now() - USD.got < 120000) return USD; + try { const r = await (await fetch('/api/public/polusd')).json(); USD = { usd: Number(r.usd) || 0, at: Number(r.at) || Date.now(), got: Date.now() }; } catch (e) { USD = USD || { usd: 0, at: 0, got: Date.now() }; } + return USD; + } + function usdOf(wei, r) { + let pol = 0; try { pol = Number(BigInt(wei || '0') / 10n ** 12n) / 1e6; } catch (e) {} + const v = pol * ((r && r.usd) || 0); + return '≈ $' + v.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + } + function usdNote(r) { + if (!r || !(r.usd > 0)) return ''; + const mins = Math.max(0, Math.round((Date.now() - r.at) / 60000)); + return '1 POL ≈ $' + r.usd.toLocaleString('en-US', { minimumFractionDigits: 4, maximumFractionDigits: 4 }) + ' at today’s price (updated ' + (mins < 1 ? 'just now' : mins + ' min ago') + '). Dollar amounts are what the POL is worth today, not on the day it was paid.'; + } async function loadActivity() { try { const c = await IAP.getConfig(); @@ -950,6 +969,12 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str for (const ev of evs) el.appendChild(IAP.feedRow(ev, c)); }; fill('earnFeed', a.earnings, 'No payouts yet. They appear here the moment one lands.'); + usdRate().then(r => { + const note = $('earnUsdNote'); if (note) note.textContent = usdNote(r); + if (!(r.usd > 0)) return; + const rows = $('earnFeed').querySelectorAll('.row'); let i = 0; + for (const ev of (a.earnings || [])) { const row = rows[i++]; if (!row || !ev.amountWei) continue; const s = document.createElement('span'); s.className = 'usd muted small'; s.textContent = usdOf(ev.amountWei, r); const tx = row.querySelector('.tx'); row.insertBefore(s, tx || null); } + }); fill('refFeed', a.referrals, 'No referral activity yet. Share your invite link.'); fill('buyFeed', a.purchases, 'No purchases from your wallet yet.'); } catch (e) {} diff --git a/public/my.html b/public/my.html index c242e3e..358b341 100644 --- a/public/my.html +++ b/public/my.html @@ -196,7 +196,7 @@
-
0
POL earned
+
0
POL earned
@@ -745,6 +745,7 @@

Earnings

Every payout the contract has sent to your wallet. Each line links to the transaction.

+

Nothing yet.
@@ -1187,7 +1188,7 @@ - + diff --git a/server.js b/server.js index a5773a2..2fb10d7 100644 --- a/server.js +++ b/server.js @@ -685,7 +685,7 @@ const gpDevNow = devDay => (!IS_PROD && /^\d{4}-\d{2}-\d{2}$/.test(String(devDay const polUsdCache = { at: 0, v: 0 }; async function polUsdLive() { if (!IS_PROD && Number(process.env.DEV_POL_USD) > 0) return Number(process.env.DEV_POL_USD); // local tests: no RPC - if (polUsdCache.at && Date.now() - polUsdCache.at < 600000 && polUsdCache.v > 0) return polUsdCache.v; + if (polUsdCache.at && Date.now() - polUsdCache.at < 300000 && polUsdCache.v > 0) return polUsdCache.v; // 5 min: what members see as today's dollar value const cat = await chain.catalog(); const pk = cat.find(x => x.costWei); if (!pk) return polUsdCache.v || 0; const v = (pk.priceCents / 100) / (Number(BigInt(pk.costWei)) / 1e18); if (v > 0) { polUsdCache.v = v; polUsdCache.at = Date.now(); } return v; } @@ -3840,6 +3840,9 @@ const server = http.createServer(async (req, res) => { } return json(res, 200, { games: out }, { 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'public, max-age=300' }); } + // Today's POL price in US dollars for the member pages (Marty, 2026-10-22, Brian's ask): the same rate the contract prices + // packages with (its Chainlink POL/USD feed), cached 5 minutes on the server, so browsers never call a price service. + if (p === '/api/public/polusd' && req.method === 'GET') { let usd = 0; try { usd = await polUsdLive(); } catch (e) {} return json(res, 200, { usd, at: polUsdCache.at || Date.now() }, { 'Cache-Control': 'public, max-age=60' }); } if (p === '/api/public/games' && req.method === 'GET') return json(res, 200, { games: stripGames() }, { 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'public, max-age=300' }); { const mg = /^\/g\/([a-z]{3,20})$/.exec(p); if (mg && req.method === 'GET') { const g = GAMES().find(x => x.slug === mg[1]); const S = STRIP()[mg[1]];