Skip to content

Commit

Permalink
[WALL] george / WALL-4929 / Noticing that crypto estimation fee is no…
Browse files Browse the repository at this point in the history
…t displayed (deriv-com#16962)

* fix(wallets): 🚑 fix subscribe method

* test(api-v2): 🧪 fix test
  • Loading branch information
heorhi-deriv authored Sep 27, 2024
1 parent 3297783 commit 9168a07
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
5 changes: 1 addition & 4 deletions packages/api-v2/src/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ type AuthContextType = {
name: T,
payload?: TSocketRequestPayload<T>
) => {
subscribe: (
onData: (response: any) => void,
onError: (response: any) => void
) => Promise<{ unsubscribe: () => Promise<void> }>;
subscribe: (onData: (response: any) => void) => Promise<{ unsubscribe: () => Promise<void> }>;
};
};

Expand Down
6 changes: 1 addition & 5 deletions packages/api-v2/src/__tests__/useSubscription.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jest.mock('../AuthProvider', () => ({
return {
subscribe() {
return {
subscribe: async (onData: (response: unknown) => void, onError: (response: unknown) => void) => {
subscribe: async (onData: (response: unknown) => void) => {
const delay = (ms: number) => new Promise<never>(resolve => setTimeout(resolve, ms));
await delay(500);
onData({ p2p_order_info: { status: 'pending' } });
Expand All @@ -21,8 +21,6 @@ jest.mock('../AuthProvider', () => ({
await delay(500);
onData({ p2p_order_info: { status: 'disputed' } });
await delay(500);
onError({ error: { code: 'Foo', message: 'Error message' } });
await delay(500);
onData({ p2p_order_info: { status: 'completed' } });
return { unsubscribe: () => Promise.resolve() };
},
Expand Down Expand Up @@ -58,8 +56,6 @@ describe('useSubscription', () => {
await waitForNextUpdate();
expect(result.current.data?.p2p_order_info).toStrictEqual({ status: 'disputed' });
await waitForNextUpdate();
expect(result.current.error).toStrictEqual({ code: 'Foo', message: 'Error message' });
await waitForNextUpdate();
expect(result.current.data?.p2p_order_info).toStrictEqual({ status: 'completed' });
});
});
18 changes: 6 additions & 12 deletions packages/api-v2/src/useSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const useSubscription = <T extends TSocketSubscribableEndpointNames>(name: T, id
const [isLoading, setIsLoading] = useState(false);
const [isSubscribed, setSubscribed] = useState(false);
const [isIdle, setIdle] = useState(false);
const [error, setError] = useState<TSocketError<T>>();
const [error, setError] = useState<TSocketError<T>['error']>();
const [data, setData] = useState<TSocketResponseData<T>>();
const subscriber = useRef<{ unsubscribe?: VoidFunction }>();
const idle_timeout = useRef<NodeJS.Timeout>();
Expand All @@ -31,18 +31,12 @@ const useSubscription = <T extends TSocketSubscribableEndpointNames>(name: T, id
}, idle_time);

try {
subscriber.current = await _subscribe(name, payload).subscribe(
response => {
setData(response);
setIsLoading(false);
},
response => {
setError(response.error);
setIsLoading(false);
}
);
subscriber.current = await _subscribe(name, payload).subscribe(response => {
setData(response);
setIsLoading(false);
});
} catch (e) {
setError(e as TSocketError<T>);
setError((e as TSocketError<T>).error);
}
}, []);

Expand Down

0 comments on commit 9168a07

Please sign in to comment.