Fix SIWE chain-mismatch: switch wallet to Polygon 137 before sign-in and members-area unlock
This commit is contained in:
+17
-1
@@ -77,6 +77,22 @@
|
||||
}, 220);
|
||||
});
|
||||
},
|
||||
list:function(){ return probeInjected(found.slice()); }
|
||||
list:function(){ return probeInjected(found.slice()); },
|
||||
// Switch the wallet to Polygon (137) so a SIWE sign-in whose message says
|
||||
// "Chain ID: 137" matches the wallet's active chain — otherwise wallets
|
||||
// refuse the signature with a "chain ID does not match" error. Adds Polygon
|
||||
// if the wallet doesn't have it. Returns a Promise.
|
||||
ensureChain:function(eth){
|
||||
var POLY='0x89';
|
||||
return eth.request({method:'eth_chainId'}).then(function(cid){
|
||||
if(cid===POLY) return true;
|
||||
return eth.request({method:'wallet_switchEthereumChain',params:[{chainId:POLY}]}).then(function(){return true;}).catch(function(e){
|
||||
if(e&&e.code===4902){
|
||||
return eth.request({method:'wallet_addEthereumChain',params:[{chainId:POLY,chainName:'Polygon Mainnet',nativeCurrency:{name:'POL',symbol:'POL',decimals:18},rpcUrls:['https://polygon-rpc.com'],blockExplorerUrls:['https://polygonscan.com']}]}).then(function(){return true;});
|
||||
}
|
||||
throw e;
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user