From b50ee08e8a57f07f9754d465ad7637d0475d8ba0 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 24 May 2023 13:25:52 +0200 Subject: [PATCH 1/7] chore: fixing endpoint --- src/features/Endpoint/Endpoint.tsx | 5 +++-- src/utils/constants.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/features/Endpoint/Endpoint.tsx b/src/features/Endpoint/Endpoint.tsx index 0600810b6..f1267da63 100644 --- a/src/features/Endpoint/Endpoint.tsx +++ b/src/features/Endpoint/Endpoint.tsx @@ -1,11 +1,12 @@ import React from 'react'; import { useForm } from 'react-hook-form'; import { Button, Text } from '@deriv/ui'; +import { getAppId } from '@site/src/utils'; import styles from './Endpoint.module.scss'; const default_endpoint = { - app_id: '35014', - server_url: 'green.binaryws.com', + app_id: getAppId(false), + server_url: 'oauth.deriv.com', }; interface IEndpointFormValues { diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 95a09c398..8e4ad294c 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -2,7 +2,7 @@ export const PRODUCTION_APP_ID = '36544'; export const STAGING_APP_ID = '36545'; export const VERCEL_DEPLOYMENT_APP_ID = '35073'; export const LOCALHOST_APP_ID = '35074'; -export const DEFAULT_WS_SERVER = 'green.binaryws.com'; +export const DEFAULT_WS_SERVER = 'oauth.deriv.com'; export const LOGIN_ACCOUNTS_SESSION_STORAGE_KEY = 'login-accounts'; export const CURRENT_LOGIN_ACCOUNT_SESSION_STORAGE_KEY = 'current-login-account'; From 8a8f3526d0d949aa78c01d51dd2d0904c4f2b835 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 24 May 2023 14:26:15 +0200 Subject: [PATCH 2/7] chore: fixing error --- src/features/Endpoint/Endpoint.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/features/Endpoint/Endpoint.tsx b/src/features/Endpoint/Endpoint.tsx index f1267da63..82721df85 100644 --- a/src/features/Endpoint/Endpoint.tsx +++ b/src/features/Endpoint/Endpoint.tsx @@ -4,16 +4,16 @@ import { Button, Text } from '@deriv/ui'; import { getAppId } from '@site/src/utils'; import styles from './Endpoint.module.scss'; -const default_endpoint = { - app_id: getAppId(false), - server_url: 'oauth.deriv.com', -}; - interface IEndpointFormValues { app_id: string; server_url: string; } const EndPoint = () => { + const default_endpoint = { + app_id: getAppId(false), + server_url: 'oauth.deriv.com', + }; + const { register, handleSubmit, From c7d24c3cc1767627de799c03200d038041bb69b3 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 24 May 2023 14:44:00 +0200 Subject: [PATCH 3/7] chore: fixing errors --- src/features/Apiexplorer/RequestResponseRenderer/index.tsx | 5 +++-- src/features/Endpoint/__tests__/Endpoint.test.tsx | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/features/Apiexplorer/RequestResponseRenderer/index.tsx b/src/features/Apiexplorer/RequestResponseRenderer/index.tsx index 6b1b7848c..cbb9ab755 100644 --- a/src/features/Apiexplorer/RequestResponseRenderer/index.tsx +++ b/src/features/Apiexplorer/RequestResponseRenderer/index.tsx @@ -1,4 +1,4 @@ -import React, { useState, useCallback, useEffect } from 'react'; +import React, { useState, useCallback } from 'react'; import { TSocketEndpointNames, TSocketRequestProps } from '@site/src/configs/websocket/types'; import { Button } from '@deriv/ui'; import useWS from '@site/src/hooks/useWs'; @@ -20,6 +20,7 @@ function RequestResponseRenderer({ reqData, auth, }: IResponseRendererProps) { + const AUTH_ENABLED = 1; const { is_logged_in } = useAuthContext(); const { disableSendRequest } = useDisableSendRequest(); const { full_response, is_loading, send, clear, error } = useWS(name); @@ -43,7 +44,7 @@ function RequestResponseRenderer({ }; const handleClick = useCallback(() => { - if (auth === 1) setToggleModal(true); + if (auth === AUTH_ENABLED) setToggleModal(true); clear(); send(parseRequestJSON()); setResponseState(true); diff --git a/src/features/Endpoint/__tests__/Endpoint.test.tsx b/src/features/Endpoint/__tests__/Endpoint.test.tsx index be54dbf5b..aafa9d2db 100644 --- a/src/features/Endpoint/__tests__/Endpoint.test.tsx +++ b/src/features/Endpoint/__tests__/Endpoint.test.tsx @@ -23,7 +23,7 @@ describe('Endpoint', () => { it('should have default values in input fields', () => { const server = screen.getByPlaceholderText('e.g. frontend.binaryws.com'); const app_id = screen.getByPlaceholderText('e.g. 9999'); - expect(server).toHaveValue('green.binaryws.com'); + expect(server).toHaveValue('oauth.deriv.com'); expect(app_id).toHaveValue('35014'); }); From 4915f079a763d7c49b1a59fa429632ba2af93a19 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 24 May 2023 14:53:00 +0200 Subject: [PATCH 4/7] chore: fix test --- src/features/Endpoint/__tests__/Endpoint.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/Endpoint/__tests__/Endpoint.test.tsx b/src/features/Endpoint/__tests__/Endpoint.test.tsx index aafa9d2db..d374bd651 100644 --- a/src/features/Endpoint/__tests__/Endpoint.test.tsx +++ b/src/features/Endpoint/__tests__/Endpoint.test.tsx @@ -25,7 +25,7 @@ describe('Endpoint', () => { const app_id = screen.getByPlaceholderText('e.g. 9999'); expect(server).toHaveValue('oauth.deriv.com'); - expect(app_id).toHaveValue('35014'); + expect(app_id).toHaveValue('35073'); }); it('validate user inputs, and provides error messages for app id field', async () => { From bc013ece1f2ff33e79c07c36e748f2530f80f4c3 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 24 May 2023 15:24:56 +0200 Subject: [PATCH 5/7] chore: fixing websocket url --- src/utils/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 8e4ad294c..82172af9d 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -2,7 +2,7 @@ export const PRODUCTION_APP_ID = '36544'; export const STAGING_APP_ID = '36545'; export const VERCEL_DEPLOYMENT_APP_ID = '35073'; export const LOCALHOST_APP_ID = '35074'; -export const DEFAULT_WS_SERVER = 'oauth.deriv.com'; +export const DEFAULT_WS_SERVER = 'ws.binaryws.com'; export const LOGIN_ACCOUNTS_SESSION_STORAGE_KEY = 'login-accounts'; export const CURRENT_LOGIN_ACCOUNT_SESSION_STORAGE_KEY = 'current-login-account'; From 6f241b9e0c79918f999f474c4da8296752bc76be Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 24 May 2023 15:33:48 +0200 Subject: [PATCH 6/7] chore: refactoring urls --- src/features/Endpoint/Endpoint.tsx | 3 ++- src/hooks/useLoginUrl/index.tsx | 4 ++-- src/utils/constants.ts | 1 + src/utils/index.ts | 4 ++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/features/Endpoint/Endpoint.tsx b/src/features/Endpoint/Endpoint.tsx index 82721df85..048cb11a6 100644 --- a/src/features/Endpoint/Endpoint.tsx +++ b/src/features/Endpoint/Endpoint.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { useForm } from 'react-hook-form'; import { Button, Text } from '@deriv/ui'; import { getAppId } from '@site/src/utils'; +import { OAUTH_URL } from '@site/src/utils/constants'; import styles from './Endpoint.module.scss'; interface IEndpointFormValues { @@ -11,7 +12,7 @@ interface IEndpointFormValues { const EndPoint = () => { const default_endpoint = { app_id: getAppId(false), - server_url: 'oauth.deriv.com', + server_url: OAUTH_URL, }; const { diff --git a/src/hooks/useLoginUrl/index.tsx b/src/hooks/useLoginUrl/index.tsx index d48e33ecb..63b31045b 100644 --- a/src/hooks/useLoginUrl/index.tsx +++ b/src/hooks/useLoginUrl/index.tsx @@ -3,8 +3,8 @@ import { useCallback } from 'react'; const useLoginUrl = () => { const getUrl = useCallback((language = 'en') => { - const { appId, serverUrl } = getServerConfig(); - return generateLoginUrl(language, serverUrl, appId); + const { appId, oauth } = getServerConfig(); + return generateLoginUrl(language, oauth, appId); }, []); return { getUrl }; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 82172af9d..95141c566 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -3,6 +3,7 @@ export const STAGING_APP_ID = '36545'; export const VERCEL_DEPLOYMENT_APP_ID = '35073'; export const LOCALHOST_APP_ID = '35074'; export const DEFAULT_WS_SERVER = 'ws.binaryws.com'; +export const OAUTH_URL = 'oauth.deriv.com'; export const LOGIN_ACCOUNTS_SESSION_STORAGE_KEY = 'login-accounts'; export const CURRENT_LOGIN_ACCOUNT_SESSION_STORAGE_KEY = 'current-login-account'; diff --git a/src/utils/index.ts b/src/utils/index.ts index 74a991d49..844974274 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -7,6 +7,7 @@ import { PRODUCTION_APP_ID, STAGING_APP_ID, VERCEL_DEPLOYMENT_APP_ID, + OAUTH_URL, } from './constants'; const CURRENCY_MAP = new Map([ @@ -130,18 +131,21 @@ export const getServerConfig = () => { return { serverUrl: config_server_url, appId: config_app_id, + oauth: OAUTH_URL, }; } else { const isLocalHost = isHost('localhost'); return { serverUrl: DEFAULT_WS_SERVER, appId: getAppId(isLocalHost), + oauth: OAUTH_URL, }; } } else { return { serverUrl: DEFAULT_WS_SERVER, appId: getAppId(false), + oauth: OAUTH_URL, }; } }; From 05cd34e099b61cc5c504656cd485ce5ddf2475cf Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 24 May 2023 15:51:43 +0200 Subject: [PATCH 7/7] chore: update test --- src/hooks/useLoginUrl/__tests__/useLoginUrl.test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hooks/useLoginUrl/__tests__/useLoginUrl.test.tsx b/src/hooks/useLoginUrl/__tests__/useLoginUrl.test.tsx index 09ef55890..139c45735 100644 --- a/src/hooks/useLoginUrl/__tests__/useLoginUrl.test.tsx +++ b/src/hooks/useLoginUrl/__tests__/useLoginUrl.test.tsx @@ -5,7 +5,7 @@ import * as utils from '@site/src/utils'; jest .spyOn(utils, 'getServerConfig') - .mockReturnValue({ appId: '1234', serverUrl: 'test.binary.sx' }); + .mockReturnValue({ appId: '1234', serverUrl: 'test.binary.sx', oauth: 'test.deriv.com' }); describe('Use Login URL', () => { afterEach(() => { @@ -23,7 +23,7 @@ describe('Use Login URL', () => { expect(loginUrl).toContain('l=en'); expect(utils.getServerConfig).toHaveBeenCalled(); - expect(loginUrl).toMatch(/https:\/\/test.binary.sx/); + expect(loginUrl).toMatch('https://test.deriv.com/oauth2/authorize?app_id=1234&l=en'); expect(loginUrl).toMatch(/app_id=1234/); }); @@ -37,7 +37,7 @@ describe('Use Login URL', () => { expect(loginUrl).toContain('l=es'); expect(utils.getServerConfig).toHaveBeenCalled(); - expect(loginUrl).toMatch(/https:\/\/test.binary.sx/); + expect(loginUrl).toMatch('https://test.deriv.com/oauth2/authorize?app_id=1234&l=es'); expect(loginUrl).toMatch(/app_id=1234/); }); });