diff --git a/apps/trading-e2e/.env b/apps/trading-e2e/.env
index ce19df7a0..d7d339f53 100644
--- a/apps/trading-e2e/.env
+++ b/apps/trading-e2e/.env
@@ -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
diff --git a/apps/trading/.env.devnet b/apps/trading/.env.devnet
index e53d01828..78681b985 100644
--- a/apps/trading/.env.devnet
+++ b/apps/trading/.env.devnet
@@ -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
diff --git a/apps/trading/.env.mainnet b/apps/trading/.env.mainnet
index e227063a2..f95396b07 100644
--- a/apps/trading/.env.mainnet
+++ b/apps/trading/.env.mainnet
@@ -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
diff --git a/apps/trading/.env.stagnet1 b/apps/trading/.env.stagnet1
index 016ede29c..c4183b794 100644
--- a/apps/trading/.env.stagnet1
+++ b/apps/trading/.env.stagnet1
@@ -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
diff --git a/apps/trading/.env.testnet b/apps/trading/.env.testnet
index 2426f57af..03f612e1f 100644
--- a/apps/trading/.env.testnet
+++ b/apps/trading/.env.testnet
@@ -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
diff --git a/apps/trading/.env.validators-testnet b/apps/trading/.env.validators-testnet
index 5cf7eeaae..341ad2fc8 100644
--- a/apps/trading/.env.validators-testnet
+++ b/apps/trading/.env.validators-testnet
@@ -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
diff --git a/apps/trading/components/welcome-dialog/telemetry-approval.spec.tsx b/apps/trading/components/welcome-dialog/telemetry-approval.spec.tsx
index 3061845aa..ac66dcaff 100644
--- a/apps/trading/components/welcome-dialog/telemetry-approval.spec.tsx
+++ b/apps/trading/components/welcome-dialog/telemetry-approval.spec.tsx
@@ -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();
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'
diff --git a/apps/trading/components/welcome-dialog/welcome-dialog.tsx b/apps/trading/components/welcome-dialog/welcome-dialog.tsx
index f57202282..8ca2ade72 100644
--- a/apps/trading/components/welcome-dialog/welcome-dialog.tsx
+++ b/apps/trading/components/welcome-dialog/welcome-dialog.tsx
@@ -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;
diff --git a/apps/trading/lib/config/env.ts b/apps/trading/lib/config/env.ts
deleted file mode 100644
index b153f0721..000000000
--- a/apps/trading/lib/config/env.ts
+++ /dev/null
@@ -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']
- ),
-};
diff --git a/apps/trading/lib/config/index.ts b/apps/trading/lib/config/index.ts
deleted file mode 100644
index c1532d6d2..000000000
--- a/apps/trading/lib/config/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './env';
diff --git a/apps/trading/lib/hooks/use-telemetry-approval.spec.ts b/apps/trading/lib/hooks/use-telemetry-approval.spec.ts
index 97ec110d6..bd0be96b9 100644
--- a/apps/trading/lib/hooks/use-telemetry-approval.spec.ts
+++ b/apps/trading/lib/hooks/use-telemetry-approval.spec.ts
@@ -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();
diff --git a/apps/trading/lib/hooks/use-telemetry-approval.ts b/apps/trading/lib/hooks/use-telemetry-approval.ts
index d469e58ac..25e0203b5 100644
--- a/apps/trading/lib/hooks/use-telemetry-approval.ts
+++ b/apps/trading/lib/hooks/use-telemetry-approval.ts
@@ -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];
};
diff --git a/apps/trading/pages/_app.page.tsx b/apps/trading/pages/_app.page.tsx
index 0c5d4686c..c787eebff 100644
--- a/apps/trading/pages/_app.page.tsx
+++ b/apps/trading/pages/_app.page.tsx
@@ -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();
diff --git a/apps/trading/pages/_document.page.tsx b/apps/trading/pages/_document.page.tsx
index 8d42dcc68..02495416a 100644
--- a/apps/trading/pages/_document.page.tsx
+++ b/apps/trading/pages/_document.page.tsx
@@ -20,10 +20,6 @@ export default function Document() {
href="https://static.vega.xyz/favicon.ico"
/>
- {['1', 'true'].includes(process.env['NX_USE_ENV_OVERRIDES'] || '') ? (
- /* eslint-disable-next-line @next/next/no-sync-scripts */
-
- ) : null}
diff --git a/libs/environment/src/hooks/use-environment.spec.ts b/libs/environment/src/hooks/use-environment.spec.ts
index 38777de8f..10be7ecbf 100644
--- a/libs/environment/src/hooks/use-environment.spec.ts
+++ b/libs/environment/src/hooks/use-environment.spec.ts
@@ -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;
diff --git a/libs/environment/src/hooks/use-environment.ts b/libs/environment/src/hooks/use-environment.ts
index 9110b6a52..7c399907f 100644
--- a/libs/environment/src/hooks/use-environment.ts
+++ b/libs/environment/src/hooks/use-environment.ts
@@ -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,
- process.env['NX_ETHEREUM_PROVIDER_URL']
+ 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;
+}
diff --git a/libs/environment/src/hooks/use-node-health.ts b/libs/environment/src/hooks/use-node-health.ts
index 79d937afc..8cb092d86 100644
--- a/libs/environment/src/hooks/use-node-health.ts
+++ b/libs/environment/src/hooks/use-node-health.ts
@@ -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]);
diff --git a/libs/environment/src/utils/validate-environment.ts b/libs/environment/src/utils/validate-environment.ts
index f4095d357..8a6412af8 100644
--- a/libs/environment/src/utils/validate-environment.ts
+++ b/libs/environment/src/utils/validate-environment.ts
@@ -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
diff --git a/libs/proposals/src/lib/protocol-upgrade-proposals/use-next-protocol-upgrade-proposals.ts b/libs/proposals/src/lib/protocol-upgrade-proposals/use-next-protocol-upgrade-proposals.ts
index 415d648fd..3d27952ab 100644
--- a/libs/proposals/src/lib/protocol-upgrade-proposals/use-next-protocol-upgrade-proposals.ts
+++ b/libs/proposals/src/lib/protocol-upgrade-proposals/use-next-protocol-upgrade-proposals.ts
@@ -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]);
diff --git a/libs/proposals/src/lib/protocol-upgrade-proposals/use-time-to-upgrade.ts b/libs/proposals/src/lib/protocol-upgrade-proposals/use-time-to-upgrade.ts
index 9a61b99a0..7e9c232ae 100644
--- a/libs/proposals/src/lib/protocol-upgrade-proposals/use-time-to-upgrade.ts
+++ b/libs/proposals/src/lib/protocol-upgrade-proposals/use-time-to-upgrade.ts
@@ -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]);
diff --git a/libs/utils/src/index.ts b/libs/utils/src/index.ts
index 163506667..d1e76477f 100644
--- a/libs/utils/src/index.ts
+++ b/libs/utils/src/index.ts
@@ -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';
diff --git a/libs/utils/src/lib/is-test-env.ts b/libs/utils/src/lib/is-test-env.ts
new file mode 100644
index 000000000..d7c2d3cf2
--- /dev/null
+++ b/libs/utils/src/lib/is-test-env.ts
@@ -0,0 +1,3 @@
+export const isTestEnv = () => {
+ return window && 'Cypress' in window;
+};
diff --git a/libs/wallet/src/use-json-rpc-connect.ts b/libs/wallet/src/use-json-rpc-connect.ts
index 40d997d16..811417093 100644
--- a/libs/wallet/src/use-json-rpc-connect.ts
+++ b/libs/wallet/src/use-json-rpc-connect.ts
@@ -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
diff --git a/libs/web3/src/lib/use-eager-connect.ts b/libs/web3/src/lib/use-eager-connect.ts
index e6551e9e4..2dca460fe 100644
--- a/libs/web3/src/lib/use-eager-connect.ts
+++ b/libs/web3/src/lib/use-eager-connect.ts
@@ -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);
diff --git a/nx.json b/nx.json
index 53753cc36..3f17e156e 100644
--- a/nx.json
+++ b/nx.json
@@ -22,7 +22,6 @@
"echo $NX_VEGA_URL",
"echo $NX_TENDERMINT_URL",
"echo $NX_TENDERMINT_WEBSOCKET_URL",
- "echo $NX_USE_ENV_OVERRIDES",
"echo $NX_ETHEREUM_PROVIDER_URL"
],
"url": "https://cloud.nx.app"