Skip to content

Commit

Permalink
Merge pull request #233 from maryia-matskevich-deriv/maryia/BOT-2669
Browse files Browse the repository at this point in the history
maryia/BOT-2669/fix: Remove quotation mark "" shown on server from local storage
  • Loading branch information
farabi-deriv authored Jan 20, 2025
2 parents e2346ab + 7dada5b commit 5288c00
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
11 changes: 6 additions & 5 deletions src/components/shared/utils/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocalStorageConstants, LocalStorageUtils, URLUtils } from '@deriv-com/utils';
import { LocalStorageConstants, URLUtils } from '@deriv-com/utils';
import { isStaging } from '../url/helpers';

export const APP_IDS = {
Expand Down Expand Up @@ -118,7 +118,7 @@ export const checkAndSetEndpointFromUrl = () => {

if (/^(^(www\.)?qa[0-9]{1,4}\.deriv.dev|(.*)\.derivws\.com)$/.test(qa_server) && /^[0-9]+$/.test(app_id)) {
localStorage.setItem('config.app_id', app_id);
localStorage.setItem('config.server_url', qa_server);
localStorage.setItem('config.server_url', qa_server.replace(/"/g, ''));
}

const params = url_params.toString();
Expand Down Expand Up @@ -146,11 +146,12 @@ export const generateOAuthURL = () => {
const { getOauthURL } = URLUtils;
const oauth_url = getOauthURL();
const original_url = new URL(oauth_url);
const configured_server_url = (LocalStorageUtils.getValue(LocalStorageConstants.configServerURL) ||
original_url.hostname) as string;
const configured_server_url = localStorage.getItem(
LocalStorageConstants.configServerURL || original_url.hostname
) as string;

const valid_server_urls = ['green.derivws.com', 'red.derivws.com', 'blue.derivws.com'];
if (!valid_server_urls.includes(configured_server_url)) {
if (!valid_server_urls.includes(JSON.stringify(configured_server_url))) {
original_url.hostname = configured_server_url;
}
return original_url.toString() || oauth_url;
Expand Down
9 changes: 4 additions & 5 deletions src/pages/endpoint/__tests__/endpoint.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { LocalStorageUtils } from '@deriv-com/utils';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import Endpoint from '..';
Expand Down Expand Up @@ -33,8 +32,8 @@ describe('<Endpoint />', () => {
await userEvent.type(appIdInput, '123');
await userEvent.click(submitButton);

expect(LocalStorageUtils.getValue('config.server_url') ?? '').toBe('qa10.deriv.dev');
expect(LocalStorageUtils.getValue('config.app_id') ?? '').toBe('123');
expect(localStorage.getItem('config.server_url') ?? '').toBe('qa10.deriv.dev');
expect(localStorage.getItem('config.app_id') ?? '').toBe('123');
});

it('should call getServerInfo and reset the inputs when user clicks on the reset button', async () => {
Expand All @@ -48,7 +47,7 @@ describe('<Endpoint />', () => {
await userEvent.type(appIdInput, '123');
await userEvent.click(resetButton);

expect(LocalStorageUtils.getValue('config.server_url') ?? '').toBe('blue.derivws.com');
expect(LocalStorageUtils.getValue('config.app_id') ?? '').toBe(65555);
expect(localStorage.getItem('config.server_url') ?? '').toBe('blue.derivws.com');
expect(localStorage.getItem('config.app_id') ?? '').toBe('65555');
});
});
14 changes: 7 additions & 7 deletions src/pages/endpoint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import React from 'react';
import { useFormik } from 'formik';
import { getAppId, getDefaultAppIdAndUrl, getSocketURL } from '@/components/shared';
import { Button, Input, Text } from '@deriv-com/ui';
import { LocalStorageConstants, LocalStorageUtils } from '@deriv-com/utils';
import { LocalStorageConstants } from '@deriv-com/utils';
import './endpoint.scss';
const Endpoint = () => {
const formik = useFormik({
initialValues: {
appId: LocalStorageUtils.getValue(LocalStorageConstants.configAppId) ?? getAppId(),
serverUrl: LocalStorageUtils.getValue(LocalStorageConstants.configServerURL) ?? getSocketURL(),
appId: localStorage.getItem(LocalStorageConstants.configAppId) ?? getAppId(),
serverUrl: localStorage.getItem(LocalStorageConstants.configServerURL) ?? getSocketURL(),
},
onSubmit: values => {
LocalStorageUtils.setValue(LocalStorageConstants.configServerURL, values.serverUrl);
LocalStorageUtils.setValue(LocalStorageConstants.configAppId, values.appId);
localStorage.setItem(LocalStorageConstants.configServerURL, values.serverUrl);
localStorage.setItem(LocalStorageConstants.configAppId, values.appId.toString());
formik.resetForm({ values });
},
validate: values => {
Expand Down Expand Up @@ -62,8 +62,8 @@ const Endpoint = () => {
color='black'
onClick={() => {
const { server_url, app_id } = getDefaultAppIdAndUrl();
LocalStorageUtils.setValue(LocalStorageConstants.configServerURL, server_url);
LocalStorageUtils.setValue(LocalStorageConstants.configAppId, app_id);
localStorage.setItem(LocalStorageConstants.configServerURL, server_url);
localStorage.setItem(LocalStorageConstants.configAppId, app_id.toString());

formik.resetForm({
values: {
Expand Down

0 comments on commit 5288c00

Please sign in to comment.