Skip to content

Commit

Permalink
added: initialChains
Browse files Browse the repository at this point in the history
  • Loading branch information
Argeare5 committed Jan 6, 2023
1 parent f342d61 commit d25866e
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions src/utils/chainInfoHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@ interface ExtendedChainInformation extends BasicChainInformation {

export type ChainInformation = BasicChainInformation | ExtendedChainInformation;

export const initialChains: {
[chainId: number]: ChainInformation;
} = {
1: {
urls: ['https://eth.llamarpc.com'],
nativeCurrency: ETH,
name: 'Ethereum',
blockExplorerUrls: ['https://etherscan.io'],
},
137: {
urls: ['https://polygon.llamarpc.com'],
nativeCurrency: MATIC,
name: 'Polygon',
blockExplorerUrls: ['https://polygonscan.com'],
},
43114: {
urls: ['https://rpc.ankr.com/avalanche'],
nativeCurrency: AVAX,
name: 'Avalanche',
blockExplorerUrls: ['https://snowtrace.io'],
},
};

function isExtendedChainInformation(
chainInformation: BasicChainInformation | ExtendedChainInformation
): chainInformation is ExtendedChainInformation {
Expand All @@ -42,18 +65,17 @@ export const initChainInformationConfig = (chains: {
[chainId: number]: BasicChainInformation | ExtendedChainInformation;
}) => {
// init urls from chains config
const urls = Object.keys(chains).reduce<{ [chainId: number]: string[] }>(
(accumulator, chainId) => {
const validURLs: string[] = chains[Number(chainId)].urls;

if (validURLs.length) {
accumulator[Number(chainId)] = validURLs;
}

return accumulator;
},
{}
);
const urls = Object.keys({ ...chains, ...initialChains }).reduce<{
[chainId: number]: string[];
}>((accumulator, chainId) => {
const validURLs: string[] = chains[Number(chainId)].urls;

if (validURLs.length) {
accumulator[Number(chainId)] = validURLs;
}

return accumulator;
}, {});

// init provider instances from chain config
const initalizedProviders: Record<number, StaticJsonRpcBatchProvider> = {};
Expand Down

0 comments on commit d25866e

Please sign in to comment.