Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/features/Apiexplorer/RequestResponseRenderer/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,6 +20,7 @@ function RequestResponseRenderer<T extends TSocketEndpointNames>({
reqData,
auth,
}: IResponseRendererProps<T>) {
const AUTH_ENABLED = 1;
const { is_logged_in } = useAuthContext();
const { disableSendRequest } = useDisableSendRequest();
const { full_response, is_loading, send, clear, error } = useWS<T>(name);
Expand All @@ -43,7 +44,7 @@ function RequestResponseRenderer<T extends TSocketEndpointNames>({
};

const handleClick = useCallback(() => {
if (auth === 1) setToggleModal(true);
if (auth === AUTH_ENABLED) setToggleModal(true);
clear();
send(parseRequestJSON());
setResponseState(true);
Expand Down
12 changes: 7 additions & 5 deletions src/features/Endpoint/Endpoint.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
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';

const default_endpoint = {
app_id: '35014',
server_url: 'green.binaryws.com',
};

interface IEndpointFormValues {
app_id: string;
server_url: string;
}
const EndPoint = () => {
const default_endpoint = {
app_id: getAppId(false),
server_url: OAUTH_URL,
};

const {
register,
handleSubmit,
Expand Down
4 changes: 2 additions & 2 deletions src/features/Endpoint/__tests__/Endpoint.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ 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');
expect(app_id).toHaveValue('35073');
});

it('validate user inputs, and provides error messages for app id field', async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useLoginUrl/__tests__/useLoginUrl.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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/);
});

Expand All @@ -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/);
});
});
4 changes: 2 additions & 2 deletions src/hooks/useLoginUrl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
3 changes: 2 additions & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ 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 = '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';
Expand Down
4 changes: 4 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
PRODUCTION_APP_ID,
STAGING_APP_ID,
VERCEL_DEPLOYMENT_APP_ID,
OAUTH_URL,
} from './constants';

const CURRENCY_MAP = new Map([
Expand Down Expand Up @@ -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,
};
}
};
Expand Down