From d25866ea8336585bac0c37487299b357c73dba0e Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 6 Jan 2023 11:39:17 +0200 Subject: [PATCH] added: initialChains --- src/utils/chainInfoHelpers.ts | 46 ++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/utils/chainInfoHelpers.ts b/src/utils/chainInfoHelpers.ts index c2043d1..6ecbcc6 100644 --- a/src/utils/chainInfoHelpers.ts +++ b/src/utils/chainInfoHelpers.ts @@ -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 { @@ -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 = {};