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:
Dexter Edwards 2022-09-16 12:32:44 +01:00 committed by GitHub
parent 6c41c0b14d
commit e8d110d207
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 5 additions and 69 deletions

View File

@ -1,6 +1,6 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api 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_TENDERMINT_WEBSOCKET_URL=wss://lb.testnet.vega.xyz/tm/websocket
NX_VEGA_URL=https://api.n11.testnet.vega.xyz/graphql NX_VEGA_URL=https://api.n11.testnet.vega.xyz/graphql
NX_VEGA_ENV=TESTNET NX_VEGA_ENV=TESTNET

View File

@ -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_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL=https://n01.stagnet3.vega.xyz/tm NX_TENDERMINT_URL=https://n01.stagnet3.vega.xyz/tm
NX_TENDERMINT_WEBSOCKET_URL=wss://n01.stagnet3.vega.xyz/tm/websocket 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_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_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
NX_VEGA_ENV=STAGNET3 NX_VEGA_ENV=STAGNET3
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions

View File

@ -1,9 +1,8 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL=https://tm.n06.testnet.vega.xyz NX_TENDERMINT_URL=https://tm.n07.testnet.vega.xyz
NX_TENDERMINT_WEBSOCKET_URL=wss://tm.n06.testnet.vega.xyz/websocket 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_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_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
NX_VEGA_ENV=TESTNET NX_VEGA_ENV=TESTNET
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions

View File

@ -17,7 +17,6 @@ const PendingTxs = () => {
<RouteTitle data-testid="unconfirmed-transactions-header"> <RouteTitle data-testid="unconfirmed-transactions-header">
{t('Unconfirmed transactions')} {t('Unconfirmed transactions')}
</RouteTitle> </RouteTitle>
https://tm.n06.testnet.vega.xyz/tm/unconfirmed_txs
<br /> <br />
<div>{t(`Number: ${unconfirmedTransactions?.result?.n_txs || 0}`)}</div> <div>{t(`Number: ${unconfirmedTransactions?.result?.n_txs || 0}`)}</div>
<br /> <br />

View File

@ -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 () => { it('executes the error callback when the config endpoint fails', async () => {
// @ts-ignore typescript doesn't recognise the mocked instance // @ts-ignore typescript doesn't recognise the mocked instance
global.fetch.mockImplementation(() => Promise.reject()); global.fetch.mockImplementation(() => Promise.reject());

View File

@ -1,11 +1,8 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { LocalStorage } from '@vegaprotocol/react-helpers';
import { ErrorType } from '../types'; import { ErrorType } from '../types';
import type { Environment, Configuration, Networks } from '../types'; import type { Environment, Configuration } from '../types';
import { validateConfiguration } from '../utils/validate-configuration'; import { validateConfiguration } from '../utils/validate-configuration';
export const LOCAL_STORAGE_NETWORK_KEY = 'vegaNetworkConfig';
export type EnvironmentWithOptionalUrl = Partial<Environment> & export type EnvironmentWithOptionalUrl = Partial<Environment> &
Omit<Environment, 'VEGA_URL'>; Omit<Environment, 'VEGA_URL'>;
@ -16,36 +13,6 @@ const compileHosts = (hosts: string[], envUrl?: string) => {
return hosts; 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 = { type UseConfigOptions = {
environment: EnvironmentWithOptionalUrl; environment: EnvironmentWithOptionalUrl;
defaultConfig?: Configuration; defaultConfig?: Configuration;
@ -57,7 +24,7 @@ export const useConfig = (
) => { ) => {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [config, setConfig] = useState<Configuration | undefined>( const [config, setConfig] = useState<Configuration | undefined>(
defaultConfig ?? getCachedConfig(environment.VEGA_ENV, environment.VEGA_URL) defaultConfig
); );
useEffect(() => { useEffect(() => {
@ -78,10 +45,6 @@ export const useConfig = (
const hosts = compileHosts(configData.hosts, environment.VEGA_URL); const hosts = compileHosts(configData.hosts, environment.VEGA_URL);
isMounted && setConfig({ hosts }); isMounted && setConfig({ hosts });
LocalStorage.setItem(
getCacheKey(environment.VEGA_ENV),
JSON.stringify({ hosts })
);
isMounted && setLoading(false); isMounted && setLoading(false);
} catch (err) { } catch (err) {
if (isMounted) { if (isMounted) {