Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit ab72b64

Browse files
authored
Merge pull request #157 from hubert-deriv/HOTFIX_playground_submit_error
Hubert / fixing error playground
2 parents e89c6e5 + 6439036 commit ab72b64

File tree

9 files changed

+29
-20
lines changed

9 files changed

+29
-20
lines changed

src/features/Apiexplorer/RequestResponseRenderer/PlaygroundSection/JsonData/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const JsonData = <T extends TSocketEndpointNames | TSocketSubscribableEndpointNa
2020
}: TJsonData<T>) => {
2121
return (
2222
<React.Fragment>
23-
{full_response !== null ? (
23+
{full_response !== null && full_response?.echo_req ? (
2424
<div className={styles.reactJsonContainer}>
2525
<ReactJson src={full_response.echo_req} theme='tube' />
2626
<ReactJson src={full_response} theme='tube' />

src/features/Apiexplorer/RequestResponseRenderer/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function RequestResponseRenderer<T extends TSocketEndpointNames>({
2525
const { full_response, is_loading, send, clear, error } = useWS<T>(name);
2626
const [toggle_modal, setToggleModal] = useState(false);
2727
const [response_state, setResponseState] = useState(false);
28-
const [is_valid, setIsValid] = useState(false);
28+
const [is_not_valid, setIsNotValid] = useState(false);
2929

3030
const parseRequestJSON = () => {
3131
let request_data: TSocketRequestProps<T> extends never ? undefined : TSocketRequestProps<T>;
@@ -35,7 +35,7 @@ function RequestResponseRenderer<T extends TSocketEndpointNames>({
3535
} catch (error) {
3636
console.error('Could not parse the JSON data while trying to send the request: ', error);
3737
console.log(error);
38-
setIsValid(true);
38+
setIsNotValid(true);
3939
setToggleModal(false);
4040
}
4141

@@ -65,7 +65,7 @@ function RequestResponseRenderer<T extends TSocketEndpointNames>({
6565
Clear
6666
</Button>
6767
</div>
68-
{!is_valid ? (
68+
{!is_not_valid ? (
6969
!is_logged_in && toggle_modal ? (
7070
<LoginDialog setToggleModal={setToggleModal} />
7171
) : (
@@ -78,7 +78,7 @@ function RequestResponseRenderer<T extends TSocketEndpointNames>({
7878
/>
7979
)
8080
) : (
81-
<ValidDialog setIsValid={setIsValid} setToggleModal={setToggleModal} />
81+
<ValidDialog setIsNotValid={setIsNotValid} setToggleModal={setToggleModal} />
8282
)}
8383
</div>
8484
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const mockUnsubscribe = jest.fn();
5454
mockUseSubscription.mockImplementation(() => ({
5555
subscribe: mockSubscribe,
5656
unsubscribe: mockUnsubscribe,
57-
error: '',
57+
error: { code: '' },
5858
full_response: {
5959
tick: 1,
6060
echo_req: { tick: 1 },

src/features/Apiexplorer/SubscribeRenderer/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ function SubscribeRenderer<T extends TSocketSubscribableEndpointNames>({
2828
const { full_response, is_loading, subscribe, unsubscribe, error } = useSubscription<T>(name);
2929
const [response_state, setResponseState] = useState(false);
3030
const [toggle_modal, setToggleModal] = useState(false);
31-
const [is_valid, setIsValid] = useState(false);
31+
const [is_not_valid, setIsNotValid] = useState(false);
32+
33+
useEffect(() => {
34+
if (error && error.code === 'AuthorizationRequired') {
35+
setToggleModal(true);
36+
}
37+
}, [error]);
3238

3339
const parseRequestJSON = () => {
3440
let request_data: TSocketRequestProps<T> extends never ? undefined : TSocketRequestProps<T>;
@@ -37,8 +43,7 @@ function SubscribeRenderer<T extends TSocketSubscribableEndpointNames>({
3743
request_data = JSON.parse(reqData);
3844
} catch (error) {
3945
console.error('Could not parse the JSON data while trying to send the request: ', error);
40-
console.log(error);
41-
setIsValid(true);
46+
setIsNotValid(true);
4247
setToggleModal(false);
4348
}
4449

@@ -66,8 +71,8 @@ function SubscribeRenderer<T extends TSocketSubscribableEndpointNames>({
6671
Clear
6772
</Button>
6873
</div>
69-
{is_valid ? (
70-
<ValidDialog setIsValid={setIsValid} setToggleModal={setToggleModal} />
74+
{is_not_valid ? (
75+
<ValidDialog setIsNotValid={setIsNotValid} setToggleModal={setToggleModal} />
7176
) : !is_logged_in && auth == 1 && toggle_modal ? (
7277
<LoginDialog setToggleModal={setToggleModal} />
7378
) : (

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('ValidDialog', () => {
66
test('if correct test is rendered', () => {
77
location.assign = jest.fn();
88

9-
render(<ValidDialog setIsValid={jest.fn()} setToggleModal={jest.fn()} />);
9+
render(<ValidDialog setIsNotValid={jest.fn()} setToggleModal={jest.fn()} />);
1010
const text = screen.getByText(
1111
'Your JSON object is invalid. Please make sure you provide the correct syntax for your JSON object.',
1212
);

src/features/Apiexplorer/ValidDialog/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { Modal } from '@deriv/ui';
33
import styles from '../LoginDialog/LoginDialog.module.scss';
44

55
type TValidDialog = {
6-
setIsValid: React.Dispatch<React.SetStateAction<boolean>>;
6+
setIsNotValid: React.Dispatch<React.SetStateAction<boolean>>;
77
setToggleModal: React.Dispatch<React.SetStateAction<boolean>>;
88
};
99

10-
export const ValidDialog = ({ setIsValid, setToggleModal }: TValidDialog) => {
10+
export const ValidDialog = ({ setIsNotValid, setToggleModal }: TValidDialog) => {
1111
const onOpenChange = useCallback(
1212
(open: boolean) => {
1313
if (!open) {
14-
setIsValid(false);
14+
setIsNotValid(false);
1515
setToggleModal(false);
1616
}
1717
},
18-
[setIsValid, setToggleModal],
18+
[setIsNotValid, setToggleModal],
1919
);
2020
return (
2121
<Modal defaultOpen onOpenChange={onOpenChange}>

src/features/Apiexplorer/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export default function ApiExplorerFeatures() {
1717
response_info,
1818
handleTextAreaInput,
1919
} = useDynamicImportJSON();
20-
2120
const has_info = Object.keys(request_info).length === 0;
2221
return (
2322
<div className={styles.playgroundContent}>

src/hooks/useDynamicImportJSON/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ const useDynamicImportJSON = () => {
5656
})
5757
.catch((error) => {
5858
// eslint-disable-next-line
59-
console.log(error);
59+
console.error(error);
6060
});
6161
import(`../../../config/v3/${selected_value}/receive.json`)
6262
.then((data) => {
6363
setResponseInfo(data);
6464
})
6565
.catch((error) => {
6666
// eslint-disable-next-line
67-
console.log(error);
67+
console.error(error);
6868
});
6969
},
7070
[setRequestInfo, setResponseInfo],

src/hooks/useSubscription/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ import {
66
} from '@site/src/configs/websocket/types';
77
import { useCallback, useState } from 'react';
88

9+
type TError = {
10+
code?: string;
11+
message?: string;
12+
};
13+
914
const useSubscription = <T extends TSocketSubscribableEndpointNames>(name: T) => {
1015
const [is_loading, setIsLoading] = useState(false);
1116
const [is_subscribed, setSubscribed] = useState(false);
12-
const [error, setError] = useState<unknown>();
17+
const [error, setError] = useState<TError>();
1318
const [data, setData] = useState<TSocketResponseData<T>>();
1419
const [full_response, setFullResponse] = useState<TSocketResponse<T>>();
1520
const [subscriber, setSubscriber] = useState<{ unsubscribe?: VoidFunction }>();

0 commit comments

Comments
 (0)