Chore/more env config (#1363)
* chore: remove vega URL as no longer needed * chore: remove bad env config * chore: remove config caching * chore: remove silly text * style: lint * chore: style lint * test: remove test for removed functionality
This commit is contained in:
parent
6c41c0b14d
commit
e8d110d207
@ -1,6 +1,6 @@
|
||||
# App configuration variables
|
||||
NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
|
||||
NX_TENDERMINT_URL=https://tm.n06.testnet.vega.xyz/tm
|
||||
NX_TENDERMINT_URL=https://tm.n07.testnet.vega.xyz/tm
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://lb.testnet.vega.xyz/tm/websocket
|
||||
NX_VEGA_URL=https://api.n11.testnet.vega.xyz/graphql
|
||||
NX_VEGA_ENV=TESTNET
|
||||
|
@ -1,14 +1,7 @@
|
||||
NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
|
||||
NX_TENDERMINT_URL=http://localhost:26617
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://localhost:26617/websocket
|
||||
NX_VEGA_URL=http://localhost:3028/query
|
||||
NX_VEGA_ENV=CUSTOM
|
||||
|
||||
NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
|
||||
NX_TENDERMINT_URL=https://n01.stagnet3.vega.xyz/tm
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://n01.stagnet3.vega.xyz/tm/websocket
|
||||
NX_VEGA_CONFIG_URL=https://static.vega.xyz/assets/stagnet3-network.json
|
||||
NX_VEGA_URL=https://api.n01.stagnet3.vega.xyz/graphql
|
||||
NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
|
||||
NX_VEGA_ENV=STAGNET3
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -1,9 +1,8 @@
|
||||
# App configuration variables
|
||||
NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
|
||||
NX_TENDERMINT_URL=https://tm.n06.testnet.vega.xyz
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://tm.n06.testnet.vega.xyz/websocket
|
||||
NX_TENDERMINT_URL=https://tm.n07.testnet.vega.xyz
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://tm.n07.testnet.vega.xyz/websocket
|
||||
NX_VEGA_CONFIG_URL=https://static.vega.xyz/assets/testnet-network.json
|
||||
NX_VEGA_URL=https://api.n09.testnet.vega.xyz/graphql
|
||||
NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
|
||||
NX_VEGA_ENV=TESTNET
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -17,7 +17,6 @@ const PendingTxs = () => {
|
||||
<RouteTitle data-testid="unconfirmed-transactions-header">
|
||||
{t('Unconfirmed transactions')}
|
||||
</RouteTitle>
|
||||
https://tm.n06.testnet.vega.xyz/tm/unconfirmed_txs
|
||||
<br />
|
||||
<div>{t(`Number: ${unconfirmedTransactions?.result?.n_txs || 0}`)}</div>
|
||||
<br />
|
||||
|
@ -87,24 +87,6 @@ describe('useConfig hook', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('caches the configuration', async () => {
|
||||
const { result: firstResult } = renderHook(() =>
|
||||
useConfig({ environment: mockEnvironment }, onError)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
expect(firstResult.current.config).toEqual(mockConfig);
|
||||
});
|
||||
|
||||
const { result: secondResult } = renderHook(() =>
|
||||
useConfig({ environment: mockEnvironment }, onError)
|
||||
);
|
||||
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
expect(secondResult.current.config).toEqual(mockConfig);
|
||||
});
|
||||
|
||||
it('executes the error callback when the config endpoint fails', async () => {
|
||||
// @ts-ignore typescript doesn't recognise the mocked instance
|
||||
global.fetch.mockImplementation(() => Promise.reject());
|
||||
|
@ -1,11 +1,8 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { LocalStorage } from '@vegaprotocol/react-helpers';
|
||||
import { ErrorType } from '../types';
|
||||
import type { Environment, Configuration, Networks } from '../types';
|
||||
import type { Environment, Configuration } from '../types';
|
||||
import { validateConfiguration } from '../utils/validate-configuration';
|
||||
|
||||
export const LOCAL_STORAGE_NETWORK_KEY = 'vegaNetworkConfig';
|
||||
|
||||
export type EnvironmentWithOptionalUrl = Partial<Environment> &
|
||||
Omit<Environment, 'VEGA_URL'>;
|
||||
|
||||
@ -16,36 +13,6 @@ const compileHosts = (hosts: string[], envUrl?: string) => {
|
||||
return hosts;
|
||||
};
|
||||
|
||||
const getCacheKey = (env: Networks) => `${LOCAL_STORAGE_NETWORK_KEY}-${env}`;
|
||||
|
||||
const getCachedConfig = (env: Networks, envUrl?: string) => {
|
||||
const cacheKey = getCacheKey(env);
|
||||
const value = LocalStorage.getItem(cacheKey);
|
||||
|
||||
if (value) {
|
||||
try {
|
||||
const config = JSON.parse(value) as Configuration;
|
||||
const hasError = validateConfiguration(config);
|
||||
|
||||
if (hasError) {
|
||||
throw new Error('Invalid configuration found in the storage.');
|
||||
}
|
||||
|
||||
return {
|
||||
...config,
|
||||
hosts: compileHosts(config.hosts, envUrl),
|
||||
};
|
||||
} catch (err) {
|
||||
LocalStorage.removeItem(cacheKey);
|
||||
console.warn(
|
||||
'Malformed data found for network configuration. Removed cached configuration, continuing...'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
type UseConfigOptions = {
|
||||
environment: EnvironmentWithOptionalUrl;
|
||||
defaultConfig?: Configuration;
|
||||
@ -57,7 +24,7 @@ export const useConfig = (
|
||||
) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [config, setConfig] = useState<Configuration | undefined>(
|
||||
defaultConfig ?? getCachedConfig(environment.VEGA_ENV, environment.VEGA_URL)
|
||||
defaultConfig
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@ -78,10 +45,6 @@ export const useConfig = (
|
||||
const hosts = compileHosts(configData.hosts, environment.VEGA_URL);
|
||||
|
||||
isMounted && setConfig({ hosts });
|
||||
LocalStorage.setItem(
|
||||
getCacheKey(environment.VEGA_ENV),
|
||||
JSON.stringify({ hosts })
|
||||
);
|
||||
isMounted && setLoading(false);
|
||||
} catch (err) {
|
||||
if (isMounted) {
|
||||
|
Loading…
Reference in New Issue
Block a user