diff --git a/src/features/Apiexplorer/Dropdown/Dropdown.tsx b/src/features/Apiexplorer/Dropdown/Dropdown.tsx index 0d7377106..02af93678 100644 --- a/src/features/Apiexplorer/Dropdown/Dropdown.tsx +++ b/src/features/Apiexplorer/Dropdown/Dropdown.tsx @@ -8,7 +8,7 @@ export type TDropdown = { selected: string; setSelected: (value: string) => void; selected_value: string; - handleChange: (event: React.MouseEvent, value: string) => void; + handleChange: (value: string) => void; }; export const Dropdown = ({ selected, setSelected, handleChange, selected_value }: TDropdown) => { diff --git a/src/features/Apiexplorer/Dropdown/DropdownList/index.tsx b/src/features/Apiexplorer/Dropdown/DropdownList/index.tsx index 2edfba321..383ab3f9b 100644 --- a/src/features/Apiexplorer/Dropdown/DropdownList/index.tsx +++ b/src/features/Apiexplorer/Dropdown/DropdownList/index.tsx @@ -15,7 +15,7 @@ type TDropdownList = { selected: string; setSelected: (value: string) => void; selected_value: string; - handleChange: (event: React.MouseEvent, value: string) => void; + handleChange: (value: string) => void; searchResults: string; setIsActive: (value: boolean) => void; setSearchResults: (result: string) => void; @@ -53,6 +53,7 @@ const DropdownList: React.FC = ({ onChange={(event) => { setSearchResults(event.target.value); }} + autoFocus />
@@ -72,7 +73,7 @@ const DropdownList: React.FC = ({ onClick={(e) => { setSelected(option.title); setIsActive(false); - handleChange(e, option.name); + handleChange(option.name); }} className={clsx(styles.dropdownItem, { [styles.dropdownSelected]: selected_value === option.title, diff --git a/src/features/Apiexplorer/RequestJSONBox/index.tsx b/src/features/Apiexplorer/RequestJSONBox/index.tsx index 802fcbf4e..0c3449e34 100644 --- a/src/features/Apiexplorer/RequestJSONBox/index.tsx +++ b/src/features/Apiexplorer/RequestJSONBox/index.tsx @@ -34,7 +34,6 @@ function RequestJSONBox({ onChange={handleChange} value={request_example} rows={10} - resizable={false} /> {is_subscribe ? ( ({ reqData, auth, }: IResponseRendererProps) { + const AUTH_ENABLED = 1; const { is_logged_in, is_switching_account } = useAuthContext(); const { disableSendRequest } = useDisableSendRequest(); const { full_response, is_loading, subscribe, unsubscribe, is_subscribed, error } = @@ -67,10 +68,14 @@ function SubscribeRenderer({ }, [reqData]); const handleClick = useCallback(() => { + if (!is_logged_in && auth == AUTH_ENABLED) { + setToggleModal(true); + return; + } if (is_subscribed) unsubscribe(); subscribe(parseRequestJSON()); setResponseState(true); - }, [parseRequestJSON, subscribe]); + }, [parseRequestJSON, subscribe, auth]); const handleClear = () => { unsubscribe(); @@ -100,9 +105,7 @@ function SubscribeRenderer({ {is_not_valid && ( )} - {!is_logged_in && auth == 1 && toggle_modal && ( - - )} + {toggle_modal && } { const history = useHistory(); const { hash, pathname } = useLocation(); - useEffect(() => { + const handleTextAreaInput = useCallback( + (e) => setTextData({ ...text_data, request: e.target.value, name: hash.split('#')[1] }), + [hash, text_data], + ); + + const handleSelectChange = useCallback( + (name: string) => history.push(`${pathname}#${name}`), + [history, pathname], + ); + + const onHashChange = useCallback(() => { if (hash) { const hash_value = hash.split('#')[1]; const find_select_value = playground_requests.find((el) => el.name === hash_value); @@ -28,29 +38,10 @@ const useDynamicImportJSON = () => { }; setTextData(hash_text_data); } - }, [hash]); + }, [hash, text_data]); - const handleTextAreaInput = useCallback( - (e) => setTextData({ ...text_data, request: e.target.value, name: hash.split('#')[1] }), - [hash, text_data], - ); - - const handleSelectChange = useCallback( - (event, name) => { - event.preventDefault(); - history.push(`${pathname}#${name}`); - const request_body = playground_requests.find((el) => el.name === event.currentTarget.value); - const new_text_data = { - ...text_data, - selected_value: event.currentTarget.value, - request: JSON.stringify(request_body?.body, null, 4), - }; - setTextData({ ...new_text_data }); - }, - [history, pathname, text_data], - ); const dynamicImportJSON = useCallback( - (selected_value) => { + (selected_value: string) => { import(`../../../config/v3/${selected_value}/send.json`) .then((data) => { setRequestInfo(data); @@ -69,6 +60,10 @@ const useDynamicImportJSON = () => { [setRequestInfo, setResponseInfo], ); + useEffect(() => { + onHashChange(); + }, [hash]); + useEffect(() => { const hash_value = hash.split('#')[1]; if (hash_value) { diff --git a/src/hooks/useSubscription/__tests__/useSubscription.test.tsx b/src/hooks/useSubscription/__tests__/useSubscription.test.tsx index aab7a5a06..025382b88 100644 --- a/src/hooks/useSubscription/__tests__/useSubscription.test.tsx +++ b/src/hooks/useSubscription/__tests__/useSubscription.test.tsx @@ -49,7 +49,6 @@ describe('Use WS', () => { expect(result.current.is_subscribed).toBeTruthy(); await expect(wsServer).toReceiveMessage({ - exchange_rates: 1, base_currency: 'USD', req_id: 1, subscribe: 1, @@ -183,7 +182,6 @@ describe('Use WS', () => { expect(result.current.is_subscribed).toBeTruthy(); await expect(wsServer).toReceiveMessage({ - exchange_rates: 1, base_currency: 'USD', req_id: 1, subscribe: 1, diff --git a/src/hooks/useSubscription/index.tsx b/src/hooks/useSubscription/index.tsx index 1051a86ac..b3c68597d 100644 --- a/src/hooks/useSubscription/index.tsx +++ b/src/hooks/useSubscription/index.tsx @@ -32,23 +32,21 @@ const useSubscription = (name: T) => const subscribe = useCallback( (data: Parameters>[0]) => { - let payload = data; - if (name) { - payload = { [name]: 1, subscribe: 1, ...payload }; - } else { - payload = { subscribe: 1, ...payload }; + if (data) { + setIsLoading(true); + setSubscribed(true); + const subscriber_ref = apiManager + .augmentedSubscribe(data) + .subscribe({ next: onData, error: onError }); + setSubscriber(subscriber_ref); + return subscriber_ref; } - setIsLoading(true); - setSubscribed(true); - const subscriber_ref = apiManager.augmentedSubscribe(payload).subscribe(onData, onError); - setSubscriber(subscriber_ref); - return subscriber_ref; }, [name, onData, onError], ); const unsubscribe = useCallback(() => { - subscriber?.unsubscribe?.(); + subscriber?.unsubscribe(); setSubscribed(false); }, [subscriber]); diff --git a/src/hooks/useWs/index.tsx b/src/hooks/useWs/index.tsx index 4a2c96c54..1e0d54633 100644 --- a/src/hooks/useWs/index.tsx +++ b/src/hooks/useWs/index.tsx @@ -22,16 +22,13 @@ const useWS = (name?: T) => { async (data?: Parameters>[0]) => { let payload = data; - if (name) { - if (payload === undefined || name == 'api_token' || name == 'app_register') { - payload = { [name]: 1, ...payload }; - } + if ((!data && name) || (name == 'api_token' || name == 'app_register')) { + payload = { [name]: 1, ...payload }; } else { payload = { ...payload }; } - setIsLoading(true); - + try { const response = await apiManager.augmentedSend(payload); const key = response['msg_type'] ?? name;