Skip to content

Commit

Permalink
fix: use getCountry from utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuzhy-Deriv committed Nov 7, 2024
1 parent 58a896d commit 2240201
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/javascript/_common/analytics.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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,
Expand Down
14 changes: 0 additions & 14 deletions src/javascript/_common/utility.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const extend = require('extend');
const Cookies = require('js-cookie');
const getCurrentBinaryDomain = require('../config').getCurrentBinaryDomain;
require('./lib/polyfills/element.matches');

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -351,5 +338,4 @@ module.exports = {
lc_clientID,
openChat,
openChatWithParam,
getCountry,
};

0 comments on commit 2240201

Please sign in to comment.