Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.
Closed
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

.idea
.idea

.vscode/settings.json
17,087 changes: 9,739 additions & 7,348 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
"yup": "^0.32.11"
},
"devDependencies": {
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/preset-env": "^7.24.3",
"@babel/preset-react": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@deriv/api-types": "^1.0.80",
"@deriv/api-types": "^1.0.172",
"@docusaurus/module-type-aliases": "^2.4.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
Expand Down
16 changes: 11 additions & 5 deletions src/configs/websocket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export class ApiManager {
}

private registerKeepAlive() {
if (this.pingInterval) {
if (this.pingInterval && typeof this.pingInterval === 'number') {
clearInterval(this.pingInterval);
}
if (this.reconnectInterval) {
if (this.reconnectInterval && typeof this.reconnectInterval === 'number') {
clearInterval(this.reconnectInterval);
}
this.socket.addEventListener('open', () => {
Expand All @@ -82,7 +82,9 @@ export class ApiManager {
this.socket.addEventListener('close', () => {
this.is_websocket_connected?.(false);
this.is_websocket_authorized?.(false);
clearInterval(this.pingInterval);
if (this.pingInterval && typeof this.pingInterval === 'number') {
clearInterval(this.pingInterval);
}
this.socket = null;
if (attempts > 0) {
this.reconnectInterval = setTimeout(this.init.bind(this), RECONNECT_INTERVAL);
Expand All @@ -91,12 +93,16 @@ export class ApiManager {
window.alert(
'Sorry, the server is currently down. Please refresh the page or try again later',
);
clearInterval(this.reconnectInterval);
if (this.reconnectInterval && typeof this.reconnectInterval === 'number') {
clearInterval(this.reconnectInterval);
}
}
});

this.socket.addEventListener('error', () => {
clearInterval(this.pingInterval);
if (this.pingInterval && typeof this.pingInterval === 'number') {
clearInterval(this.pingInterval);
}
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/features/Endpoint/Endpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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 { DEFAULT_WS_SERVER } from '@site/src/utils/constants';
import styles from './Endpoint.module.scss';

interface IEndpointFormValues {
Expand All @@ -12,7 +12,7 @@ interface IEndpointFormValues {
const EndPoint = () => {
const default_endpoint = {
app_id: getAppId(),
server_url: OAUTH_URL,
server_url: DEFAULT_WS_SERVER,
};

const {
Expand Down
3 changes: 2 additions & 1 deletion src/features/Endpoint/__tests__/Endpoint.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
import React from 'react';
import EndPoint from '../Endpoint';
import userEvent from '@testing-library/user-event';
import { DEFAULT_WS_SERVER } from '@site/src/utils/constants';

describe('Endpoint', () => {
beforeEach(() => {
Expand All @@ -23,7 +24,7 @@ describe('Endpoint', () => {
it('should have default values in input fields', () => {
const server = screen.getByPlaceholderText('e.g. ws.derivws.com');
const app_id = screen.getByPlaceholderText('e.g. 9999');
expect(server).toHaveValue('oauth.deriv.com');
expect(server).toHaveValue(DEFAULT_WS_SERVER);

expect(app_id).toHaveValue('35074');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('App Form', () => {
scopes: ['read', 'trade', 'trading_information'],
verification_uri: 'https://example.com',
last_used: '',
official: 0,
},
{
active: 1,
Expand All @@ -71,6 +72,7 @@ describe('App Form', () => {
scopes: ['read', 'trade'],
verification_uri: 'https://example.com',
last_used: '',
official: 0,
},
];
const mockGetApps = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const fakeApplications: ApplicationObject[] = [
scopes: ['admin', 'payments', 'read', 'trade', 'trading_information'],
verification_uri: 'https://example.com',
last_used: '',
official: 0,
},
{
active: 1,
Expand All @@ -48,6 +49,7 @@ const fakeApplications: ApplicationObject[] = [
scopes: ['payments', 'read', 'trade', 'trading_information'],
verification_uri: 'https://example.com',
last_used: '',
official: 0,
},
];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { CellProps } from 'react-table';
import { TAppColumn } from '.';
import styles from './cells.module.scss';
import { ApplicationObject } from '@deriv/api-types';

interface IAppActionsCellProps extends React.PropsWithChildren<CellProps<TAppColumn, string>> {
interface IAppActionsCellProps extends CellProps<ApplicationObject> {
openDeleteDialog: () => void;
openEditDialog: () => void;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const fakeApp: ApplicationObject = {
scopes: ['read', 'trade', 'trading_information'],
verification_uri: 'https://example.com',
last_used: '',
official: 0,
};

describe('Update App Dialog', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import useAppManager from '@site/src/hooks/useAppManager';
import { render, screen, cleanup } from '@site/src/test-utils';
import React from 'react';
import AppManagement from '..';
import LoadingTable from '../../components/LoadingTable';

jest.mock('@site/src/hooks/useAppManager');

Expand Down Expand Up @@ -53,6 +52,7 @@ describe('App Management', () => {
scopes: ['admin', 'payments', 'read', 'trade', 'trading_information'],
verification_uri: 'https://example.com',
last_used: '',
official: 0,
},
{
active: 1,
Expand All @@ -67,6 +67,7 @@ describe('App Management', () => {
scopes: ['payments', 'read', 'trade', 'trading_information'],
verification_uri: 'https://example.com',
last_used: '',
official: 0,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,6 @@ mockUseAppManager.mockImplementation(() => ({
getApps: mockGetApps,
}));

const fakeApp: ApplicationObject = {
active: 1,
app_id: 12345,
app_markup_percentage: 0,
appstore: '',
github: '',
googleplay: '',
homepage: '',
name: 'testApp',
redirect_uri: 'https://example.com',
scopes: ['read', 'trade', 'trading_information'],
verification_uri: 'https://example.com',
last_used: '',
};

describe('Update App Dialog', () => {
let wsServer: WS;

Expand Down
4 changes: 3 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ export const getServerConfig = () => {
if (isBrowser) {
const config_server_url = localStorage.getItem('config.server_url');
const config_app_id = localStorage.getItem('config.app_id');
const is_qa_server = config_server_url?.toLowerCase().includes('qa');
const oauth = is_qa_server ? config_server_url : OAUTH_URL;

return {
serverUrl: config_server_url ?? DEFAULT_WS_SERVER,
appId: config_app_id ?? getAppId(),
oauth: config_server_url ?? OAUTH_URL,
oauth,
};
} else {
return {
Expand Down