diff --git a/src/botPage/common/const.js b/src/botPage/common/const.js index 367771b51f..4ab79c391d 100644 --- a/src/botPage/common/const.js +++ b/src/botPage/common/const.js @@ -235,8 +235,7 @@ const config = { quick_strategies: ['martingale', 'dalembert'], }; -export async function updateConfigCurrencies() { - const api = generateLiveApiInstance(); +export async function updateConfigCurrencies(api = generateLiveApiInstance()) { try { const response = await api.getPayoutCurrencies(); config.lists.CURRENCY = response.payout_currencies.map(c => [c, c]); diff --git a/src/botPage/view/View.js b/src/botPage/view/View.js index 2d1e124143..9caf151bd8 100644 --- a/src/botPage/view/View.js +++ b/src/botPage/view/View.js @@ -28,6 +28,7 @@ import { addTokenIfValid, } from '../../common/appId'; import { translate } from '../../common/i18n'; +import { isEuCountry, showHideEuElements, hasEuAccount } from '../../common/footer-checks'; import googleDrive from '../../common/integrations/GoogleDrive'; import { getLanguage } from '../../common/lang'; import { observer as globalObserver } from '../../common/utils/observer'; @@ -186,6 +187,9 @@ const updateTokenList = () => { loginButton.show(); accountList.hide(); + // If logged out, determine EU based on IP. + isEuCountry(api).then(isEu => showHideEuElements(isEu)); + $('.account-id') .removeAttr('value') .text(''); @@ -196,13 +200,17 @@ const updateTokenList = () => { } else { loginButton.hide(); accountList.show(); + const activeToken = getActiveToken(tokenList, getStorage(AppConstants.STORAGE_ACTIVE_TOKEN)); + showHideEuElements(hasEuAccount(tokenList)); updateLogo(activeToken.token); addBalanceForToken(activeToken.token); + if (!('loginInfo' in activeToken)) { removeAllTokens(); updateTokenList(); } + tokenList.forEach(tokenInfo => { const prefix = isVirtual(tokenInfo) ? 'Virtual Account' : `${tokenInfo.loginInfo.currency} Account`; if (tokenInfo === activeToken) { @@ -212,7 +220,9 @@ const updateTokenList = () => { $('.account-type').text(`${prefix}`); } else { $('.login-id-list').append( - `
  • ${prefix}
    ${tokenInfo.accountName}
  • ` + `
  • ${prefix}
    ${ + tokenInfo.accountName + }
  • ` ); } }); @@ -231,7 +241,7 @@ export default class View { constructor() { logHandler(); this.initPromise = new Promise(resolve => { - updateConfigCurrencies().then(() => { + updateConfigCurrencies(api).then(() => { symbolPromise.then(() => { updateTokenList(); this.blockly = new _Blockly(); diff --git a/src/common/footer-checks.js b/src/common/footer-checks.js index d3489397ec..76bc067e8b 100644 --- a/src/common/footer-checks.js +++ b/src/common/footer-checks.js @@ -1,21 +1,45 @@ /* eslint-disable import/prefer-default-export */ import { generateLiveApiInstance } from './appId'; -export default async function isEuCountry() { - const api = generateLiveApiInstance(); - const { website_status: { clients_country: clientsCountry } } = await api.send({ website_status: 1 }); - const { landing_company: { financial_company: financialCompany, gaming_company: gamingCompany } } = await api.send({ - landing_company: clientsCountry, +export const showHideEuElements = isEu => { + document.querySelectorAll('.eu-hide').forEach(el => { + if (!isEu && el.classList.contains('invisible')) { + // Keep original display type if invisible was specified. + el.classList.remove('invisible'); + } else { + // Default to setting display to block. + el.setAttribute('display', `${!isEu ? 'block' : 'none'} !important`); + } }); + document.querySelectorAll('.eu-show', '.eu-only').forEach(el => { + if (isEu && el.classList.contains('invisible')) { + el.classList.remove('invisible'); + } else { + el.setAttribute('display', `${isEu ? 'block' : 'none'} !important`); + } + }); +}; + +/* eslint-disable camelcase */ +export const isEuLandingCompany = landing_company => /^(maltainvest|malta|iom)$/.test(landing_company); + +export const hasEuAccount = token_list => + token_list.some(token_obj => isEuLandingCompany(token_obj.loginInfo.landing_company_name)); + +export const isEuCountry = async (api = generateLiveApiInstance()) => { + const { website_status } = await api.send({ website_status: 1 }); + const { clients_country } = website_status; + const { landing_company } = await api.send({ landing_company: clients_country }); + const { financial_company, gaming_company } = landing_company; - const euShortcodeRegex = new RegExp('^(maltainvest|malta|iom)$'); - const euExcludedRegex = new RegExp('^mt$'); - const financialShortcode = financialCompany ? financialCompany.shortcode : false; - const gamingShortcode = gamingCompany ? gamingCompany.shortcode : false; + const eu_excluded_regexp = /^mt$/; + const financial_shortcode = financial_company ? financial_company.shortcode : false; + const gaming_shortcode = gaming_company ? gaming_company.shortcode : false; - api.disconnect(); + if (financial_shortcode || gaming_shortcode) { + return isEuLandingCompany(financial_shortcode) || isEuLandingCompany(gaming_shortcode); + } - return financialShortcode || gamingShortcode - ? euShortcodeRegex.test(financialShortcode) || euShortcodeRegex.test(gamingShortcode) - : euExcludedRegex.test(clientsCountry); -} + return eu_excluded_regexp.test(clients_country); +}; +/* eslint-enable */ diff --git a/src/indexPage/index.js b/src/indexPage/index.js index ce98e6bb66..42a7b635da 100644 --- a/src/indexPage/index.js +++ b/src/indexPage/index.js @@ -4,23 +4,17 @@ import endpoint from './endpoint'; import Logo from './react-components/logo.jsx'; import Footer from './react-components/footer.jsx'; import { oauthLogin } from '../common/appId'; -import '../common/binary-ui/dropdown'; -import isEuCountry from '../common/footer-checks'; +import { isEuCountry, showHideEuElements } from '../common/footer-checks'; import GTM from '../common/gtm'; import { load as loadLang } from '../common/lang'; import { getTokenList } from '../common/utils/storageManager'; import { createUrl } from '../common/utils/tools'; +import '../common/binary-ui/dropdown'; const renderElements = () => { - const showHideEuElements = isEu => { - $('.eu-hide').attr('style', `display: ${isEu ? 'none' : 'block'} !important`); - $('.eu-show, .eu-only').attr('style', `display: ${isEu ? 'block' : 'none'} !important`); - }; ReactDOM.render(, document.getElementById('binary-logo')); ReactDOM.render(