From 4800d81cdfc55e758e16ec71ba918a700746226a Mon Sep 17 00:00:00 2001 From: niloo-fs Date: Wed, 16 Feb 2022 15:31:10 +0330 Subject: [PATCH 1/5] fix broken terms and condition link for zh-tw and zh-cn language --- src/common/constants.ts | 2 +- src/common/utility.js | 17 ++++++++++------- src/components/localization/localized-link.js | 9 +++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/common/constants.ts b/src/common/constants.ts index 216df5df4d7..3dab22fcc40 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -6,7 +6,7 @@ const deriv_me_url = 'deriv.me' const deriv_com_app_id = 16929 const deriv_me_app_id = 1411 -const supported_domains = [deriv_com_url, deriv_me_url] +export const supported_domains = [deriv_com_url, deriv_me_url] const domain_url = isBrowser() && supported_domains.includes(window.location.hostname) ? window.location.hostname diff --git a/src/common/utility.js b/src/common/utility.js index 9063a2e3c32..ae5d4c5b9d5 100644 --- a/src/common/utility.js +++ b/src/common/utility.js @@ -7,6 +7,7 @@ import { deriv_app_languages, live_chat_redirection_link, live_chat_key, + supported_domains, } from './constants' import { isUK } from 'common/country-base' import { localize } from 'components/localization' @@ -316,13 +317,15 @@ export const addScript = (settings) => { export const isChoosenLanguage = () => ({ english: getLanguage() === 'en' }) // Function to manually replace server's locale ("zh_tw" or "zh_cn") to "zh-tw"/"zh-cn" -export const replaceLocale = (locale) => { - let checked_locale = locale - if (locale === 'zh_tw') { - checked_locale = 'zh-tw' - } else if (locale === 'zh_cn') { - checked_locale = 'zh-cn' - } +export const replaceLocale = (url) => { + let checked_locale = url + const domains = [...supported_domains, 'localhost', 'deriv-com-git-fork'] //deriv-com-git-fork for versel server, localhost - for developer mode + domains.forEach((domain) => { + if (url.includes(domain) && url.includes('zh_tw')) + checked_locale = url.replace(/(zh_tw)/g, 'zh-tw') + if (url.includes(domain) && url.includes('zh_cn')) + checked_locale = url.replace(/(zh_cn)/g, 'zh-cn') + }) return checked_locale } diff --git a/src/components/localization/localized-link.js b/src/components/localization/localized-link.js index 65a71b9a2f6..3cc0072faa9 100644 --- a/src/components/localization/localized-link.js +++ b/src/components/localization/localized-link.js @@ -7,7 +7,12 @@ import { LocationContext } from '../layout/location-context.js' import language_config from '../../../i18n-config' import { LocaleContext } from './locale-context' import { localized_link_url } from 'common/constants' -import { getLocalizedUrl, getDerivAppLocalizedURL, getThaiExcludedLocale } from 'common/utility' +import { + getLocalizedUrl, + getDerivAppLocalizedURL, + getThaiExcludedLocale, + replaceLocale, +} from 'common/utility' import { DerivStore } from 'store' export const SharedLinkStyle = css` @@ -183,7 +188,7 @@ const ExternalLink = ({ const { is_eu_country } = useContext(DerivStore) const { setModalPayload, toggleModal } = useContext(LocationContext) const { affiliate_lang } = language_config[locale] - const url = getURLFormat(type, locale, to, affiliate_lang) + const url = replaceLocale(getURLFormat(type, locale, to, affiliate_lang)) const show_modal = is_eu_country && !is_mail_link && From 93a41188db42e847308fd878b9568cdce62fc88d Mon Sep 17 00:00:00 2001 From: niloo-fs Date: Wed, 16 Feb 2022 15:36:14 +0330 Subject: [PATCH 2/5] . --- src/common/utility.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/utility.js b/src/common/utility.js index ae5d4c5b9d5..e747a31ce2b 100644 --- a/src/common/utility.js +++ b/src/common/utility.js @@ -319,7 +319,7 @@ export const isChoosenLanguage = () => ({ english: getLanguage() === 'en' }) // Function to manually replace server's locale ("zh_tw" or "zh_cn") to "zh-tw"/"zh-cn" export const replaceLocale = (url) => { let checked_locale = url - const domains = [...supported_domains, 'localhost', 'deriv-com-git-fork'] //deriv-com-git-fork for versel server, localhost - for developer mode + const domains = [...supported_domains, 'localhost', 'deriv-com-git-fork'] //deriv-com-git-fork for vercel server, localhost - for developer mode domains.forEach((domain) => { if (url.includes(domain) && url.includes('zh_tw')) checked_locale = url.replace(/(zh_tw)/g, 'zh-tw') From 201913f91f36d87705c83a11a9db042062b3562b Mon Sep 17 00:00:00 2001 From: niloo-fs Date: Wed, 16 Feb 2022 17:14:33 +0330 Subject: [PATCH 3/5] add some exceptions --- src/common/utility.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/common/utility.js b/src/common/utility.js index e747a31ce2b..d6c1d96cac7 100644 --- a/src/common/utility.js +++ b/src/common/utility.js @@ -320,12 +320,15 @@ export const isChoosenLanguage = () => ({ english: getLanguage() === 'en' }) export const replaceLocale = (url) => { let checked_locale = url const domains = [...supported_domains, 'localhost', 'deriv-com-git-fork'] //deriv-com-git-fork for vercel server, localhost - for developer mode - domains.forEach((domain) => { - if (url.includes(domain) && url.includes('zh_tw')) - checked_locale = url.replace(/(zh_tw)/g, 'zh-tw') - if (url.includes(domain) && url.includes('zh_cn')) - checked_locale = url.replace(/(zh_cn)/g, 'zh-cn') - }) + const excluded_paths = ['smarttrader'] + if (!excluded_paths.some((path) => url.includes(path))) { + domains.forEach((domain) => { + if (url.includes(domain) && url.includes('zh_tw')) + checked_locale = url.replace(/(zh_tw)/g, 'zh-tw') + if (url.includes(domain) && url.includes('zh_cn')) + checked_locale = url.replace(/(zh_cn)/g, 'zh-cn') + }) + } return checked_locale } From 8832a39b21fc240cf2464023f6c05a1107157c51 Mon Sep 17 00:00:00 2001 From: niloo-fs Date: Wed, 16 Feb 2022 17:21:53 +0330 Subject: [PATCH 4/5] code improvement --- src/common/constants.ts | 1 + src/common/utility.js | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/constants.ts b/src/common/constants.ts index 3dab22fcc40..c55859263e4 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -7,6 +7,7 @@ const deriv_com_app_id = 16929 const deriv_me_app_id = 1411 export const supported_domains = [deriv_com_url, deriv_me_url] +export const domains = [...supported_domains, 'localhost', 'deriv-com-git-fork'] //deriv-com-git-fork for vercel server, localhost - for developer mode const domain_url = isBrowser() && supported_domains.includes(window.location.hostname) ? window.location.hostname diff --git a/src/common/utility.js b/src/common/utility.js index d6c1d96cac7..d0b53467efb 100644 --- a/src/common/utility.js +++ b/src/common/utility.js @@ -7,7 +7,7 @@ import { deriv_app_languages, live_chat_redirection_link, live_chat_key, - supported_domains, + domains, } from './constants' import { isUK } from 'common/country-base' import { localize } from 'components/localization' @@ -319,7 +319,6 @@ export const isChoosenLanguage = () => ({ english: getLanguage() === 'en' }) // Function to manually replace server's locale ("zh_tw" or "zh_cn") to "zh-tw"/"zh-cn" export const replaceLocale = (url) => { let checked_locale = url - const domains = [...supported_domains, 'localhost', 'deriv-com-git-fork'] //deriv-com-git-fork for vercel server, localhost - for developer mode const excluded_paths = ['smarttrader'] if (!excluded_paths.some((path) => url.includes(path))) { domains.forEach((domain) => { From 32834fe23e43b1e67b617129c127233d2c7b2aed Mon Sep 17 00:00:00 2001 From: niloo-fs Date: Wed, 23 Feb 2022 10:48:22 +0330 Subject: [PATCH 5/5] remove supported-domains --- src/common/constants.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/constants.ts b/src/common/constants.ts index 1efe5571553..313d40f1b89 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -9,9 +9,6 @@ export const deriv_com_app_id = 16929 export const deriv_me_app_id = 1411 export const deriv_be_app_id = 30767 -export const supported_domains = [deriv_com_url, deriv_me_url] -export const domains = [...supported_domains, 'localhost', 'deriv-com-git-fork'] //deriv-com-git-fork for vercel server, localhost - for developer mode - const domain_url_pair = { [deriv_com_url]: deriv_com_url, [deriv_me_url]: deriv_me_url, @@ -19,6 +16,15 @@ const domain_url_pair = { [staging_deriv_be_url]: deriv_be_url, } +export const domains = [ + deriv_com_url, + deriv_me_url, + deriv_be_url, + staging_deriv_be_url, + 'localhost', + 'deriv-com-git-fork', +] //deriv-com-git-fork for vercel server, localhost - for developer mode + const getDomainUrl = (): string => isBrowser() && window.location.hostname in domain_url_pair ? domain_url_pair[window.location.hostname]