From 412c8e1123c55047dc0bdfa7fca49abcd383eda3 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 4 Aug 2021 11:47:20 +0200 Subject: [PATCH 1/5] refactoring checkCountry and handler functions --- src/javascript/static/pages/Home/home.jsx | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/javascript/static/pages/Home/home.jsx b/src/javascript/static/pages/Home/home.jsx index 79e0f0512e4d6..6cbdbda88d7ab 100644 --- a/src/javascript/static/pages/Home/home.jsx +++ b/src/javascript/static/pages/Home/home.jsx @@ -26,19 +26,32 @@ import urlFor from '../../../_common/url'; import BinaryPjax from '../../../app/base/binary_pjax'; import BinarySocket from '../../../app/base/socket'; import { isBinaryApp } from '../../../config'; +import { getElementById } from '../../../_common/common_functions'; +import { createElement } from '../../../_common/utility'; const checkCountry = (req, clients_country) => { + const verify_email_form_child = document.querySelector('#frm_verify_email div'); + const set_notice_msg = createElement('p'); + if ((clients_country !== 'my') || /@((binary|deriv|regentmarkets)\.com|4x\.my|binary\.me)$/.test(req.verify_email)) { return true; } - $('#frm_verify_email').find('div') - .html($('

', { class: 'notice-msg center-text', html: localize('Sorry, account signup is not available in your country.') })); + + set_notice_msg.setAttribute('class', 'notice-msg center-text'); + set_notice_msg.innerText(localize('Sorry, account signup is not available in your country.')); + + verify_email_form_child.appendChild(set_notice_msg); + return false; }; const handler = (response) => { + const signup_error = getElementById('signup_error'); + const social_signup = getElementById('social-signup'); + const signup_box_child_div = document.querySelector('.signup-box div'); + if (response.error) { - $('#signup_error').setVisibility(1).text(response.error.message); + signup_error.setVisibility(1).innerText(response.error.message); return; } BinarySocket.wait('time').then(({ time }) => { @@ -54,8 +67,8 @@ const handler = (response) => { if (is_binary_app) { BinaryPjax.load(urlFor('new_account/virtualws')); } else { - $('.signup-box div').replaceWith($('

', { text: localize('Thank you for signing up! Please check your email to complete the registration process.'), class: 'gr-10 gr-centered center-text' })); - $('#social-signup').setVisibility(0); + signup_box_child_div.replaceWith($('

', { text: localize('Thank you for signing up! Please check your email to complete the registration process.'), class: 'gr-10 gr-centered center-text' })); + social_signup.setVisibility(0); } }); }; From 8038c81cdadf097b4741d16f8105688f4a036178 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 4 Aug 2021 13:59:15 +0200 Subject: [PATCH 2/5] refactoring handler function --- src/javascript/static/pages/Home/home.jsx | 35 ++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/javascript/static/pages/Home/home.jsx b/src/javascript/static/pages/Home/home.jsx index 6cbdbda88d7ab..eb0771b5cee4a 100644 --- a/src/javascript/static/pages/Home/home.jsx +++ b/src/javascript/static/pages/Home/home.jsx @@ -31,44 +31,53 @@ import { createElement } from '../../../_common/utility'; const checkCountry = (req, clients_country) => { const verify_email_form_child = document.querySelector('#frm_verify_email div'); - const set_notice_msg = createElement('p'); - + const fail_msg = localize('Sorry, account signup is not available in your country.'); + + const fail_msg_element = createElement('p'); + fail_msg_element.setAttribute('class', 'notice-msg center-text'); + fail_msg_element.innerText(fail_msg); + if ((clients_country !== 'my') || /@((binary|deriv|regentmarkets)\.com|4x\.my|binary\.me)$/.test(req.verify_email)) { return true; } - set_notice_msg.setAttribute('class', 'notice-msg center-text'); - set_notice_msg.innerText(localize('Sorry, account signup is not available in your country.')); - - verify_email_form_child.appendChild(set_notice_msg); + verify_email_form_child.appendChild(fail_msg_element); return false; }; const handler = (response) => { - const signup_error = getElementById('signup_error'); - const social_signup = getElementById('social-signup'); - const signup_box_child_div = document.querySelector('.signup-box div'); + const signup_error_element = getElementById('signup_error'); + const social_signup_element = getElementById('social-signup'); + const signup_box_child = document.querySelector('.signup-box div'); + + const success_msg = localize('Thank you for signing up! Please check your email to complete the registration process.'); + const success_msg_element = createElement('p'); + success_msg_element.setAttribute('class', 'gr-10 gr-centered center-text'); + success_msg_element.innerText(success_msg); if (response.error) { - signup_error.setVisibility(1).innerText(response.error.message); + const error_msg = response.error.message; + signup_error_element.setVisibility(1); + signup_error_element.innerText(error_msg); return; } BinarySocket.wait('time').then(({ time }) => { const is_binary_app = isBinaryApp(); + const date_first_contact = localStorage.getItem('date_first_contact'); GTM.pushDataLayer({ event : 'email_submit', email_submit_input : response.echo_req.verify_email, - email_submit_days_passed: moment(time * 1000).utc().diff(moment.utc(localStorage.getItem('date_first_contact')), 'days'), + email_submit_days_passed: moment(time * 1000).utc().diff(moment.utc(date_first_contact), 'days'), email_submit_source : is_binary_app ? 'desktop app' : 'binary.com', }); if (is_binary_app) { BinaryPjax.load(urlFor('new_account/virtualws')); } else { - signup_box_child_div.replaceWith($('

', { text: localize('Thank you for signing up! Please check your email to complete the registration process.'), class: 'gr-10 gr-centered center-text' })); - social_signup.setVisibility(0); + signup_box_child.replaceWith(success_msg_element); + social_signup_element.setVisibility(0); } }); }; From 727e75daf44acfb3589ebc1cc318a020d9d08e9f Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 4 Aug 2021 16:26:23 +0200 Subject: [PATCH 3/5] refactoring code --- src/javascript/static/pages/Home/home.jsx | 39 +++++++++++++---------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/javascript/static/pages/Home/home.jsx b/src/javascript/static/pages/Home/home.jsx index eb0771b5cee4a..3e18d86d44ea6 100644 --- a/src/javascript/static/pages/Home/home.jsx +++ b/src/javascript/static/pages/Home/home.jsx @@ -1,7 +1,12 @@ import React from 'react'; -import moment from 'moment'; -import { AccountsTabContent, MarketsTabContent, TabCircles } from '../Components'; -import { PlatformContext, PlatformDefaultValue } from '../../../react/context/platform'; +import moment from 'moment'; +import { + AccountsTabContent, + MarketsTabContent, + TabCircles } from '../Components'; +import { + PlatformContext, + PlatformDefaultValue } from '../../../react/context/platform'; import FormVerifyEmail from '../../../../templates/_common/includes/form_verify_email.jsx'; import { SocialButton } from '../../../../templates/_common/components/elements.jsx'; import PaymentLogo from '../../../../templates/_common/components/payment_logo.jsx'; @@ -14,20 +19,20 @@ import { TabsSubtabs, TabContent } from '../../../../templates/_common/components/tabs.jsx'; import DerivBanner from '../../../../templates/_common/components/deriv_banner.jsx'; -import { localize } from '../../../_common/localize'; -import TabSelector from '../../../_common/tab_selector'; -import Login from '../../../_common/base/login'; -import DerivBannerModule from '../../../app/common/deriv_banner'; -import FormManager from '../../../app/common/form_manager'; -import getFormRequest from '../../../app/common/verify_email'; -import GTM from '../../../_common/base/gtm'; -import { State } from '../../../_common/storage'; -import urlFor from '../../../_common/url'; -import BinaryPjax from '../../../app/base/binary_pjax'; -import BinarySocket from '../../../app/base/socket'; -import { isBinaryApp } from '../../../config'; -import { getElementById } from '../../../_common/common_functions'; -import { createElement } from '../../../_common/utility'; +import { localize } from '../../../_common/localize'; +import TabSelector from '../../../_common/tab_selector'; +import Login from '../../../_common/base/login'; +import DerivBannerModule from '../../../app/common/deriv_banner'; +import FormManager from '../../../app/common/form_manager'; +import getFormRequest from '../../../app/common/verify_email'; +import GTM from '../../../_common/base/gtm'; +import { State } from '../../../_common/storage'; +import urlFor from '../../../_common/url'; +import BinaryPjax from '../../../app/base/binary_pjax'; +import BinarySocket from '../../../app/base/socket'; +import { isBinaryApp } from '../../../config'; +import { getElementById } from '../../../_common/common_functions'; +import { createElement } from '../../../_common/utility'; const checkCountry = (req, clients_country) => { const verify_email_form_child = document.querySelector('#frm_verify_email div'); From d0ef29e64eb69372c6f9bff4482be4164cb9950f Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 4 Aug 2021 16:35:51 +0200 Subject: [PATCH 4/5] making code more readable --- src/javascript/static/pages/Home/home.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/javascript/static/pages/Home/home.jsx b/src/javascript/static/pages/Home/home.jsx index 3e18d86d44ea6..c04cdced6f992 100644 --- a/src/javascript/static/pages/Home/home.jsx +++ b/src/javascript/static/pages/Home/home.jsx @@ -36,9 +36,9 @@ import { createElement } from '../../../_common/utility'; const checkCountry = (req, clients_country) => { const verify_email_form_child = document.querySelector('#frm_verify_email div'); - const fail_msg = localize('Sorry, account signup is not available in your country.'); + const fail_msg = localize('Sorry, account signup is not available in your country.'); - const fail_msg_element = createElement('p'); + const fail_msg_element = createElement('p'); fail_msg_element.setAttribute('class', 'notice-msg center-text'); fail_msg_element.innerText(fail_msg); @@ -52,12 +52,12 @@ const checkCountry = (req, clients_country) => { }; const handler = (response) => { - const signup_error_element = getElementById('signup_error'); + const signup_error_element = getElementById('signup_error'); const social_signup_element = getElementById('social-signup'); - const signup_box_child = document.querySelector('.signup-box div'); + const signup_box_child = document.querySelector('.signup-box div'); - const success_msg = localize('Thank you for signing up! Please check your email to complete the registration process.'); - const success_msg_element = createElement('p'); + const success_msg = localize('Thank you for signing up! Please check your email to complete the registration process.'); + const success_msg_element = createElement('p'); success_msg_element.setAttribute('class', 'gr-10 gr-centered center-text'); success_msg_element.innerText(success_msg); @@ -68,7 +68,7 @@ const handler = (response) => { return; } BinarySocket.wait('time').then(({ time }) => { - const is_binary_app = isBinaryApp(); + const is_binary_app = isBinaryApp(); const date_first_contact = localStorage.getItem('date_first_contact'); GTM.pushDataLayer({ From 9bed0f17b2d8d34b8450dbc6459760f99a49cecb Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 4 Aug 2021 16:40:35 +0200 Subject: [PATCH 5/5] making code more readable --- src/javascript/static/pages/Home/home.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascript/static/pages/Home/home.jsx b/src/javascript/static/pages/Home/home.jsx index c04cdced6f992..74a3711f40795 100644 --- a/src/javascript/static/pages/Home/home.jsx +++ b/src/javascript/static/pages/Home/home.jsx @@ -36,8 +36,8 @@ import { createElement } from '../../../_common/utility'; const checkCountry = (req, clients_country) => { const verify_email_form_child = document.querySelector('#frm_verify_email div'); + const fail_msg = localize('Sorry, account signup is not available in your country.'); - const fail_msg_element = createElement('p'); fail_msg_element.setAttribute('class', 'notice-msg center-text'); fail_msg_element.innerText(fail_msg);