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:
+11
-4
@@ -229,11 +229,18 @@
|
||||
try{await upEth.request({method:'wallet_switchEthereumChain',params:[{chainId:UPG.POLYGON}]});}
|
||||
catch(e){if(e&&e.code===4902){await upEth.request({method:'wallet_addEthereumChain',params:[{chainId:UPG.POLYGON,chainName:'Polygon Mainnet',nativeCurrency:{name:'POL',symbol:'POL',decimals:18},rpcUrls:['https://polygon-rpc.com'],blockExplorerUrls:['https://polygonscan.com']}]});}else{throw e;}}
|
||||
}
|
||||
// exact cost from the contract (BigInt)
|
||||
// exact cost from the contract (BigInt). Costs are immutable constants,
|
||||
// so if the WALLET's internal RPC hiccups (MetaMask iOS: "Load failed")
|
||||
// we fall back to the verified baked table instead of failing the flow.
|
||||
upgLog('Reading the exact upgrade cost from the contract…');
|
||||
const r=await upEth.request({method:'eth_call',params:[{to:UPG.CONTRACT,data:UPG.SEL_GETCOSTS},'latest']});
|
||||
const words=[];for(let i=2;i<r.length;i+=64)words.push(BigInt('0x'+r.slice(i,i+64)));
|
||||
const arr=(d.tier===2)?words.slice(24,32):words.slice(16,24);
|
||||
const UP_STD=[310701203558346391552n,621402407116692783104n,1242804814233385566208n,2485609628466771132416n,4971219256933542264832n,9942438513867084529664n,19884877027734169059328n,0n];
|
||||
const UP_PREM=[621402407116692783104n,1242804814233385566208n,2485609628466771132416n,4971219256933542264832n,9942438513867084529664n,19884877027734169059328n,39769754055468338118656n,0n];
|
||||
let arr;
|
||||
try{
|
||||
const r=await upEth.request({method:'eth_call',params:[{to:UPG.CONTRACT,data:UPG.SEL_GETCOSTS},'latest']});
|
||||
const words=[];for(let i=2;i<r.length;i+=64)words.push(BigInt('0x'+r.slice(i,i+64)));
|
||||
arr=(d.tier===2)?words.slice(24,32):words.slice(16,24);
|
||||
}catch(e){ arr=(d.tier===2)?UP_PREM:UP_STD; }
|
||||
const val=arr[(d.level||1)-1];
|
||||
if(!val||val<=0n){upgLog('Could not read the upgrade cost — try again in a minute.',true);return;}
|
||||
upgLog('Upgrading to '+esc(LEVELS[ns.nextLevel-1]||'')+' for '+(Number(val)/1e18).toFixed(4)+' POL — confirm in your wallet…');
|
||||
|
||||
Reference in New Issue
Block a user