Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chain to the Metamask if it does not exist #69

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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