Skip to content

Commit

Permalink
fix: rpc fields getting overridden in Object.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
anondev2323 committed Sep 8, 2023
1 parent ccff612 commit f583f1e
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 37 deletions.
19 changes: 14 additions & 5 deletions wormhole-connect/src/config/devnet/rpcs.ts
Original file line number Diff line number Diff line change
@@ -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),
};
4 changes: 2 additions & 2 deletions wormhole-connect/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 34 additions & 15 deletions wormhole-connect/src/config/mainnet/rpcs.ts
Original file line number Diff line number Diff line change
@@ -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),
};
49 changes: 34 additions & 15 deletions wormhole-connect/src/config/testnet/rpcs.ts
Original file line number Diff line number Diff line change
@@ -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),
};
8 changes: 8 additions & 0 deletions wormhole-connect/src/config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f583f1e

Please sign in to comment.