Skip to content

Commit

Permalink
Filter out chains without RPCs (#93)
Browse files Browse the repository at this point in the history
* Filter out chains without RPCs

* Fix issue with empty explorer array
  • Loading branch information
FrederikBolding authored Sep 2, 2023
1 parent 088bc36 commit 7ceadd1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
38 changes: 19 additions & 19 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const path = require("path");
const webpack = require("webpack");
const { createRemoteFileNode } = require("gatsby-source-filesystem");
const fetch = require("node-fetch");

Expand Down Expand Up @@ -42,21 +40,23 @@ exports.sourceNodes = async ({
return acc;
}, Promise.resolve({}));

chains.forEach((chain) => {
const icon = chain.icon;
const iconCid = iconFiles[icon]?.name;
const node = {
...chain,
icon: iconCid,
parent: null,
children: [],
id: createNodeId(`chain__${chain.chainId}`),
internal: {
type: "Chain",
content: JSON.stringify(chain),
contentDigest: createContentDigest(chain),
},
};
createNode(node);
});
chains
.filter((chain) => chain.rpc.length > 0)
.forEach((chain) => {
const icon = chain.icon;
const iconCid = iconFiles[icon]?.name;
const node = {
...chain,
icon: iconCid,
parent: null,
children: [],
id: createNodeId(`chain__${chain.chainId}`),
internal: {
type: "Chain",
content: JSON.stringify(chain),
contentDigest: createContentDigest(chain),
},
};
createNode(node);
});
};
7 changes: 5 additions & 2 deletions src/context/Web3Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ export const Web3Provider = ({ children }) => {
if (!provider) {
return;
}
const { nativeCurrency, explorers } = chain;
const blockExplorerUrls =
explorers && explorers.length > 0 ? explorers.map((e) => e.url) : null;
provider.send("wallet_addEthereumChain", [
{
chainId: `0x${chain.chainId.toString(16)}`,
chainName: chain.name,
nativeCurrency: chain.nativeCurrency,
nativeCurrency,
rpcUrls: chain.rpc,
blockExplorerUrls: chain.explorers?.map((e) => e.url),
blockExplorerUrls,
},
]);
};
Expand Down

0 comments on commit 7ceadd1

Please sign in to comment.