fix: env ssl to subscription (#2440)
* fix: rename ssl environment check to subscription * fix: format
This commit is contained in:
parent
28fe7458ca
commit
2217925285
@ -40,11 +40,13 @@ const getBlockDisplayValue = (
|
||||
return '-';
|
||||
};
|
||||
|
||||
const getSslDisplayValue = (ssl?: NodeData['ssl']) => {
|
||||
if (ssl?.value) {
|
||||
const getSubscriptionDisplayValue = (
|
||||
subscription?: NodeData['subscription']
|
||||
) => {
|
||||
if (subscription?.value) {
|
||||
return t('Yes');
|
||||
}
|
||||
if (ssl?.hasError) {
|
||||
if (subscription?.hasError) {
|
||||
return t('No');
|
||||
}
|
||||
return '-';
|
||||
@ -81,12 +83,12 @@ const NodeStatsContent = ({
|
||||
{getBlockDisplayValue(data.block, setBlock)}
|
||||
</LayoutCell>
|
||||
<LayoutCell
|
||||
label={t('SSL')}
|
||||
isLoading={data.ssl?.isLoading}
|
||||
hasError={data.ssl?.hasError}
|
||||
dataTestId="ssl-cell"
|
||||
label={t('Subscription')}
|
||||
isLoading={data.subscription?.isLoading}
|
||||
hasError={data.subscription?.hasError}
|
||||
dataTestId="subscription-cell"
|
||||
>
|
||||
{getSslDisplayValue(data.ssl)}
|
||||
{getSubscriptionDisplayValue(data.subscription)}
|
||||
</LayoutCell>
|
||||
</LayoutRow>
|
||||
);
|
||||
|
@ -10,7 +10,7 @@ import { getErrorByType } from '../../utils/validate-node';
|
||||
import type { Configuration, NodeData } from '../../types';
|
||||
import { Networks, ErrorType, CUSTOM_NODE_KEY } from '../../types';
|
||||
|
||||
type NodeDataProp = 'responseTime' | 'block' | 'chain' | 'ssl';
|
||||
type NodeDataProp = 'responseTime' | 'block' | 'chain' | 'subscription';
|
||||
|
||||
jest.mock('../../hooks/use-environment');
|
||||
jest.mock('../../hooks/use-nodes');
|
||||
@ -99,7 +99,7 @@ const getValidNodeState = (env: Networks, url: string) => ({
|
||||
hasError: false,
|
||||
value: 123,
|
||||
},
|
||||
ssl: {
|
||||
subscription: {
|
||||
isLoading: false,
|
||||
hasError: false,
|
||||
value: true,
|
||||
@ -203,8 +203,8 @@ describe('Node switcher', () => {
|
||||
${'block'} | ${STATES.HAS_ERROR}
|
||||
${'chain'} | ${STATES.LOADING}
|
||||
${'chain'} | ${STATES.HAS_ERROR}
|
||||
${'ssl'} | ${STATES.LOADING}
|
||||
${'ssl'} | ${STATES.HAS_ERROR}
|
||||
${'subscription'} | ${STATES.LOADING}
|
||||
${'subscription'} | ${STATES.HAS_ERROR}
|
||||
`(
|
||||
'disables selecting a node when the $dataProp $state',
|
||||
({ dataProp, state }: { dataProp: NodeDataProp; state: STATES }) => {
|
||||
@ -409,8 +409,8 @@ describe('Node switcher', () => {
|
||||
${'block'} | ${STATES.HAS_ERROR}
|
||||
${'chain'} | ${STATES.LOADING}
|
||||
${'chain'} | ${STATES.HAS_ERROR}
|
||||
${'ssl'} | ${STATES.LOADING}
|
||||
${'ssl'} | ${STATES.HAS_ERROR}
|
||||
${'subscription'} | ${STATES.LOADING}
|
||||
${'subscription'} | ${STATES.HAS_ERROR}
|
||||
`(
|
||||
'disables selecting a custom node when the $dataProp $state',
|
||||
({ dataProp, state }: { dataProp: NodeDataProp; state: STATES }) => {
|
||||
@ -494,7 +494,9 @@ describe('Node switcher', () => {
|
||||
|
||||
if (state === STATES.HAS_ERROR) {
|
||||
const expectedErrorType =
|
||||
dataProp === 'ssl' ? ErrorType.SSL_ERROR : ErrorType.CONNECTION_ERROR;
|
||||
dataProp === 'subscription'
|
||||
? ErrorType.SUBSCRIPTION_ERROR
|
||||
: ErrorType.CONNECTION_ERROR;
|
||||
const error = getErrorByType(
|
||||
expectedErrorType,
|
||||
Networks.TESTNET,
|
||||
@ -547,7 +549,7 @@ describe('Node switcher', () => {
|
||||
it.each`
|
||||
description | errorType
|
||||
${'the node has an invalid url'} | ${ErrorType.INVALID_URL}
|
||||
${'the node has an ssl issue'} | ${ErrorType.SSL_ERROR}
|
||||
${'the node has a subscription issue'} | ${ErrorType.SUBSCRIPTION_ERROR}
|
||||
${'the node cannot be reached'} | ${ErrorType.CONNECTION_ERROR}
|
||||
${'none of the config nodes can be connected to'} | ${ErrorType.CONNECTION_ERROR_ALL}
|
||||
${'the config cannot be loaded'} | ${ErrorType.CONFIG_LOAD_ERROR}
|
||||
|
@ -97,7 +97,7 @@ export const NodeSwitcher = ({
|
||||
<div />
|
||||
<span className="text-right">{t('Response time')}</span>
|
||||
<span className="text-right">{t('Block')}</span>
|
||||
<span className="text-right">{t('SSL')}</span>
|
||||
<span className="text-right">{t('Subscription')}</span>
|
||||
</LayoutRow>
|
||||
</div>
|
||||
<RadioGroup
|
||||
|
@ -503,7 +503,7 @@ describe('node selection', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('has a network error when the selected node has not ssl available', async () => {
|
||||
it('has a network error when the selected node has not subscription available', async () => {
|
||||
act(async () => {
|
||||
// @ts-ignore allow adding a mock return value to mocked module
|
||||
createClient.mockImplementation(() => {
|
||||
@ -517,7 +517,7 @@ describe('node selection', () => {
|
||||
await waitFor(() => {
|
||||
expect(result.current).toEqual({
|
||||
...mockEnvironmentState,
|
||||
networkError: ErrorType.SSL_ERROR,
|
||||
networkError: ErrorType.SUBSCRIPTION_ERROR,
|
||||
setNodeSwitcherOpen: result.current.setNodeSwitcherOpen,
|
||||
});
|
||||
});
|
||||
|
@ -24,7 +24,7 @@ const initialState = {
|
||||
hasError: false,
|
||||
value: undefined,
|
||||
},
|
||||
ssl: {
|
||||
subscription: {
|
||||
isLoading: false,
|
||||
hasError: false,
|
||||
value: undefined,
|
||||
@ -84,8 +84,8 @@ describe('useNodes hook', () => {
|
||||
...initialState.chain,
|
||||
isLoading: true,
|
||||
},
|
||||
ssl: {
|
||||
...initialState.ssl,
|
||||
subscription: {
|
||||
...initialState.subscription,
|
||||
isLoading: true,
|
||||
},
|
||||
});
|
||||
@ -122,7 +122,7 @@ describe('useNodes hook', () => {
|
||||
const { result } = renderHook(() => useNodes({ hosts: [node] }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.state[node].ssl).toEqual({
|
||||
expect(result.current.state[node].subscription).toEqual({
|
||||
isLoading: false,
|
||||
hasError: false,
|
||||
value: true,
|
||||
@ -182,7 +182,7 @@ describe('useNodes hook', () => {
|
||||
const { result } = renderHook(() => useNodes({ hosts: [node] }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.state[node].ssl).toEqual({
|
||||
expect(result.current.state[node].subscription).toEqual({
|
||||
isLoading: false,
|
||||
hasError: true,
|
||||
value: undefined,
|
||||
@ -273,7 +273,7 @@ describe('useNodes hook', () => {
|
||||
expect(result.current.state[node].block.hasError).toBe(true);
|
||||
expect(result.current.state[node].chain.hasError).toBe(true);
|
||||
expect(result.current.state[node].responseTime.hasError).toBe(true);
|
||||
expect(result.current.state[node].ssl.hasError).toBe(true);
|
||||
expect(result.current.state[node].subscription.hasError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@ -331,7 +331,7 @@ describe('useNodes hook', () => {
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.state[node].ssl).toEqual({
|
||||
expect(result.current.state[node].subscription).toEqual({
|
||||
isLoading: false,
|
||||
hasError: true,
|
||||
value: undefined,
|
||||
|
@ -61,7 +61,7 @@ const getNodeData = (url?: string): NodeData => ({
|
||||
initialized: false,
|
||||
responseTime: withData(),
|
||||
block: withData(),
|
||||
ssl: withData(),
|
||||
subscription: withData(),
|
||||
chain: withData(),
|
||||
});
|
||||
|
||||
@ -141,18 +141,18 @@ const reducer = (state: Record<string, NodeData>, action: Action) => {
|
||||
state[action.node] = getNodeData(action.payload?.url);
|
||||
}
|
||||
state[action.node].url = action.payload?.url ?? '';
|
||||
state[action.node].ssl.isLoading = true;
|
||||
state[action.node].subscription.isLoading = true;
|
||||
state[action.node].initialized = true;
|
||||
});
|
||||
case ACTIONS.CHECK_SUBSCRIPTION_SUCCESS:
|
||||
return produce(state, (state) => {
|
||||
if (!state[action.node]) return;
|
||||
state[action.node].ssl = withData(true);
|
||||
state[action.node].subscription = withData(true);
|
||||
});
|
||||
case ACTIONS.CHECK_SUBSCRIPTION_FAILURE:
|
||||
return produce(state, (state) => {
|
||||
if (!state[action.node]) return;
|
||||
state[action.node].ssl = withError();
|
||||
state[action.node].subscription = withError();
|
||||
});
|
||||
case ACTIONS.ADD_NODE:
|
||||
return produce(state, (state) => {
|
||||
|
@ -10,7 +10,7 @@ export const CUSTOM_NODE_KEY = 'custom';
|
||||
|
||||
export enum ErrorType {
|
||||
INVALID_URL,
|
||||
SSL_ERROR,
|
||||
SUBSCRIPTION_ERROR,
|
||||
CONNECTION_ERROR,
|
||||
CONNECTION_ERROR_ALL,
|
||||
CONFIG_LOAD_ERROR,
|
||||
@ -37,7 +37,7 @@ type NodeCheck<T> = {
|
||||
export type NodeData = {
|
||||
url: string;
|
||||
initialized: boolean;
|
||||
ssl: NodeCheck<boolean>;
|
||||
subscription: NodeCheck<boolean>;
|
||||
block: NodeCheck<number>;
|
||||
responseTime: NodeCheck<number>;
|
||||
chain: NodeCheck<string>;
|
||||
|
@ -8,7 +8,7 @@ export const getIsNodeLoading = (node?: NodeData): boolean => {
|
||||
node.chain.isLoading ||
|
||||
node.responseTime.isLoading ||
|
||||
node.block.isLoading ||
|
||||
node.ssl.isLoading
|
||||
node.subscription.isLoading
|
||||
);
|
||||
};
|
||||
|
||||
@ -29,7 +29,7 @@ export const getIsNodeDisabled = (env: Networks, data?: NodeData) => {
|
||||
data.chain.hasError ||
|
||||
data.responseTime.hasError ||
|
||||
data.block.hasError ||
|
||||
data.ssl.hasError)
|
||||
data.subscription.hasError)
|
||||
);
|
||||
};
|
||||
|
||||
@ -57,12 +57,12 @@ export const getErrorByType = (
|
||||
headline: t('Error: invalid url'),
|
||||
message: t(url ? `${url} is not a valid url.` : ''),
|
||||
};
|
||||
case ErrorType.SSL_ERROR:
|
||||
case ErrorType.SUBSCRIPTION_ERROR:
|
||||
return {
|
||||
headline: t(`Error: the node you are reading from does not have SSL`),
|
||||
headline: t(`Error: the node you are reading from does not emit data`),
|
||||
message: t(
|
||||
url
|
||||
? `${url} does not have SSL. SSL is required to subscribe to data.`
|
||||
? `${url} is required to have subscriptions working to enable data updates on the page.`
|
||||
: ''
|
||||
),
|
||||
};
|
||||
@ -112,8 +112,8 @@ export const getErrorType = (env: Networks, data?: NodeData) => {
|
||||
return ErrorType.CONNECTION_ERROR;
|
||||
}
|
||||
|
||||
if (data.ssl.hasError) {
|
||||
return ErrorType.SSL_ERROR;
|
||||
if (data.subscription.hasError) {
|
||||
return ErrorType.SUBSCRIPTION_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user