Skip to content

Commit 6221b89

Browse files
Merge pull request #189 from ahmed-deriv/ahmed/DAPI-841/chore--fix-custom-endpoint-specific-scenarios
ahmed/DAPI-841/chore--fix-custom-endpoint-specific-scenarios
2 parents 9aa52f4 + 2f810ab commit 6221b89

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

src/features/Apiexplorer/RequestJSONBox/__tests__/RequestJsonBox.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const fakeHookObject = {
1919
tick: 1,
2020
echo_req: { tick: 1 },
2121
},
22+
disableApiNameOnRequest: jest.fn(),
2223
};
2324

2425
jest.mock('@site/src/hooks/useAuthContext');

src/features/Apiexplorer/RequestResponseRenderer/__test__/RequestResponseRenderer.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ mockUseWS.mockImplementation(() => ({
4848
ping: 'pong',
4949
req_id: 1,
5050
},
51+
disableApiNameOnRequest: jest.fn(),
5152
}));
5253

5354
describe('RequestResponseRenderer', () => {

src/features/Apiexplorer/RequestResponseRenderer/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useCallback } from 'react';
1+
import React, { useState, useCallback, useEffect } from 'react';
22
import { TSocketEndpointNames, TSocketRequestProps } from '@site/src/configs/websocket/types';
33
import useWS from '@site/src/hooks/useWs';
44
import useAuthContext from '@site/src/hooks/useAuthContext';
@@ -24,11 +24,15 @@ function RequestResponseRenderer<T extends TSocketEndpointNames>({
2424
const AUTH_ENABLED = 1;
2525
const { is_logged_in } = useAuthContext();
2626
const { disableSendRequest } = useDisableSendRequest();
27-
const { full_response, is_loading, send, clear, error } = useWS<T>(name);
27+
const { full_response, is_loading, send, clear, error, disableApiNameOnRequest } = useWS<T>(name);
2828
const [toggle_modal, setToggleModal] = useState(false);
2929
const [response_state, setResponseState] = useState(false);
3030
const [is_not_valid, setIsNotValid] = useState(false);
3131

32+
useEffect(() => {
33+
disableApiNameOnRequest();
34+
}, []);
35+
3236
const parseRequestJSON = () => {
3337
let request_data: TSocketRequestProps<T> extends never ? undefined : TSocketRequestProps<T>;
3438

src/features/Apiexplorer/__tests__/ApiExplorer.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ mockuseWS.mockImplementation(() => ({
5858
tick: 1,
5959
echo_req: { tick: 1 },
6060
},
61+
disableApiNameOnRequest: jest.fn(),
6162
}));
6263

6364
jest.mock('@site/src/hooks/useDynamicImportJSON');

src/hooks/useWs/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,32 @@ const useWS = <T extends TSocketEndpointNames>(name?: T) => {
1111
const [error, setError] = useState<unknown>();
1212
const [data, setData] = useState<TSocketResponseData<T>>();
1313
const [full_response, setFullResponse] = useState<TSocketResponse<T>>();
14+
const [isUseName, setIsUseName] = useState(true);
1415

1516
const clear = useCallback(() => {
1617
setError(null);
1718
setData(null);
1819
setFullResponse(null);
1920
}, []);
2021

22+
// This function is used to disable the API name on request from playground.
23+
const disableApiNameOnRequest = useCallback(() => {
24+
setIsUseName(false);
25+
}, []);
26+
2127
const send = useCallback(
2228
async (data?: Parameters<typeof apiManager.augmentedSend<T>>[0]) => {
2329
let payload = data;
2430

25-
if ((!data && name) || (name == 'api_token' || name == 'app_register')) {
31+
const isAllowName = isUseName && (name == 'api_token' || name == 'app_register');
32+
33+
if ((!data && name) || isAllowName) {
2634
payload = { [name]: 1, ...payload };
2735
} else {
2836
payload = { ...payload };
2937
}
3038
setIsLoading(true);
31-
39+
3240
try {
3341
const response = await apiManager.augmentedSend(payload);
3442
const key = response['msg_type'] ?? name;
@@ -43,7 +51,7 @@ const useWS = <T extends TSocketEndpointNames>(name?: T) => {
4351
[name],
4452
);
4553

46-
return { send, full_response, is_loading, error, data, clear };
54+
return { send, full_response, is_loading, error, data, clear, disableApiNameOnRequest };
4755
};
4856

4957
export default useWS;

0 commit comments

Comments
 (0)