Dollar value at today's POL price on the member's own pages (Marty, 2026-10-22, Brian's ask; US dollars, not a dollar token): /api/public/polusd serves the contract's own package rate (Chainlink POL/USD) cached 5 min on the server; Overview 'POL earned' shows '≈ $x.xx today', every Earnings line gets '≈ $x.xx', and a note under Earnings gives the rate, when it was updated, and that it is today's value, not the payout-day value. Browser re-reads at most every 2 min; no outside price service. QA member walk 0 bugs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-22 08:21:29 -05:00
parent 1c2928553a
commit 16ec626d2c
3 changed files with 32 additions and 3 deletions
+25
View File
@@ -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) {}
+3 -2
View File
@@ -196,7 +196,7 @@
</div>
<div class="statx c-cyan">
<div class="pl"><svg viewBox="0 0 24 24"><rect x="3" y="6" width="18" height="13" rx="2"/><path d="M3 10h18"/><circle cx="16.5" cy="14.5" r="1.4"/></svg></div>
<div><div class="nv mono" id="dbEarned">0</div><div class="lb">POL earned</div><span class="chip" id="dbEarnedChip" hidden></span></div>
<div><div class="nv mono" id="dbEarned">0</div><div class="lb">POL earned <span class="muted" id="dbEarnedUsd"></span></div><span class="chip" id="dbEarnedChip" hidden></span></div>
</div>
<div class="statx c-violet">
<div class="pl"><svg viewBox="0 0 24 24"><circle cx="12" cy="7" r="3.2"/><circle cx="5" cy="17" r="2.6"/><circle cx="19" cy="17" r="2.6"/><path d="M12 10v3M12 13l-5 2M12 13l5 2"/></svg></div>
@@ -745,6 +745,7 @@
<div class="card">
<h3>Earnings</h3>
<p class="muted small">Every payout the contract has sent to your wallet. Each line links to the transaction.</p>
<p class="muted small" id="earnUsdNote" style="margin-top:-4px"></p>
<div class="feed" id="earnFeed"><div class="row muted">Nothing yet.</div></div>
</div>
<div class="card">
@@ -1187,7 +1188,7 @@
<script src="/assets/wallet.js?v=20260911a"></script>
<script src="/assets/promo.js?v=20261016p"></script>
<script src="/assets/support.js?v=20261016a"></script>
<script src="/assets/my.js?v=20261022gp"></script>
<script src="/assets/my.js?v=20261022usd"></script>
<script src="/assets/chat.js?v=20261016n"></script>
</body>
</html>
+4 -1
View File
@@ -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]];