Skip to content

Commit

Permalink
Merge branch 'master' into amina/feature/90115/update_jurisdiction
Browse files Browse the repository at this point in the history
  • Loading branch information
suisin-deriv authored May 5, 2023
2 parents 6704425 + 8a4fec1 commit 29f2f5f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const useLiveChat = (has_cookie_account = false) => {
const [isReady, setIsReady] = useState(false);
const [reload, setReload] = useState(false);
const history = useHistory();
const search_params = window.location.search;
const widget = window.LiveChatWidget;

const liveChatDeletion = () =>
Expand Down Expand Up @@ -103,10 +102,6 @@ const useLiveChat = (has_cookie_account = false) => {
});
};

useEffect(() => {
onHistoryChange();
}, [search_params, onHistoryChange]);

useEffect(() => {
if (isReady && !widget) {
onHistoryChange();
Expand Down
19 changes: 8 additions & 11 deletions packages/core/src/App/Containers/Routes/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import { withRouter } from 'react-router';
import Loadable from 'react-loadable';
import { UILoader } from '@deriv/components';
import { urlSetQuery } from '@deriv/shared';
import { urlForLanguage } from '@deriv/shared';
import { getLanguage } from '@deriv/translations';
import BinaryRoutes from 'App/Components/Routes';
import { connect } from 'Stores/connect';
Expand All @@ -23,7 +23,6 @@ const Routes = ({
error,
has_error,
history,
is_dark_mode_on,
is_logged_in,
is_logging_in,
location,
Expand Down Expand Up @@ -58,6 +57,8 @@ const Routes = ({
}, []);

const lang = getLanguage();
const lang_regex = /[?&]lang=/;
const has_lang = lang_regex.test(location.search);

if (has_error) {
return <Error {...error} />;
Expand All @@ -69,12 +70,10 @@ const Routes = ({
// non-supported language, the language still
// shows up in the URL. This is not in sync
// with the default language (EN), so we
// will remove it. (The same thing for dark_mode)
window.history.replaceState(
{},
document.title,
urlSetQuery({ lang: lang.replace('EN', ''), dark: Number(is_dark_mode_on) })
);
// will remove it.
if ((!has_lang && lang !== 'EN') || (has_lang && lang === 'EN')) {
window.history.replaceState({}, document.title, urlForLanguage(lang));
}

return <BinaryRoutes is_logged_in={is_logged_in} is_logging_in={is_logging_in} passthrough={passthrough} />;
};
Expand All @@ -84,7 +83,6 @@ Routes.propTypes = {
error: MobxPropTypes.objectOrObservableObject,
has_error: PropTypes.bool,
history: PropTypes.object,
is_dark_mode_on: PropTypes.bool,
is_logged_in: PropTypes.bool,
is_logging_in: PropTypes.bool,
is_virtual: PropTypes.bool,
Expand All @@ -97,8 +95,7 @@ Routes.propTypes = {
// need to wrap withRouter around connect
// to prevent updates on <BinaryRoutes /> from being blocked
export default withRouter(
connect(({ client, common, ui }) => ({
is_dark_mode_on: ui.is_dark_mode_on,
connect(({ client, common }) => ({
is_logged_in: client.is_logged_in,
is_logging_in: client.is_logging_in,
error: common.error,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Stores/common-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export default class CommonStore extends BaseStore {
try {
await changeLanguage(key, () => {
this.changeCurrentLanguage(key);
this.root_store.client.setIsAuthorize(false);
BinarySocket.closeAndOpenNewConnection(key);
this.root_store.client.setIsAuthorize(false);
});
resolve();
} catch (e) {
Expand Down
22 changes: 0 additions & 22 deletions packages/shared/src/utils/url/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ type TOption = {
language?: string;
};

type TQueryObj = {
dark: string;
lang: string;
};

const default_domain = 'binary.com';
const host_map = {
// the exceptions regarding updating the URLs
Expand All @@ -40,23 +35,6 @@ export const urlForLanguage = (lang: string, url: string = window.location.href)
return `${current_url}`;
};

export const urlSetQuery = (queryObj: TQueryObj, url: string = window.location.href) => {
const current_url = new URL(url);

Object.entries(queryObj).forEach(element => {
const [key, value] = element;
if (value) {
current_url.searchParams.set(key, value);
} else {
current_url.searchParams.delete(key);
}
});

current_url.searchParams.sort();

return current_url.toString();
};

export const reset = () => {
location_url = window?.location ?? location_url;
};
Expand Down

0 comments on commit 29f2f5f

Please sign in to comment.