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
+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]];