add RPC to wallet on unrecognized chains
This commit is contained in:
parent
e483fd537c
commit
42fcae0465
@ -73,15 +73,20 @@ const listenToNetworkChange = (connection: any) => {
|
|||||||
const requestNetworkChange = async (network: NetworkEnum): Promise<boolean> => {
|
const requestNetworkChange = async (network: NetworkEnum): Promise<boolean> => {
|
||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
if (!etherStore.walletAddress) return true;
|
if (!etherStore.walletAddress) return true;
|
||||||
|
const window_ = window as any;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const window_ = window as any;
|
|
||||||
await window_.ethereum.request({
|
await window_.ethereum.request({
|
||||||
method: "wallet_switchEthereumChain",
|
method: "wallet_switchEthereumChain",
|
||||||
params: [{ chainId: Networks[network].chainId }], // chainId must be in hexadecimal numbers
|
params: [{ chainId: Networks[network].chainId }], // chainId must be in hexadecimal numbers
|
||||||
});
|
});
|
||||||
} catch {
|
} catch (e:any){
|
||||||
return false;
|
if (e.code == 4902){ // Unrecognized chain ID
|
||||||
|
await window_.ethereum.request({
|
||||||
|
"method": "wallet_addEthereumChain",
|
||||||
|
"params": [ Networks[network] ],
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user