feat: add is test env helper
This commit is contained in:
@@ -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='dummy dsn'
|
||||
|
||||
# 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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
+2
-2
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user