chore(trading): allow window._env_ override (#4159)
This commit is contained in:
parent
c3e39b6e15
commit
b8c9f9772e
@ -14,6 +14,7 @@ NX_VEGA_WALLET_URL=http://localhost:1789
|
||||
NX_ETH_LOCAL_PROVIDER_URL=http://localhost:8545/
|
||||
NX_ETH_WALLET_MNEMONIC="ozone access unlock valid olympic save include omit supply green clown session"
|
||||
NX_WALLETCONNECT_PROJECT_ID=fe8091dc35738863e509fc4947525c72
|
||||
NX_SENTRY_DSN=https://dummy@o999999.ingest.sentry.io/9999999
|
||||
|
||||
# Expose some env vars to cypress environment for market setup
|
||||
CYPRESS_ETH_WALLET_MNEMONIC=ozone access unlock valid olympic save include omit supply green clown session
|
||||
|
@ -2,7 +2,7 @@ NX_ETHEREUM_PROVIDER_URL=https://sepolia.infura.io/v3/4f846e79e13f44d1b51bbd7ed9
|
||||
NX_ETHERSCAN_URL=https://sepolia.etherscan.io
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
NX_HOSTED_WALLET_URL=https://wallet.testnet.vega.xyz
|
||||
NX_TRADING_SENTRY_DSN=https://2ffce43721964aafa78277c50654ece4@o286262.ingest.sentry.io/6300613
|
||||
NX_SENTRY_DSN=https://2ffce43721964aafa78277c50654ece4@o286262.ingest.sentry.io/6300613
|
||||
NX_VEGA_CONFIG_URL=https://raw.githubusercontent.com/vegaprotocol/networks-internal/main/devnet1/vegawallet-devnet1.toml
|
||||
NX_VEGA_ENV=DEVNET
|
||||
NX_VEGA_EXPLORER_URL=https://dev.explorer.vega.xyz
|
||||
|
@ -1,7 +1,7 @@
|
||||
NX_ETHEREUM_PROVIDER_URL=https://eth-mainnet.gateway.pokt.network/v1/lb/af6a2d529a11f8158bc8ca2a
|
||||
NX_ETHERSCAN_URL=https://etherscan.io
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
NX_TRADING_SENTRY_DSN=https://2ffce43721964aafa78277c50654ece4@o286262.ingest.sentry.io/6300613
|
||||
NX_SENTRY_DSN=https://2ffce43721964aafa78277c50654ece4@o286262.ingest.sentry.io/6300613
|
||||
NX_VEGA_CONFIG_URL=https://raw.githubusercontent.com/vegaprotocol/networks/master/mainnet1/mainnet1.toml
|
||||
NX_VEGA_ENV=MAINNET
|
||||
NX_VEGA_EXPLORER_URL=https://explorer.vega.xyz
|
||||
|
@ -2,7 +2,7 @@ NX_ETHEREUM_PROVIDER_URL=https://sepolia.infura.io/v3/4f846e79e13f44d1b51bbd7ed9
|
||||
NX_ETHERSCAN_URL=https://sepolia.etherscan.io
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
NX_HOSTED_WALLET_URL=https://wallet.testnet.vega.xyz
|
||||
NX_TRADING_SENTRY_DSN=https://2ffce43721964aafa78277c50654ece4@o286262.ingest.sentry.io/6300613
|
||||
NX_SENTRY_DSN=https://2ffce43721964aafa78277c50654ece4@o286262.ingest.sentry.io/6300613
|
||||
NX_VEGA_CONFIG_URL=https://raw.githubusercontent.com/vegaprotocol/networks-internal/main/stagnet1/vegawallet-stagnet1.toml
|
||||
NX_VEGA_ENV=STAGNET1
|
||||
NX_VEGA_EXPLORER_URL=https://explorer.stagnet1.vega.rocks
|
||||
|
@ -2,7 +2,7 @@ NX_ETHEREUM_PROVIDER_URL=https://sepolia.infura.io/v3/4f846e79e13f44d1b51bbd7ed9
|
||||
NX_ETHERSCAN_URL=https://sepolia.etherscan.io
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
NX_HOSTED_WALLET_URL=https://wallet.testnet.vega.xyz
|
||||
NX_TRADING_SENTRY_DSN=https://2ffce43721964aafa78277c50654ece4@o286262.ingest.sentry.io/6300613
|
||||
NX_SENTRY_DSN=https://2ffce43721964aafa78277c50654ece4@o286262.ingest.sentry.io/6300613
|
||||
NX_VEGA_CONFIG_URL=https://raw.githubusercontent.com/vegaprotocol/networks-internal/main/fairground/vegawallet-fairground.toml
|
||||
NX_VEGA_ENV=TESTNET
|
||||
NX_VEGA_EXPLORER_URL=https://explorer.fairground.wtf
|
||||
|
@ -2,7 +2,7 @@ NX_ETHEREUM_PROVIDER_URL=https://sepolia.infura.io/v3/4f846e79e13f44d1b51bbd7ed9
|
||||
NX_ETHERSCAN_URL=https://sepolia.etherscan.io
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
NX_HOSTED_WALLET_URL=https://wallet.testnet.vega.xyz
|
||||
NX_TRADING_SENTRY_DSN=https://2ffce43721964aafa78277c50654ece4@o286262.ingest.sentry.io/6300613
|
||||
NX_SENTRY_DSN=https://2ffce43721964aafa78277c50654ece4@o286262.ingest.sentry.io/6300613
|
||||
NX_VEGA_CONFIG_URL=https://raw.githubusercontent.com/vegaprotocol/networks/master/testnet2/testnet2.toml
|
||||
NX_VEGA_ENV=VALIDATOR_TESTNET
|
||||
NX_VEGA_EXPLORER_URL=https://explorer.validators-testnet.vega.rocks
|
||||
|
@ -1,17 +1,25 @@
|
||||
import { render, screen, act } from '@testing-library/react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { TelemetryApproval } from './telemetry-approval';
|
||||
|
||||
jest.mock('@vegaprotocol/logger', () => ({
|
||||
SentryInit: () => undefined,
|
||||
SentryClose: () => undefined,
|
||||
}));
|
||||
|
||||
jest.mock('@vegaprotocol/environment', () => ({
|
||||
useEnvironment: () => ({ VEGA_ENV: 'test', SENTRY_DSN: 'sentry-dsn' }),
|
||||
}));
|
||||
|
||||
describe('TelemetryApproval', () => {
|
||||
it('click on checkbox should be properly handled', () => {
|
||||
it('click on checkbox should be properly handled', async () => {
|
||||
const helpText = 'My help text';
|
||||
render(<TelemetryApproval helpText={helpText} />);
|
||||
expect(screen.getByRole('checkbox')).toHaveAttribute(
|
||||
'data-state',
|
||||
'unchecked'
|
||||
);
|
||||
act(() => {
|
||||
screen.getByRole('checkbox').click();
|
||||
});
|
||||
await userEvent.click(screen.getByRole('checkbox'));
|
||||
expect(screen.getByRole('checkbox')).toHaveAttribute(
|
||||
'data-state',
|
||||
'checked'
|
||||
|
@ -11,6 +11,7 @@ import { WelcomeNoticeDialog } from './welcome-notice-dialog';
|
||||
import { useGlobalStore } from '../../stores';
|
||||
import { useEnvironment } from '@vegaprotocol/environment';
|
||||
import { Networks } from '@vegaprotocol/environment';
|
||||
import { isTestEnv } from '@vegaprotocol/utils';
|
||||
|
||||
export const WelcomeDialog = () => {
|
||||
const { VEGA_ENV } = useEnvironment();
|
||||
@ -31,9 +32,7 @@ export const WelcomeDialog = () => {
|
||||
);
|
||||
|
||||
const isRiskDialogNeeded =
|
||||
riskAccepted !== 'true' &&
|
||||
VEGA_ENV !== Networks.MAINNET &&
|
||||
!('Cypress' in window);
|
||||
riskAccepted !== 'true' && VEGA_ENV !== Networks.MAINNET && !isTestEnv();
|
||||
|
||||
const isWelcomeDialogNeeded = pathname === '/' || shouldDisplayWelcomeDialog;
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
const windowOrDefault = (key: string, defaultValue?: string) => {
|
||||
if (typeof window !== 'undefined') {
|
||||
if (window._env_ && window._env_[key]) {
|
||||
return window._env_[key];
|
||||
}
|
||||
}
|
||||
return defaultValue || '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Need to have default value as next in-lines environment variables. Cannot figure out dynamic keys.
|
||||
* So must provide the default with the key so that next can figure it out.
|
||||
*/
|
||||
export const ENV = {
|
||||
envName: windowOrDefault('NX_VEGA_ENV', process.env['NX_VEGA_ENV']),
|
||||
dsn: windowOrDefault(
|
||||
'NX_TRADING_SENTRY_DSN',
|
||||
process.env['NX_TRADING_SENTRY_DSN']
|
||||
),
|
||||
};
|
@ -1 +0,0 @@
|
||||
export * from './env';
|
@ -12,22 +12,26 @@ jest.mock('@vegaprotocol/react-helpers', () => ({
|
||||
.fn()
|
||||
.mockImplementation(() => [false, mockSetValue, mockRemoveValue]),
|
||||
}));
|
||||
jest.mock('@vegaprotocol/environment', () => ({
|
||||
useEnvironment: () => ({ VEGA_ENV: 'test', SENTRY_DSN: 'sentry-dsn' }),
|
||||
}));
|
||||
|
||||
describe('useTelemetryApproval', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('hook should return proper array', () => {
|
||||
const res = renderHook(() => useTelemetryApproval());
|
||||
expect(res.result.current[0]).toEqual(false);
|
||||
expect(res.result.current[1]).toEqual(expect.any(Function));
|
||||
const { result } = renderHook(() => useTelemetryApproval());
|
||||
expect(result.current[0]).toEqual(false);
|
||||
expect(result.current[1]).toEqual(expect.any(Function));
|
||||
expect(useLocalStorage).toHaveBeenCalledWith(STORAGE_KEY);
|
||||
});
|
||||
|
||||
it('hook should init stuff properly', async () => {
|
||||
const res = renderHook(() => useTelemetryApproval());
|
||||
const { result } = renderHook(() => useTelemetryApproval());
|
||||
await act(() => {
|
||||
res.result.current[1](true);
|
||||
result.current[1](true);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(SentryInit).toHaveBeenCalled();
|
||||
@ -36,9 +40,9 @@ describe('useTelemetryApproval', () => {
|
||||
});
|
||||
|
||||
it('hook should close stuff properly', async () => {
|
||||
const res = renderHook(() => useTelemetryApproval());
|
||||
const { result } = renderHook(() => useTelemetryApproval());
|
||||
await act(() => {
|
||||
res.result.current[1](false);
|
||||
result.current[1](false);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(SentryClose).toHaveBeenCalled();
|
||||
|
@ -1,24 +1,25 @@
|
||||
import { useLocalStorage } from '@vegaprotocol/react-helpers';
|
||||
import { useCallback } from 'react';
|
||||
import { SentryInit, SentryClose } from '@vegaprotocol/logger';
|
||||
import { ENV } from '../config';
|
||||
import { useEnvironment } from '@vegaprotocol/environment';
|
||||
export const STORAGE_KEY = 'vega_telemetry_approval';
|
||||
|
||||
export const useTelemetryApproval = (): [
|
||||
value: boolean,
|
||||
setValue: (value: boolean) => void
|
||||
] => {
|
||||
const { VEGA_ENV, SENTRY_DSN } = useEnvironment();
|
||||
const [value, setValue, removeValue] = useLocalStorage(STORAGE_KEY);
|
||||
const setApprove = useCallback(
|
||||
(value: boolean) => {
|
||||
if (value) {
|
||||
SentryInit(ENV.dsn, ENV.envName);
|
||||
if (value && SENTRY_DSN) {
|
||||
SentryInit(SENTRY_DSN, VEGA_ENV);
|
||||
return setValue('1');
|
||||
}
|
||||
SentryClose();
|
||||
removeValue();
|
||||
},
|
||||
[setValue, removeValue]
|
||||
[setValue, removeValue, SENTRY_DSN, VEGA_ENV]
|
||||
);
|
||||
return [Boolean(value), setApprove];
|
||||
};
|
||||
|
@ -34,7 +34,6 @@ import { ViewingBanner } from '../components/viewing-banner';
|
||||
import { AnnouncementBanner, UpgradeBanner } from '../components/banner';
|
||||
import { AppLoader, DynamicLoader } from '../components/app-loader';
|
||||
import { Navbar } from '../components/navbar';
|
||||
import { ENV } from '../lib/config';
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import { activeOrdersProvider } from '@vegaprotocol/orders';
|
||||
import { useTelemetryApproval } from '../lib/hooks/use-telemetry-approval';
|
||||
@ -155,10 +154,11 @@ const PartyData = () => {
|
||||
};
|
||||
|
||||
const MaybeConnectEagerly = () => {
|
||||
const { VEGA_ENV, SENTRY_DSN } = useEnvironment();
|
||||
useVegaEagerConnect(Connectors);
|
||||
const [isTelemetryApproved] = useTelemetryApproval();
|
||||
useEthereumEagerConnect(
|
||||
isTelemetryApproved ? { dsn: ENV.dsn, env: ENV.envName } : {}
|
||||
isTelemetryApproved ? { dsn: SENTRY_DSN, env: VEGA_ENV } : {}
|
||||
);
|
||||
|
||||
const { pubKey, connect } = useVegaWallet();
|
||||
|
@ -20,10 +20,6 @@ export default function Document() {
|
||||
href="https://static.vega.xyz/favicon.ico"
|
||||
/>
|
||||
<script src="/theme-setter.js" type="text/javascript" async />
|
||||
{['1', 'true'].includes(process.env['NX_USE_ENV_OVERRIDES'] || '') ? (
|
||||
/* eslint-disable-next-line @next/next/no-sync-scripts */
|
||||
<script src="/assets/env-config.js" type="text/javascript" />
|
||||
) : null}
|
||||
</Head>
|
||||
<body className="font-alpha dark:bg-black dark:text-white">
|
||||
<Main />
|
||||
|
@ -301,6 +301,25 @@ describe('useEnvironment', () => {
|
||||
expect(fetch).toHaveBeenCalledWith(configUrl);
|
||||
});
|
||||
|
||||
it('uses env vars from window._env_ if set', async () => {
|
||||
const url = 'http://foo.bar.com';
|
||||
// @ts-ignore _env_ is declared in app
|
||||
window._env_ = {
|
||||
VEGA_URL: url,
|
||||
};
|
||||
|
||||
const { result } = setup();
|
||||
|
||||
await act(async () => {
|
||||
result.current.initialize();
|
||||
});
|
||||
|
||||
expect(result.current.VEGA_URL).toBe(url);
|
||||
|
||||
// @ts-ignore delete _env_
|
||||
delete window['_env_'];
|
||||
});
|
||||
|
||||
it('sets error if environment is invalid', async () => {
|
||||
const error = console.error;
|
||||
console.error = noop;
|
||||
|
@ -269,34 +269,96 @@ const testSubscription = (client: Client) => {
|
||||
* here to appease the environment store interface
|
||||
*/
|
||||
function compileEnvVars() {
|
||||
const VEGA_ENV = process.env['NX_VEGA_ENV'] as Networks;
|
||||
const VEGA_ENV = windowOrDefault(
|
||||
'VEGA_ENV',
|
||||
process.env['NX_VEGA_ENV']
|
||||
) as Networks;
|
||||
const env: Environment = {
|
||||
VEGA_URL: process.env['NX_VEGA_URL'],
|
||||
VEGA_URL: windowOrDefault('VEGA_URL', process.env['NX_VEGA_URL']),
|
||||
VEGA_ENV,
|
||||
VEGA_CONFIG_URL: process.env['NX_VEGA_CONFIG_URL'] as string,
|
||||
VEGA_NETWORKS: parseNetworks(process.env['NX_VEGA_NETWORKS']),
|
||||
VEGA_WALLET_URL: process.env['NX_VEGA_WALLET_URL'] as string,
|
||||
HOSTED_WALLET_URL: process.env['NX_HOSTED_WALLET_URL'],
|
||||
ETHERSCAN_URL: getEtherscanUrl(VEGA_ENV, process.env['NX_ETHERSCAN_URL']),
|
||||
VEGA_CONFIG_URL: windowOrDefault(
|
||||
'VEGA_CONFIG_URL',
|
||||
process.env['NX_VEGA_CONFIG_URL'] as string
|
||||
),
|
||||
VEGA_NETWORKS: parseNetworks(
|
||||
windowOrDefault('VEGA_NETWORKS', process.env['NX_VEGA_NETWORKS'])
|
||||
),
|
||||
VEGA_WALLET_URL: windowOrDefault(
|
||||
'VEGA_WALLET_URL',
|
||||
process.env['NX_VEGA_WALLET_URL'] as string
|
||||
),
|
||||
HOSTED_WALLET_URL: windowOrDefault(
|
||||
'HOSTED_WALLET_URL',
|
||||
process.env['NX_HOSTED_WALLET_URL']
|
||||
),
|
||||
ETHERSCAN_URL: getEtherscanUrl(
|
||||
VEGA_ENV,
|
||||
windowOrDefault('ETHERSCAN_URL', process.env['NX_ETHERSCAN_URL'])
|
||||
),
|
||||
ETHEREUM_PROVIDER_URL: getEthereumProviderUrl(
|
||||
VEGA_ENV,
|
||||
windowOrDefault(
|
||||
'ETHEREUM_PROVIDER_URL',
|
||||
process.env['NX_ETHEREUM_PROVIDER_URL']
|
||||
)
|
||||
),
|
||||
ETH_LOCAL_PROVIDER_URL: process.env['NX_ETH_LOCAL_PROVIDER_URL'],
|
||||
ETH_WALLET_MNEMONIC: process.env['NX_ETH_WALLET_MNEMONIC'],
|
||||
ORACLE_PROOFS_URL: process.env['NX_ORACLE_PROOFS_URL'],
|
||||
VEGA_DOCS_URL: process.env['NX_VEGA_DOCS_URL'],
|
||||
VEGA_CONSOLE_URL: process.env['NX_VEGA_CONSOLE_URL'],
|
||||
VEGA_EXPLORER_URL: process.env['NX_VEGA_EXPLORER_URL'],
|
||||
VEGA_TOKEN_URL: process.env['NX_VEGA_TOKEN_URL'],
|
||||
GITHUB_FEEDBACK_URL: process.env['NX_GITHUB_FEEDBACK_URL'],
|
||||
MAINTENANCE_PAGE: parseBoolean(process.env['NX_MAINTENANCE_PAGE']),
|
||||
GIT_BRANCH: process.env['GIT_COMMIT_BRANCH'],
|
||||
GIT_COMMIT_HASH: process.env['GIT_COMMIT_HASH'],
|
||||
GIT_ORIGIN_URL: process.env['GIT_ORIGIN_URL'],
|
||||
ANNOUNCEMENTS_CONFIG_URL: process.env['NX_ANNOUNCEMENTS_CONFIG_URL'],
|
||||
VEGA_INCIDENT_URL: process.env['NX_VEGA_INCIDENT_URL'],
|
||||
APP_VERSION: process.env['NX_APP_VERSION'],
|
||||
ETH_LOCAL_PROVIDER_URL: windowOrDefault(
|
||||
'ETH_LOCAL_PROVIDER_URL',
|
||||
process.env['NX_ETH_LOCAL_PROVIDER_URL']
|
||||
),
|
||||
ETH_WALLET_MNEMONIC: windowOrDefault(
|
||||
'ETH_WALLET_MNEMONIC',
|
||||
process.env['NX_ETH_WALLET_MNEMONIC']
|
||||
),
|
||||
ORACLE_PROOFS_URL: windowOrDefault(
|
||||
'ORACLE_PROOFS_URL',
|
||||
process.env['NX_ORACLE_PROOFS_URL']
|
||||
),
|
||||
VEGA_DOCS_URL: windowOrDefault(
|
||||
'VEGA_DOCS_URL',
|
||||
process.env['NX_VEGA_DOCS_URL']
|
||||
),
|
||||
VEGA_CONSOLE_URL: windowOrDefault(
|
||||
'VEGA_CONSOLE_URL',
|
||||
process.env['NX_VEGA_CONSOLE_URL']
|
||||
),
|
||||
VEGA_EXPLORER_URL: windowOrDefault(
|
||||
'VEGA_EXPLORER_URL',
|
||||
process.env['NX_VEGA_EXPLORER_URL']
|
||||
),
|
||||
VEGA_TOKEN_URL: windowOrDefault(
|
||||
'VEGA_TOKEN_URL',
|
||||
process.env['NX_VEGA_TOKEN_URL']
|
||||
),
|
||||
GITHUB_FEEDBACK_URL: windowOrDefault(
|
||||
'GITHUB_FEEDBACK_URL',
|
||||
process.env['NX_GITHUB_FEEDBACK_URL']
|
||||
),
|
||||
MAINTENANCE_PAGE: parseBoolean(
|
||||
windowOrDefault('MAINTENANCE_PAGE', process.env['NX_MAINTENANCE_PAGE'])
|
||||
),
|
||||
GIT_BRANCH: windowOrDefault(
|
||||
'GIT_COMMIT_BRANCH',
|
||||
process.env['GIT_COMMIT_BRANCH']
|
||||
),
|
||||
GIT_COMMIT_HASH: windowOrDefault(
|
||||
'GIT_COMMIT_HASH',
|
||||
process.env['GIT_COMMIT_HASH']
|
||||
),
|
||||
GIT_ORIGIN_URL: windowOrDefault(
|
||||
'GIT_ORIGIN_URL',
|
||||
process.env['GIT_ORIGIN_URL']
|
||||
),
|
||||
ANNOUNCEMENTS_CONFIG_URL: windowOrDefault(
|
||||
'ANNOUNCEMENTS_CONFIG_URL',
|
||||
process.env['NX_ANNOUNCEMENTS_CONFIG_URL']
|
||||
),
|
||||
VEGA_INCIDENT_URL: windowOrDefault(
|
||||
'VEGA_INCIDENT_URL',
|
||||
process.env['NX_VEGA_INCIDENT_URL']
|
||||
),
|
||||
APP_VERSION: windowOrDefault('APP_VERSION', process.env['NX_APP_VERSION']),
|
||||
SENTRY_DSN: windowOrDefault('SENTRY_DSN', process.env['NX_SENTRY_DSN']),
|
||||
};
|
||||
|
||||
return env;
|
||||
@ -341,3 +403,14 @@ function getEtherscanUrl(
|
||||
? 'https://etherscan.io'
|
||||
: 'https://sepolia.etherscan.io';
|
||||
}
|
||||
|
||||
export function windowOrDefault(key: string, defaultValue?: string) {
|
||||
if (typeof window !== 'undefined') {
|
||||
// @ts-ignore avoid conflic in env
|
||||
if (window._env_ && window._env_[key]) {
|
||||
// @ts-ignore presence has been check above
|
||||
return window._env_[key];
|
||||
}
|
||||
}
|
||||
return defaultValue || undefined;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import { useEnvironment } from './use-environment';
|
||||
import { useNavigatorOnline } from '@vegaprotocol/react-helpers';
|
||||
import { Intent } from '@vegaprotocol/ui-toolkit';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { isTestEnv } from '@vegaprotocol/utils';
|
||||
|
||||
const POLL_INTERVAL = 1000;
|
||||
const BLOCK_THRESHOLD = 3;
|
||||
@ -38,7 +39,7 @@ export const useNodeHealth = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!('Cypress' in window) && window.location.hostname !== 'localhost') {
|
||||
if (!isTestEnv() && window.location.hostname !== 'localhost') {
|
||||
startPolling(POLL_INTERVAL);
|
||||
}
|
||||
}, [error, startPolling, stopPolling]);
|
||||
|
@ -52,6 +52,7 @@ const schemaObject = {
|
||||
ANNOUNCEMENTS_CONFIG_URL: z.optional(z.string()),
|
||||
VEGA_INCIDENT_URL: z.optional(z.string()),
|
||||
APP_VERSION: z.optional(z.string()),
|
||||
SENTRY_DSN: z.optional(z.string()),
|
||||
};
|
||||
|
||||
// combine schema above with custom rule to ensure either
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useMemo, useEffect } from 'react';
|
||||
import * as Schema from '@vegaprotocol/types';
|
||||
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
||||
import { removePaginationWrapper, isTestEnv } from '@vegaprotocol/utils';
|
||||
import { useProtocolUpgradeProposalsQuery } from './__generated__/ProtocolUpgradeProposals';
|
||||
|
||||
export const useNextProtocolUpgradeProposals = (since?: number) => {
|
||||
@ -21,7 +21,7 @@ export const useNextProtocolUpgradeProposals = (since?: number) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!('Cypress' in window) && window.location.hostname !== 'localhost') {
|
||||
if (!isTestEnv() && window.location.hostname !== 'localhost') {
|
||||
startPolling(5000);
|
||||
}
|
||||
}, [error, startPolling, stopPolling]);
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useBlockStatisticsQuery } from './__generated__/BlockStatistics';
|
||||
import sum from 'lodash/sum';
|
||||
import { isTestEnv } from '@vegaprotocol/utils';
|
||||
|
||||
const DEFAULT_POLLS = 10;
|
||||
const INTERVAL = 1000;
|
||||
@ -20,7 +21,7 @@ const useAverageBlockDuration = (polls = DEFAULT_POLLS) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!('Cypress' in window) && window.location.hostname !== 'localhost') {
|
||||
if (!isTestEnv() && window.location.hostname !== 'localhost') {
|
||||
startPolling(INTERVAL);
|
||||
}
|
||||
}, [error, startPolling, stopPolling]);
|
||||
|
@ -14,3 +14,4 @@ export * from './lib/remove-pagination-wrapper';
|
||||
export * from './lib/time';
|
||||
export * from './lib/validate';
|
||||
export * from './lib/resolve-network-name';
|
||||
export * from './lib/is-test-env';
|
||||
|
3
libs/utils/src/lib/is-test-env.ts
Normal file
3
libs/utils/src/lib/is-test-env.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export const isTestEnv = () => {
|
||||
return window && 'Cypress' in window;
|
||||
};
|
@ -3,6 +3,7 @@ import { WalletClientError } from '@vegaprotocol/wallet-client';
|
||||
import type { JsonRpcConnector } from './connectors';
|
||||
import { ClientErrors } from './connectors';
|
||||
import { useVegaWallet } from './use-vega-wallet';
|
||||
import { isTestEnv } from '@vegaprotocol/utils';
|
||||
|
||||
export enum Status {
|
||||
Idle = 'Idle',
|
||||
@ -34,7 +35,7 @@ export const useJsonRpcConnect = (onConnect: () => void) => {
|
||||
// Do not throw in when cypress is running as trading app relies on
|
||||
// mocks which result in a mismatch between chainId for app and
|
||||
// chainId for wallet
|
||||
if (!('Cypress' in window)) {
|
||||
if (!isTestEnv()) {
|
||||
const chainIdResult = await connector.getChainId();
|
||||
if (chainIdResult.chainID !== appChainId) {
|
||||
// Throw wallet error for consistent error handling
|
||||
|
@ -7,6 +7,7 @@ import type { Connector } from '@web3-react/types';
|
||||
import { WalletConnect } from '@web3-react/walletconnect-v2';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useWeb3ConnectStore } from './web3-connect-store';
|
||||
import { isTestEnv } from '@vegaprotocol/utils';
|
||||
|
||||
export const ETHEREUM_EAGER_CONNECT = 'ethereum-eager-connect';
|
||||
|
||||
@ -18,7 +19,7 @@ export const useEagerConnect = (loggerConf: LoggerProps) => {
|
||||
const logger = localLoggerFactory(loggerConf);
|
||||
|
||||
useEffect(() => {
|
||||
if (attemptedRef.current || 'Cypress' in window) return;
|
||||
if (attemptedRef.current || isTestEnv()) return;
|
||||
|
||||
const stored = getConnector(connectors, eagerConnector);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user