From f583f1e08e760feb95bc2a778a278a2f4a205681 Mon Sep 17 00:00:00 2001 From: Anon dev Date: Fri, 8 Sep 2023 15:53:00 -0400 Subject: [PATCH] fix: rpc fields getting overridden in Object.assign --- wormhole-connect/src/config/devnet/rpcs.ts | 19 +++++--- wormhole-connect/src/config/index.ts | 4 +- wormhole-connect/src/config/mainnet/rpcs.ts | 49 ++++++++++++++------- wormhole-connect/src/config/testnet/rpcs.ts | 49 ++++++++++++++------- wormhole-connect/src/config/utils.ts | 8 ++++ 5 files changed, 92 insertions(+), 37 deletions(-) diff --git a/wormhole-connect/src/config/devnet/rpcs.ts b/wormhole-connect/src/config/devnet/rpcs.ts index 43a8a13a2..0c252a9ca 100644 --- a/wormhole-connect/src/config/devnet/rpcs.ts +++ b/wormhole-connect/src/config/devnet/rpcs.ts @@ -1,10 +1,19 @@ +import { populateRpcField } from 'config/utils'; +const { + REACT_APP_ETHEREUM_DEVNET_RPC, + REACT_APP_OSMOSIS_DEVNET_RPC, + REACT_APP_WORMCHAIN_DEVNET_RPC, + REACT_APP_TERRA2_DEVNET_RPC, + REACT_APP_SEI_REST, +} = process.env; + export const DEVNET_RPC_MAPPING = { - ethereum: process.env.REACT_APP_ETHEREUM_DEVNET_RPC, - osmosis: process.env.REACT_APP_OSMOSIS_DEVNET_RPC, - wormchain: process.env.REACT_APP_WORMCHAIN_DEVNET_RPC, - terra2: process.env.REACT_APP_TERRA2_DEVNET_RPC, + ...populateRpcField('ethereum', REACT_APP_ETHEREUM_DEVNET_RPC), + ...populateRpcField('osmosis', REACT_APP_OSMOSIS_DEVNET_RPC), + ...populateRpcField('wormchain', REACT_APP_WORMCHAIN_DEVNET_RPC), + ...populateRpcField('terra2', REACT_APP_TERRA2_DEVNET_RPC), }; export const DEVNET_REST_MAPPING = { - sei: process.env.REACT_APP_SEI_REST, + ...populateRpcField('sei', REACT_APP_SEI_REST), }; diff --git a/wormhole-connect/src/config/index.ts b/wormhole-connect/src/config/index.ts index 91ab6397f..d4d29d95b 100644 --- a/wormhole-connect/src/config/index.ts +++ b/wormhole-connect/src/config/index.ts @@ -81,8 +81,8 @@ export const ROUTES = export const RPCS = config && config.rpcs - ? Object.assign({}, NETWORK_DATA.rpcs, config.rpcs) - : NETWORK_DATA.rpcs; + ? Object.assign({}, sdkConfig.rpcs, NETWORK_DATA.rpcs, config.rpcs) + : Object.assign({}, sdkConfig.rpcs, NETWORK_DATA.rpcs); export const REST = config && config.rest diff --git a/wormhole-connect/src/config/mainnet/rpcs.ts b/wormhole-connect/src/config/mainnet/rpcs.ts index f59ac2748..dd3401f61 100644 --- a/wormhole-connect/src/config/mainnet/rpcs.ts +++ b/wormhole-connect/src/config/mainnet/rpcs.ts @@ -1,20 +1,39 @@ +import { populateRpcField } from 'config/utils'; +const { + REACT_APP_ETHEREUM_RPC, + REACT_APP_SOLANA_RPC, + REACT_APP_POLYGON_RPC, + REACT_APP_BSC_RPC, + REACT_APP_AVALANCHE_RPC, + REACT_APP_FANTOM_RPC, + REACT_APP_CELO_RPC, + REACT_APP_MOONBEAM_RPC, + REACT_APP_SUI_RPC, + REACT_APP_APTOS_RPC, + REACT_APP_SEI_RPC, + REACT_APP_BASE_RPC, + REACT_APP_OSMOSIS_RPC, + REACT_APP_WORMCHAIN_RPC, + REACT_APP_SEI_REST, +} = process.env; + export const MAINNET_RPC_MAPPING = { - ethereum: process.env.REACT_APP_ETHEREUM_RPC, - solana: process.env.REACT_APP_SOLANA_RPC, - polygon: process.env.REACT_APP_POLYGON_RPC, - bsc: process.env.REACT_APP_BSC_RPC, - avalanche: process.env.REACT_APP_AVALANCHE_RPC, - fantom: process.env.REACT_APP_FANTOM_RPC, - celo: process.env.REACT_APP_CELO_RPC, - moonbeam: process.env.REACT_APP_MOONBEAM_RPC, - sui: process.env.REACT_APP_SUI_RPC, - aptos: process.env.REACT_APP_APTOS_RPC, - sei: process.env.REACT_APP_SEI_RPC, - base: process.env.REACT_APP_BASE_RPC, - osmosis: process.env.REACT_APP_OSMOSIS_RPC, - wormchain: process.env.REACT_APP_WORMCHAIN_RPC, + ...populateRpcField('ethereum', REACT_APP_ETHEREUM_RPC), + ...populateRpcField('solana', REACT_APP_SOLANA_RPC), + ...populateRpcField('polygon', REACT_APP_POLYGON_RPC), + ...populateRpcField('bsc', REACT_APP_BSC_RPC), + ...populateRpcField('avalanche', REACT_APP_AVALANCHE_RPC), + ...populateRpcField('fantom', REACT_APP_FANTOM_RPC), + ...populateRpcField('celo', REACT_APP_CELO_RPC), + ...populateRpcField('moonbeam', REACT_APP_MOONBEAM_RPC), + ...populateRpcField('sui', REACT_APP_SUI_RPC), + ...populateRpcField('aptos', REACT_APP_APTOS_RPC), + ...populateRpcField('sei', REACT_APP_SEI_RPC), + ...populateRpcField('base', REACT_APP_BASE_RPC), + ...populateRpcField('osmosis', REACT_APP_OSMOSIS_RPC), + ...populateRpcField('wormchain', REACT_APP_WORMCHAIN_RPC), }; export const MAINNET_REST_MAPPING = { - sei: process.env.REACT_APP_SEI_REST, + ...populateRpcField('sei', REACT_APP_SEI_REST), }; diff --git a/wormhole-connect/src/config/testnet/rpcs.ts b/wormhole-connect/src/config/testnet/rpcs.ts index b52b09c6c..50d77773b 100644 --- a/wormhole-connect/src/config/testnet/rpcs.ts +++ b/wormhole-connect/src/config/testnet/rpcs.ts @@ -1,20 +1,39 @@ +import { populateRpcField } from 'config/utils'; +const { + REACT_APP_GOERLI_RPC, + REACT_APP_MUMBAI_RPC, + REACT_APP_BSC_TESTNET_RPC, + REACT_APP_FUJI_RPC, + REACT_APP_FANTOM_TESTNET_RPC, + REACT_APP_ALFAJORES_RPC, + REACT_APP_SOLANA_DEVNET_RPC, + REACT_APP_MOONBASE_RPC, + REACT_APP_SUI_TESTNET_RPC, + REACT_APP_APTOS_TESTNET_RPC, + REACT_APP_SEI_TESTNET_RPC, + REACT_APP_BASE_GOERLI_RPC, + REACT_APP_OSMOSIS_TESTNET_RPC, + REACT_APP_WORMCHAIN_TESTNET_RPC, + REACT_APP_SEI_REST, +} = process.env; + export const TESTNET_RPC_MAPPING = { - goerli: process.env.REACT_APP_GOERLI_RPC, - mumbai: process.env.REACT_APP_MUMBAI_RPC, - bsc: process.env.REACT_APP_BSC_TESTNET_RPC, - fuji: process.env.REACT_APP_FUJI_RPC, - fantom: process.env.REACT_APP_FANTOM_TESTNET_RPC, - alfajores: process.env.REACT_APP_ALFAJORES_RPC, - solana: process.env.REACT_APP_SOLANA_DEVNET_RPC, - moonbasealpha: process.env.REACT_APP_MOONBASE_RPC, - sui: process.env.REACT_APP_SUI_TESTNET_RPC, - aptos: process.env.REACT_APP_APTOS_TESTNET_RPC, - sei: process.env.REACT_APP_SEI_TESTNET_RPC, - basegoerli: process.env.REACT_APP_BASE_GOERLI_RPC, - osmosis: process.env.REACT_APP_OSMOSIS_TESTNET_RPC, - wormchain: process.env.REACT_APP_WORMCHAIN_TESTNET_RPC, + ...populateRpcField('goerli', REACT_APP_GOERLI_RPC), + ...populateRpcField('mumbai', REACT_APP_MUMBAI_RPC), + ...populateRpcField('bsc', REACT_APP_BSC_TESTNET_RPC), + ...populateRpcField('fuji', REACT_APP_FUJI_RPC), + ...populateRpcField('fantom', REACT_APP_FANTOM_TESTNET_RPC), + ...populateRpcField('alfajores', REACT_APP_ALFAJORES_RPC), + ...populateRpcField('solana', REACT_APP_SOLANA_DEVNET_RPC), + ...populateRpcField('moonbasealpha', REACT_APP_MOONBASE_RPC), + ...populateRpcField('sui', REACT_APP_SUI_TESTNET_RPC), + ...populateRpcField('aptos', REACT_APP_APTOS_TESTNET_RPC), + ...populateRpcField('sei', REACT_APP_SEI_TESTNET_RPC), + ...populateRpcField('basegoerli', REACT_APP_BASE_GOERLI_RPC), + ...populateRpcField('osmosis', REACT_APP_OSMOSIS_TESTNET_RPC), + ...populateRpcField('wormchain', REACT_APP_WORMCHAIN_TESTNET_RPC), }; export const TESTNET_REST_MAPPING = { - sei: process.env.REACT_APP_SEI_REST, + ...populateRpcField('sei', REACT_APP_SEI_REST), }; diff --git a/wormhole-connect/src/config/utils.ts b/wormhole-connect/src/config/utils.ts index b5ab59a9e..eed45189c 100644 --- a/wormhole-connect/src/config/utils.ts +++ b/wormhole-connect/src/config/utils.ts @@ -7,6 +7,14 @@ const error = (msg: string) => { console.error(`Wormhole Connect:\n${msg}`); }; +export const populateRpcField = ( + chainName: string, + rpc: string | undefined, +) => { + if (!rpc) return {}; + return { [chainName]: rpc }; +}; + export const validateResourceMap = (field: 'rpcs' | 'rest') => { if (!config || !config[field]) { error(