diff --git a/packages/core/src/App/Components/Elements/LiveChat/use-livechat.ts b/packages/core/src/App/Components/Elements/LiveChat/use-livechat.ts index 0f211ee8d22d..6d52e1aab9aa 100644 --- a/packages/core/src/App/Components/Elements/LiveChat/use-livechat.ts +++ b/packages/core/src/App/Components/Elements/LiveChat/use-livechat.ts @@ -1,20 +1,14 @@ import { useCallback, useEffect, useState } from 'react'; -import { useHistory, useParams } from 'react-router'; +import { useHistory } from 'react-router'; import { liveChatInitialization } from './live-chat'; import Cookies from 'js-cookie'; import { deriv_urls } from '@deriv/shared'; -type TQueryParams = { - lang: string; - dark: string; -}; - // Todo: Should break this into smaller hooks or utility functions. const useLiveChat = (has_cookie_account = false) => { const [isReady, setIsReady] = useState(false); const [reload, setReload] = useState(false); const history = useHistory(); - const { lang, dark } = useParams(); const widget = window.LiveChatWidget; const liveChatDeletion = () => @@ -108,10 +102,6 @@ const useLiveChat = (has_cookie_account = false) => { }); }; - useEffect(() => { - onHistoryChange(); - }, [lang, dark, onHistoryChange]); - useEffect(() => { if (isReady && !widget) { onHistoryChange(); diff --git a/packages/core/src/App/Containers/Routes/routes.jsx b/packages/core/src/App/Containers/Routes/routes.jsx index 2765c6f935f8..df30a7ad900d 100644 --- a/packages/core/src/App/Containers/Routes/routes.jsx +++ b/packages/core/src/App/Containers/Routes/routes.jsx @@ -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'; @@ -23,7 +23,6 @@ const Routes = ({ error, has_error, history, - is_dark_mode_on, is_logged_in, is_logging_in, location, @@ -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 ; @@ -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 ; }; @@ -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, @@ -97,8 +95,7 @@ Routes.propTypes = { // need to wrap withRouter around connect // to prevent updates on 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, diff --git a/packages/shared/src/utils/url/url.ts b/packages/shared/src/utils/url/url.ts index db6c0729df24..8b762438935a 100644 --- a/packages/shared/src/utils/url/url.ts +++ b/packages/shared/src/utils/url/url.ts @@ -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 @@ -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; };