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

Commit c394743

Browse files
Merge pull request #276 from utkarsha-deriv/utkarsha/subscribe-rerender-issue/DERA-496
2 parents 96a8512 + c9ac0cd commit c394743

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/features/Apiexplorer/SubscribeRenderer/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ function SubscribeRenderer<T extends TSocketSubscribableEndpointNames>({
3232
const [is_not_valid, setIsNotValid] = useState(false);
3333

3434
useEffect(() => {
35-
if (error && error.code === 'AuthorizationRequired') {
35+
if (
36+
error &&
37+
typeof error === 'object' &&
38+
'code' in error &&
39+
error.code === 'AuthorizationRequired'
40+
) {
3641
setToggleModal(true);
3742
}
3843
}, [error]);

src/hooks/useSubscription/__tests__/useSubscription.test.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,22 @@ describe('Use WS', () => {
206206
},
207207
});
208208

209-
expect(result.current.error).toEqual({ message: 'this is an error' });
209+
expect(result.current.error).toEqual({
210+
echo_req: {
211+
base_currency: 'USD',
212+
exchange_rates: 1,
213+
req_id: 1,
214+
subscribe: 1,
215+
},
216+
error: {
217+
message: 'this is an error',
218+
},
219+
msg_type: 'exchange_rates',
220+
req_id: 1,
221+
subscription: {
222+
id: '2f39f7e7-d986-33f2-080a-b0ee50cfb85c',
223+
},
224+
});
210225
expect(result.current.is_loading).toBeFalsy();
211226
});
212227
});

src/hooks/useSubscription/index.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ 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-
149
const useSubscription = <T extends TSocketSubscribableEndpointNames>(name: T) => {
1510
const [is_loading, setIsLoading] = useState(false);
1611
const [is_subscribed, setSubscribed] = useState(false);
17-
const [error, setError] = useState<TError>();
12+
const [error, setError] = useState<unknown>();
1813
const [data, setData] = useState<TSocketResponseData<T>>();
1914
const [full_response, setFullResponse] = useState<TSocketResponse<T>>();
2015
const [subscriber, setSubscriber] = useState<{ unsubscribe?: VoidFunction }>();
@@ -30,7 +25,7 @@ const useSubscription = <T extends TSocketSubscribableEndpointNames>(name: T) =>
3025
);
3126

3227
const onError = useCallback((response: TSocketResponse<T>) => {
33-
setError(response.error);
28+
setError(response);
3429
setIsLoading(false);
3530
setFullResponse(null);
3631
}, []);

0 commit comments

Comments
 (0)