Skip to content

Commit 0b29578

Browse files
committed
clean up confusing env/network mess
1 parent 37ee1e1 commit 0b29578

File tree

5 files changed

+36
-26
lines changed

5 files changed

+36
-26
lines changed

wormhole-connect/src/config/index.ts

+24-17
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,42 @@ import {
55
ForeignAssetCache,
66
ChainResourceMap,
77
} from '@wormhole-foundation/wormhole-connect-sdk';
8+
import { Network as NetworkLegacy } from '@certusone/wormhole-sdk'; // TODO remove
89
import MAINNET from './mainnet';
910
import TESTNET from './testnet';
1011
import DEVNET from './devnet';
1112
import type { WormholeConnectConfig } from './types';
12-
import { Environment, InternalConfig, Route, TokensConfig } from './types';
13+
import { Network, InternalConfig, Route, TokensConfig } from './types';
1314
import { mergeCustomTokensConfig, validateDefaults } from './utils';
1415

15-
type Network = 'MAINNET' | 'TESTNET' | 'DEVNET';
16-
1716
export function buildConfig(
1817
customConfig?: WormholeConnectConfig,
1918
): InternalConfig {
20-
const env = (customConfig?.env ||
19+
const network = (
20+
customConfig?.network ||
21+
customConfig?.env || // TODO remove; deprecated
2122
import.meta.env.REACT_APP_CONNECT_ENV?.toLowerCase() ||
22-
'testnet') as Environment;
23+
'testnet'
24+
).toLowerCase() as Network;
2325

24-
if (!['mainnet', 'testnet', 'devnet'].includes(env))
25-
throw new Error(`Invalid env "${env}"`);
26+
if (!['mainnet', 'testnet', 'devnet'].includes(network))
27+
throw new Error(`Invalid env "${network}"`);
2628

27-
const network: Network = env.toUpperCase() as Network;
29+
// TODO remove
30+
// SDKv1 uses ALLCAPS network consts like "MAINNET"
31+
// Connect uses lowercase like "mainnet"
32+
// SDKv2 uses capitalized like "Mainnet"
33+
// It's a mess
34+
const networkLegacy = network.toUpperCase() as NetworkLegacy;
2835

29-
const networkData = { MAINNET, DEVNET, TESTNET }[network];
36+
const networkData = { MAINNET, DEVNET, TESTNET }[networkLegacy]!;
3037

3138
const tokens = mergeCustomTokensConfig(
3239
networkData.tokens,
3340
customConfig?.tokensConfig,
3441
);
3542

36-
const sdkConfig = WormholeContext.getConfig(network);
43+
const sdkConfig = WormholeContext.getConfig(networkLegacy);
3744

3845
const rpcs = Object.assign(
3946
{},
@@ -42,17 +49,17 @@ export function buildConfig(
4249
customConfig?.rpcs,
4350
);
4451

45-
const wh = getWormholeContext(network, sdkConfig, tokens, rpcs);
52+
const wh = getWormholeContext(networkLegacy, sdkConfig, tokens, rpcs);
4653

4754
return {
4855
wh,
4956
sdkConfig,
5057

5158
// TODO remove either env or network from this
5259
// some code uses lowercase, some uppercase... :(
53-
env,
5460
network,
55-
isMainnet: env === 'mainnet',
61+
networkLegacy,
62+
isMainnet: network === 'mainnet',
5663
// External resources
5764
rpcs,
5865
rest: Object.assign(
@@ -66,7 +73,7 @@ export function buildConfig(
6673
mainnet: 'https://api.wormholescan.io/',
6774
testnet: 'https://api.testnet.wormholescan.io/',
6875
devnet: '',
69-
}[env],
76+
}[network],
7077
wormholeRpcHosts: {
7178
mainnet: [
7279
'https://wormhole-v2-mainnet-api.mcf.rocks',
@@ -79,7 +86,7 @@ export function buildConfig(
7986
'https://guardian-02.testnet.xlabs.xyz',
8087
],
8188
devnet: ['http://localhost:7071'],
82-
}[env],
89+
}[network],
8390
coinGeckoApiKey: customConfig?.coinGeckoApiKey,
8491

8592
// White lists
@@ -106,7 +113,7 @@ export function buildConfig(
106113
devnet: '',
107114
testnet:
108115
'https://wormhole-foundation.github.io/example-token-bridge-ui/#/register',
109-
}[env],
116+
}[network],
110117
bridgeDefaults: validateDefaults(customConfig?.bridgeDefaults),
111118
cctpWarning: customConfig?.cctpWarning?.href || '',
112119
pageHeader: customConfig?.pageHeader,
@@ -132,7 +139,7 @@ const config = buildConfig();
132139
export default config;
133140

134141
function getWormholeContext(
135-
network: Network,
142+
network: NetworkLegacy,
136143
sdkConfig: WormholeConfig,
137144
tokens: TokensConfig,
138145
rpcs: ChainResourceMap,

wormhole-connect/src/config/types.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Network } from '@certusone/wormhole-sdk';
1+
import { Network as NetworkLegacy } from '@certusone/wormhole-sdk';
22
import {
33
ChainConfig as BaseChainConfig,
44
ChainName,
@@ -57,7 +57,7 @@ export enum Route {
5757

5858
export type SupportedRoutes = keyof typeof Route;
5959

60-
export type Environment = 'mainnet' | 'testnet' | 'devnet';
60+
export type Network = 'mainnet' | 'testnet' | 'devnet';
6161

6262
// TODO: preference is fromChain/toChain, but want to keep backwards compatibility
6363
export interface BridgeDefaults {
@@ -69,7 +69,8 @@ export interface BridgeDefaults {
6969

7070
// This is the integrator-provided JSON config
7171
export interface WormholeConnectConfig {
72-
env?: Environment;
72+
env?: Network; // TODO REMOVE; DEPRECATED
73+
network?: Network; // New name for this, consistent with SDKv2
7374

7475
// External resources
7576
rpcs?: ChainResourceMap;
@@ -78,7 +79,8 @@ export interface WormholeConnectConfig {
7879
coinGeckoApiKey?: string;
7980

8081
// White lists
81-
networks?: ChainName[];
82+
networks?: ChainName[]; // TODO REMOVE; DEPRECATED
83+
chains?: ChainName[]; // New name for this, consistent with SDKv2
8284
tokens?: string[];
8385

8486
// Custom tokens
@@ -121,8 +123,9 @@ export interface InternalConfig {
121123
wh: WormholeContext;
122124
sdkConfig: WormholeConfig;
123125

124-
env: Environment;
125-
network: Network; // TODO reduce these to just one...
126+
network: Network;
127+
networkLegacy: NetworkLegacy; // TODO remove...
128+
126129
isMainnet: boolean;
127130

128131
// External resources

wormhole-connect/src/routes/cosmosGateway/cosmosGateway.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class CosmosGatewayRoute extends BaseRoute {
207207
};
208208

209209
const destChainName = config.wh.toChainName(destChain);
210-
const gasDenom = getNativeDenom(destChainName, config.network);
210+
const gasDenom = getNativeDenom(destChainName, config.networkLegacy);
211211

212212
const tx: CosmosTransaction = {
213213
fee: calculateFee(1000000, `1.0${gasDenom}`),

wormhole-connect/src/utils/wallet/sei.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const getSeiChainId = (env: Network) =>
1616

1717
export async function fetchOptions() {
1818
const seiWallets = getSupportedWallets({
19-
chainId: getSeiChainId(config.network) as SeiChainId,
19+
chainId: getSeiChainId(config.networkLegacy) as SeiChainId,
2020
rpcUrl: config.rpcs.sei || '',
2121
});
2222

wormhole-connect/src/views/Redeem/ExplorerLink.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function ExplorerLink(props: ExplorerLinkProps) {
3939
explorerLink = `${chainConfig.explorerUrl}transaction/${props.txHash}`;
4040
} else if (chainConfig.key === 'osmosis') {
4141
explorerLink =
42-
config.network === 'TESTNET'
42+
config.network === 'testnet'
4343
? `${chainConfig.explorerUrl}txs/${props.txHash}`
4444
: `${chainConfig.explorerUrl}transactions/${props.txHash}`;
4545
} else {

0 commit comments

Comments
 (0)