Fix stale dashboard right after own tx: fresh=1 cache bypass (one-shot via sessionStorage flag) set on upgrade success and post-join redirect
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -147,6 +147,7 @@
|
||||
$('resultLink').href='/my/'+newId; $('resultLink').style.display='inline-flex';
|
||||
log('🎉 Confirmed — your position is <strong>#'+newId+'</strong>. Redirecting to your dashboard…','ok');
|
||||
try{ el_scroll('result'); }catch(e){}
|
||||
try{sessionStorage.setItem('rmc.fresh','1');}catch(e){}
|
||||
setTimeout(function(){ location.href='/my/'+newId; }, 4500);
|
||||
} else {
|
||||
log('Confirmed on-chain. Open your dashboard at <a href="/my">/my</a> and enter your new ID (also shown on Polygonscan).','ok');
|
||||
|
||||
+5
-2
@@ -221,7 +221,7 @@
|
||||
for(let i=0;i<60;i++){
|
||||
try{const rc=await upEth.request({method:'eth_getTransactionReceipt',params:[tx]});
|
||||
if(rc){if(rc.status==='0x0'){upgLog('⚠️ The upgrade reverted — your POL was returned (minus gas). Wait a moment and try again.',true);return;}
|
||||
upgLog('🎉 <strong>Upgraded!</strong> Refreshing your dashboard…');setTimeout(function(){location.reload();},2500);return;}
|
||||
upgLog('🎉 <strong>Upgraded!</strong> Refreshing your dashboard…');try{sessionStorage.setItem('rmc.fresh','1');}catch(e){}setTimeout(function(){location.reload();},3000);return;}
|
||||
}catch(e){}
|
||||
await new Promise(function(s){setTimeout(s,3000);});
|
||||
}
|
||||
@@ -481,7 +481,10 @@
|
||||
}
|
||||
async function load(id){
|
||||
try{
|
||||
const r=await fetch('/api/public/member?id='+id);
|
||||
// after our own join/upgrade tx, force one cache-bypassing read so the
|
||||
// dashboard reflects the transaction immediately instead of the cache
|
||||
let fresh='';try{if(sessionStorage.getItem('rmc.fresh')){fresh='&fresh=1&_t='+Date.now();sessionStorage.removeItem('rmc.fresh');}}catch(e){}
|
||||
const r=await fetch('/api/public/member?id='+id+fresh);
|
||||
const d=await r.json();
|
||||
if(!r.ok)throw new Error(d.error||'Lookup failed');
|
||||
if(!d.registered)throw new Error(`ID ${id} isn't registered on the smart contract — double-check the number.`);
|
||||
|
||||
@@ -384,10 +384,13 @@ async function handleApi(req,res,pathname){
|
||||
if(req.method==='GET'&&pathname==='/api/public/member'){
|
||||
const ip=String(req.headers['x-forwarded-for']||req.socket.remoteAddress||'').split(',')[0].trim();
|
||||
if(memberLookupLimited(ip))return json(res,429,{error:'Too many lookups — give it a minute.'});
|
||||
const id=Number(new URL(req.url,'http://x').searchParams.get('id')||0);
|
||||
const q0=new URL(req.url,'http://x').searchParams;
|
||||
const id=Number(q0.get('id')||0);
|
||||
if(!Number.isInteger(id)||id<1||id>281474976710655)return json(res,400,{error:'Enter a numeric member ID.'});
|
||||
const cached=memberCache.get(id);
|
||||
if(cached&&Date.now()-cached.ts<120000)return json(res,200,cached.data,{'Cache-Control':'public, max-age=15'});
|
||||
// fresh=1: the caller just completed their own transaction — bypass the
|
||||
// cache once so the dashboard reflects it immediately
|
||||
if(q0.get('fresh')!=='1'&&cached&&Date.now()-cached.ts<120000)return json(res,200,cached.data,{'Cache-Control':'public, max-age=15'});
|
||||
try{
|
||||
const r=await Promise.race([chain.memberPublic(id),new Promise((_,rej)=>setTimeout(()=>rej(new Error('Blockchain lookup timed out — try again.')),20000))]);
|
||||
if(r.registered)r.referralUrl=`${getConfig().dappReferralBaseUrl}${encodeURIComponent(id)}`;
|
||||
|
||||
Reference in New Issue
Block a user