Skip to content

Commit

Permalink
Add chain to the Metamask if it does not exist (#69)
Browse files Browse the repository at this point in the history
Signed-off-by: OjusWiZard <ojuswimail@gmail.com>
  • Loading branch information
OjusWiZard authored Oct 10, 2023
1 parent 3b5135a commit 56d6df2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/shared/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export const chainInfos: Record<string | number, ChainInfo> = {
id: "xdai",
color: "#48a900",
chainId: 100,
name: "xDAI Chain",
rpcUrls: ["https://gnosischain-rpc.gateway.pokt.network/"],
name: "Gnosis",
rpcUrls: ["https://rpc.gnosischain.com/"],
nativeCurrency: {
name: "xDAI",
symbol: "xDAI",
symbol: "XDAI",
decimals: 18,
},
blockExplorerUrls: ["https://gnosischain.io/"],
blockExplorerUrls: ["https://gnosisscan.io/"],
},
matic: {
id: "matic",
Expand Down Expand Up @@ -96,7 +96,7 @@ export const chainInfos: Record<string | number, ChainInfo> = {
},
};

export const addEthereumChain = (
export const addEthereumChain = async (
chain: string | number,
library?: providers.Web3Provider
) => {
Expand All @@ -108,16 +108,16 @@ export const addEthereumChain = (

// first attempt to switch to that chain
try {
return library.send("wallet_switchEthereumChain", [
return await library.send("wallet_switchEthereumChain", [
{ chainId: utils.hexValue(chainId) },
]);
} catch {}
} catch { }

if (!rpcUrls || rpcUrls.length === 0) {
return null;
}

return library.send("wallet_addEthereumChain", [
return await library.send("wallet_addEthereumChain", [
{
chainId: utils.hexValue(chainId),
chainName: name,
Expand Down

0 comments on commit 56d6df2

Please sign in to comment.