Wallet-connect resilience: contract costs are immutable constants, so bake verified wei fallbacks for when the wallet's internal RPC fails (MetaMask iOS 'Load failed'); friendlier retry message on network hiccups
join-now.js entry price + my.js upgrade table. Reported by Neville's team overnight 8/28. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+18
-4
@@ -24,10 +24,17 @@ fetch('/api/public/config').then(function(r){return r.json()}).then(function(c){
|
||||
async function req(method,params){ if(!eth) throw new Error('No wallet found'); return await eth.request({method:method,params:params||[]}); }
|
||||
async function ethCall(data){ return await req('eth_call',[{to:CONTRACT,data:data},'latest']); }
|
||||
|
||||
// Immutable contract constant (getAllCosts premium[0], verified on-chain).
|
||||
// Fallback when the WALLET's internal RPC hiccups (MetaMask iOS surfaces
|
||||
// that as "Load failed") — prices can never change, so baking it is safe.
|
||||
var REG_PREM_WEI=343406593406593400832n;
|
||||
async function loadCosts(){
|
||||
var r=await ethCall(SEL_GETCOSTS); var d=r.slice(2), w=[];
|
||||
for(var i=0;i<d.length;i+=64) w.push(BigInt('0x'+d.slice(i,i+64)));
|
||||
costs={ regPrem:w.slice(8,16) }; return costs;
|
||||
try{
|
||||
var r=await ethCall(SEL_GETCOSTS); var d=r.slice(2), w=[];
|
||||
for(var i=0;i<d.length;i+=64) w.push(BigInt('0x'+d.slice(i,i+64)));
|
||||
costs={ regPrem:w.slice(8,16) };
|
||||
}catch(e){ costs={ regPrem:[REG_PREM_WEI] }; }
|
||||
return costs;
|
||||
}
|
||||
function regValue(){ return costs.regPrem[0]*105n/100n; } // premium base * 1.05 (verified)
|
||||
|
||||
@@ -105,7 +112,14 @@ fetch('/api/public/config').then(function(r){return r.json()}).then(function(c){
|
||||
await ensurePolygon();
|
||||
await finishConnect();
|
||||
log('Connected. Review the amount, then Join.','ok');
|
||||
}catch(e){ log('Connect failed: '+(e.message||e),'err'); }
|
||||
}catch(e){
|
||||
var m=String((e&&e.message)||e);
|
||||
if(/load failed|failed to fetch|network|timeout/i.test(m)){
|
||||
log('Your wallet’s network connection hiccuped (this happens inside wallet apps sometimes) — tap <strong>Connect wallet</strong> once more and it usually goes right through.','err');
|
||||
}else{
|
||||
log('Connect failed: '+m,'err');
|
||||
}
|
||||
}
|
||||
}
|
||||
// Inside a wallet's in-app browser the wallet is often ALREADY connected —
|
||||
// recognize it silently on load (eth_accounts never prompts) instead of
|
||||
|
||||
Reference in New Issue
Block a user