diff --git a/apps/explorer-e2e/src/integration/node-switcher.cy.js b/apps/explorer-e2e/src/integration/node-switcher.cy.js index a5b99f165..131cbd9a6 100644 --- a/apps/explorer-e2e/src/integration/node-switcher.cy.js +++ b/apps/explorer-e2e/src/integration/node-switcher.cy.js @@ -49,23 +49,6 @@ context.skip('Node switcher', function () { validateNodeError(errorTypeTxt, nodeErrorTxt); }); - it('Cannot connect to network from different chain ID', function () { - const errorTypeTxt = 'Error: incorrect network'; - const nodeErrorTxt = 'This node is not on the CUSTOM network.'; - - cy.getByTestId('node-url-custom').click(); - - cy.getByTestId(customNodeBtn).within(() => { - cy.get('input').clear().type('https://n03.s.vega.xyz/query'); - cy.getByTestId('link').click(); - }); - cy.getByTestId('ssl-cell', { timeout: 6000 }).should( - 'contain.text', - 'Yes' - ); - validateNodeError(errorTypeTxt, nodeErrorTxt); - }); - function validateNodeError(errortype, errorMsg) { cy.getByTestId(nodeErrorType).should('have.text', errortype); cy.getByTestId(nodeErrorMsg).should('have.text', errorMsg); diff --git a/libs/environment/src/components/node-switcher/node-switcher.spec.tsx b/libs/environment/src/components/node-switcher/node-switcher.spec.tsx index 43606777f..b4d6ffe75 100644 --- a/libs/environment/src/components/node-switcher/node-switcher.spec.tsx +++ b/libs/environment/src/components/node-switcher/node-switcher.spec.tsx @@ -285,45 +285,6 @@ describe('Node switcher', () => { ); }); - it('disables selecting a node when it is on an incorrect network', () => { - const mockUrl = 'https://mock.url'; - const mockConfig = { - hosts: [mockUrl], - }; - - // @ts-ignore Typescript doesn't recognise mocked instances - useNodes.mockImplementation((config: Configuration) => { - const nodeState = getValidNodeState(Networks.TESTNET, mockUrl); - return { - state: { - [mockUrl]: { - ...nodeState, - chain: { - ...nodeState.chain, - value: `some-network-id`, - }, - }, - }, - clients: createMockClients(config.hosts), - updateNodeUrl: jest.fn(), - updateNodeBlock: jest.fn(), - }; - }); - - render( - - - - ); - - expect(screen.getByRole('radio', { name: mockUrl })).toHaveAttribute( - 'disabled' - ); - expect(screen.getByRole('button', { name: 'Connect' })).toHaveAttribute( - 'disabled' - ); - }); - it('allows connecting to a valid node', () => { render(); @@ -583,56 +544,9 @@ describe('Node switcher', () => { expect(screen.getByText(error?.headline ?? '')).toBeInTheDocument(); }); - it('disables selecting a custom node when it is on an incorrect network', () => { - const mockUrl = 'https://mock.url'; - const updateNodeUrlMock = jest.fn(); - - // @ts-ignore Typescript doesn't recognise mocked instances - useNodes.mockImplementation( - mockNodesImplementation(updateNodeUrlMock, (env, url) => { - const nodeState = getValidNodeState(env, url); - return { - ...nodeState, - chain: { - ...nodeState.chain, - value: 'network-chain-id', - }, - }; - }) - ); - - render( - - - - ); - - fireEvent.click(screen.getByRole('radio', { name: 'Other' })); - fireEvent.change(screen.getByRole('textbox'), { - target: { - value: mockUrl, - }, - }); - fireEvent.click(screen.getByRole('link', { name: 'Check' })); - - expect(screen.getByRole('button', { name: 'Connect' })).toHaveAttribute( - 'disabled' - ); - - const error = getErrorByType( - ErrorType.INVALID_NETWORK, - Networks.TESTNET, - mockUrl - ); - - expect(error?.headline).not.toBeNull(); - expect(screen.getByText(error?.headline ?? '')).toBeInTheDocument(); - }); - it.each` description | errorType ${'the node has an invalid url'} | ${ErrorType.INVALID_URL} - ${'the node is on an invalid network'} | ${ErrorType.INVALID_NETWORK} ${'the node has an ssl issue'} | ${ErrorType.SSL_ERROR} ${'the node cannot be reached'} | ${ErrorType.CONNECTION_ERROR} ${'none of the config nodes can be connected to'} | ${ErrorType.CONNECTION_ERROR_ALL} diff --git a/libs/environment/src/components/node-switcher/node-switcher.tsx b/libs/environment/src/components/node-switcher/node-switcher.tsx index d629999ce..53361318e 100644 --- a/libs/environment/src/components/node-switcher/node-switcher.tsx +++ b/libs/environment/src/components/node-switcher/node-switcher.tsx @@ -15,10 +15,9 @@ import { getIsFormDisabled, getErrorType, getErrorByType, - getHasInvalidChain, } from '../../utils/validate-node'; import { CUSTOM_NODE_KEY } from '../../types'; -import type { Configuration, NodeData, ErrorType, Networks } from '../../types'; +import type { Configuration, NodeData, ErrorType } from '../../types'; import { LayoutRow } from './layout-row'; import { NodeError } from './node-error'; import { NodeStats } from './node-stats'; @@ -34,9 +33,8 @@ const getDefaultNode = (urls: string[], currentUrl?: string) => { return currentUrl && urls.includes(currentUrl) ? currentUrl : undefined; }; -const getHighestBlock = (env: Networks, state: Record) => { +const getHighestBlock = (state: Record) => { return Object.keys(state).reduce((acc, node) => { - if (getHasInvalidChain(env, state[node].chain.value)) return acc; const value = Number(state[node].block.value); return value ? Math.max(acc, value) : acc; }, 0); @@ -56,7 +54,7 @@ export const NodeSwitcher = ({ getDefaultNode(config.hosts, VEGA_URL) ); const { state, clients, updateNodeUrl, updateNodeBlock } = useNodes(config); - const highestBlock = getHighestBlock(VEGA_ENV, state); + const highestBlock = getHighestBlock(state); const customUrl = state[CUSTOM_NODE_KEY]?.url; diff --git a/libs/environment/src/hooks/use-environment.spec.tsx b/libs/environment/src/hooks/use-environment.spec.tsx index a3de88e8c..822134a40 100644 --- a/libs/environment/src/hooks/use-environment.spec.tsx +++ b/libs/environment/src/hooks/use-environment.spec.tsx @@ -503,27 +503,6 @@ describe('node selection', () => { }); }); - it('has a network error when the selected node is not on the correct network', async () => { - act(async () => { - // @ts-ignore allow adding a mock return value to mocked module - createClient.mockImplementation(() => { - return createMockClient({ network: Networks.MAINNET }); - }); - - const { result } = renderHook(() => useEnvironment(), { - wrapper: MockWrapper, - }); - - await waitFor(() => { - expect(result.current).toEqual({ - ...mockEnvironmentState, - networkError: ErrorType.INVALID_NETWORK, - setNodeSwitcherOpen: result.current.setNodeSwitcherOpen, - }); - }); - }); - }); - it('has a network error when the selected node has not ssl available', async () => { act(async () => { // @ts-ignore allow adding a mock return value to mocked module diff --git a/libs/environment/src/types.ts b/libs/environment/src/types.ts index f8aed909c..bfcec4129 100644 --- a/libs/environment/src/types.ts +++ b/libs/environment/src/types.ts @@ -10,7 +10,6 @@ export const CUSTOM_NODE_KEY = 'custom'; export enum ErrorType { INVALID_URL, - INVALID_NETWORK, SSL_ERROR, CONNECTION_ERROR, CONNECTION_ERROR_ALL, diff --git a/libs/environment/src/utils/validate-node.tsx b/libs/environment/src/utils/validate-node.tsx index 039b6708c..09f9a43d8 100644 --- a/libs/environment/src/utils/validate-node.tsx +++ b/libs/environment/src/utils/validate-node.tsx @@ -12,10 +12,6 @@ export const getIsNodeLoading = (node?: NodeData): boolean => { ); }; -export const getHasInvalidChain = (env: Networks, chain = '') => { - return !chain.split('-').includes(env.toLowerCase()); -}; - export const getIsInvalidUrl = (url: string) => { try { new URL(url); @@ -29,7 +25,6 @@ export const getIsNodeDisabled = (env: Networks, data?: NodeData) => { return ( !!data && (getIsNodeLoading(data) || - getHasInvalidChain(env, data.chain.value) || getIsInvalidUrl(data.url) || data.chain.hasError || data.responseTime.hasError || @@ -62,11 +57,6 @@ export const getErrorByType = ( headline: t('Error: invalid url'), message: t(url ? `${url} is not a valid url.` : ''), }; - case ErrorType.INVALID_NETWORK: - return { - headline: t(`Error: incorrect network`), - message: t(`This node is not on the ${env} network.`), - }; case ErrorType.SSL_ERROR: return { headline: t(`Error: the node you are reading from does not have SSL`), @@ -122,10 +112,6 @@ export const getErrorType = (env: Networks, data?: NodeData) => { return ErrorType.CONNECTION_ERROR; } - if (!data.chain.isLoading && getHasInvalidChain(env, data.chain.value)) { - return ErrorType.INVALID_NETWORK; - } - if (data.ssl.hasError) { return ErrorType.SSL_ERROR; }