From 22402014219e3ca2462d274aae33b0c1c9796130 Mon Sep 17 00:00:00 2001 From: Nuzhy-Deriv Date: Thu, 7 Nov 2024 17:13:07 +0800 Subject: [PATCH] fix: use getCountry from utils --- package-lock.json | 8 ++++---- package.json | 2 +- src/javascript/_common/analytics.js | 4 ++-- src/javascript/_common/utility.js | 14 -------------- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index e65087e7a1d..cfd75a34be1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "@deriv-com/analytics": "^1.26.1", "@deriv-com/auth-client": "^1.0.15", "@deriv-com/quill-ui": "^1.16.2", - "@deriv-com/utils": "^0.0.37", + "@deriv-com/utils": "^0.0.38", "@deriv/deriv-api": "^1.0.15", "@deriv/quill-icons": "^1.23.1", "@livechat/customer-sdk": "4.0.2", @@ -2620,9 +2620,9 @@ } }, "node_modules/@deriv-com/utils": { - "version": "0.0.37", - "resolved": "https://registry.npmjs.org/@deriv-com/utils/-/utils-0.0.37.tgz", - "integrity": "sha512-+ngUvT+OqwblBoqkHcsbLtljjwOGIjjMpo5xLS5fwyhtNvBe8Rcq+140QV1j0xq9vlm2kmcowEKIVBq33imFmg==" + "version": "0.0.38", + "resolved": "https://registry.npmjs.org/@deriv-com/utils/-/utils-0.0.38.tgz", + "integrity": "sha512-8PBW6IssZYo9JDIwPOKlz36772rExLO+FyI55mZAUz2yVr9dD+ZRUEXsNgIAcGQEGE0U+m5HOQLX/x6JiTqHkQ==" }, "node_modules/@deriv/deriv-api": { "version": "1.0.15", diff --git a/package.json b/package.json index d7dad911fe0..a0c3ec3bbcc 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ "@deriv-com/analytics": "^1.26.1", "@deriv-com/auth-client": "^1.0.15", "@deriv-com/quill-ui": "^1.16.2", - "@deriv-com/utils": "^0.0.37", + "@deriv-com/utils": "^0.0.38", "@deriv/deriv-api": "^1.0.15", "@deriv/quill-icons": "^1.23.1", "@livechat/customer-sdk": "4.0.2", diff --git a/src/javascript/_common/analytics.js b/src/javascript/_common/analytics.js index 9e0d96d4e48..8364d650fde 100644 --- a/src/javascript/_common/analytics.js +++ b/src/javascript/_common/analytics.js @@ -1,6 +1,6 @@ const DerivAnalytics = require('@deriv-com/analytics'); +const CountryUtils = require('@deriv-com/utils').CountryUtils; const Cookies = require('js-cookie'); -const { getCountry } = require('./utility'); const LocalStore = require('./storage').LocalStore; const Language = require('./language'); const { getAppId } = require('../config'); @@ -26,7 +26,7 @@ const Analytics = (() => { loggedIn : !!Cookies.get('clients_information'), account_type : active_account?.account_type || 'unlogged', app_id : String(getAppId()), - country : await getCountry(), + country : await CountryUtils.getCountry(), device_language: navigator?.language || 'en-EN', device_type : window.innerWidth <= 600 ? 'mobile' : 'desktop', domain : window.location.hostname, diff --git a/src/javascript/_common/utility.js b/src/javascript/_common/utility.js index 6c2f3fc8f38..618f9961a55 100644 --- a/src/javascript/_common/utility.js +++ b/src/javascript/_common/utility.js @@ -1,5 +1,4 @@ const extend = require('extend'); -const Cookies = require('js-cookie'); const getCurrentBinaryDomain = require('../config').getCurrentBinaryDomain; require('./lib/polyfills/element.matches'); @@ -312,18 +311,6 @@ const openChatWithParam = () => { }, 500); }; -const getCountry = async () => { - try { - const response = await fetch('https://www.cloudflare.com/cdn-cgi/trace').catch(() => null); - const text = response ? await response.text().catch(() => '') : ''; - const entries = text ? text.split('\n').map(v => v.split('=', 2)) : []; - const data = entries.length ? Object.fromEntries(entries) : {}; - return data?.loc?.toLowerCase() || JSON.parse(Cookies.get('website_status') || '') || ''; - } catch { - return ''; - } -}; - module.exports = { showLoadingImage, getHighestZIndex, @@ -351,5 +338,4 @@ module.exports = { lc_clientID, openChat, openChatWithParam, - getCountry, };