/* modal start */ function modalOpen(id) { if (!id) { id = "data-modal-login"; let login_type = searchParams.get('login_type'); // if guest goto login if (login_type == "G"){ let appClone = searchParams.get('app'); var appvalue = "cosmos"; if (appClone) { appvalue = appClone; } window.location.href = appvalue + "://login"; return; } // outright refusal to participate if (login_type && login_type != "A" && login_type != "G"){ modalOpen("data-modal-noteligible"); } let afp = searchParams.get('afp'); if (login_type == "A" && afp){ console.log("add") joinNow(afp, null); return; } } document.querySelector(".modal[" + id + "]").classList.add("modal-show"); document.body.style.overflow = "hidden"; } function modalClose() { document.querySelector(".modal.modal-show") ? document.querySelector(".modal.modal-show").classList.remove("modal-show") : ''; document.body.style.overflow = "auto"; } function copyLink(event) { // Get the text field var copyText = document.getElementById("refer-link"); if (window.JsHook && JsHook.appCopy) { JsHook.appCopy(copyText); } else if ( window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.appCopy ) { window.webkit.messageHandlers.appCopy.postMessage({ url: copyText }); } else { // Select the text field copyText.select(); copyText.setSelectionRange(0, 99999); // For mobile devices // // Copy the text inside the text field // navigator.clipboard.writeText(copyText.value); copyToClipboard(copyText.value); event.target .querySelector(".tooltiptext") .classList.add("tooltiptext-show"); } setTimeout(() => { event.target .querySelector(".tooltiptext") .classList.remove("tooltiptext-show"); }, 3000); } function unsecuredCopyToClipboard(text) { const textArea = document.createElement("textarea"); textArea.value = text; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { document.execCommand("copy"); } catch (err) { console.error("Unable to copy to clipboard", err); } document.body.removeChild(textArea); } const copyToClipboard = (content) => { if (window.isSecureContext && navigator.clipboard) { navigator.clipboard.writeText(content); } else { unsecuredCopyToClipboard(content); } }; // cause bug // const getCookie = (name) => ( // document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || '' // ) const togglePassword = (e) => { const parent = e.target.parentElement; const input_field = parent.querySelector("input"); if (input_field) { const type = input_field.type; if (type === "password") { input_field.type = "text"; } else { input_field.type = "password"; } input_field.focus(); } }; const awaitAjaxPost = (path, data, type = "json", abort = true) => { return new Promise((resolve) => { var xhr = new XMLHttpRequest(); xhr.addEventListener("load", function () { if (this.readyState === 4) { let response = this.response; if (type === "json") { if (response === null) { response = {}; } response.code = this.status; } resolve(response); } }); xhr.responseType = type; //xhr.open('POST', '../account-creation/a/' + path); xhr.open("POST", path); xhr.setRequestHeader("desktop", "1"); xhr.setRequestHeader("inapp", "0"); xhr.setRequestHeader("x-funnel-customer-session-id", ""); xhr.setRequestHeader("x-br-extras", JSON.stringify({})); xhr.setRequestHeader("Content-Type", "application/json"); data.config_id = "conf_default"; xhr.send(JSON.stringify(data)); }); }; const submitLogin = (e) => { e.preventDefault(); document .querySelector('form[data-action="submitLogin"]') .setAttribute("data-state", "disabled"); document.querySelector( '[data-action="submitLogin"] .company-message' ).style.display = "none"; awaitAjaxPost("/account-creation/a/account/login", { email: this.email.value, password: this.password.value, remember: false, appSource: 8, isDemoMode: false, }).then(function (result) { if (result.code === 400) { // error document .querySelector('form[data-action="submitLogin"]') .setAttribute("data-state", ""); document.querySelector( '[data-action="submitLogin"] .company-message' ).style.display = "block"; } if (result.code === 200) { window._uid = result.data.aid; joinNow(result.data.aid, this.email.value); } }); }; const joinNow = (aid, email) => { awaitAjaxPost("https://funapi.inter-bots.com/promo/edb", { email: email, customer_id: aid, promo_name: "edb20", }).then(function (result) { document.querySelector('form[data-action="submitLogin"]').setAttribute("data-state", ""); if (result.result == "0") { modalClose(); modalOpen("data-modal-success"); } else if (result.result == "410") { modalClose(); modalOpen("data-modal-noteligible"); } }); }; document.querySelector('[data-action="togglePassword"]').addEventListener("click", togglePassword); document.querySelector('[data-action="submitLogin"]').addEventListener("submit", submitLogin); //test_sfdg@dfg.com / Danny1! window.SOCIAL_GOOGLE_CLIENT_ID = "21155591901-3isu8mp2fid95i2o6sl3pp24t3vforrd.apps.googleusercontent.com"; window.SOCIAL_FACEBOOK_APP_ID = "714426151973006"; window.SOCIAL_APPLE_JSON = { apiKey: "AIzaSyCqRl_-q57A6LRNibxLeg-mH6mZWbtY4oA", authDomain: "api-project-21155591901.firebaseapp.com", databaseURL: "https://api-project-21155591901.firebaseio.com", projectId: "api-project-21155591901", storageBucket: "api-project-21155591901.appspot.com", messagingSenderId: "21155591901", appId: "1:21155591901:web:6df0d915f039b20914cd34", measurementId: "G-2NMBXHHZG9", }; window.appleAuth = null; window.__externalLibraries = []; window.__externalLibrariesCallbacks = []; loadExternalLibrary = function (ref, callback) { if (typeof window.__externalLibraries[ref] === "undefined") { window.__externalLibraries[ref] = 0; window.__externalLibrariesCallbacks[ref] = []; window.__externalLibrariesCallbacks[ref].push(callback); let script = document.createElement("script"); script.src = ref; script.onload = function () { window.__externalLibraries[ref] = 1; for ( var i = 0; i < window.__externalLibrariesCallbacks[ref].length; i++ ) { window.__externalLibrariesCallbacks[ref][i](); } }; document.getElementsByTagName("head")[0].appendChild(script); } else { if (window.__externalLibraries[ref] === 0) { window.__externalLibrariesCallbacks[ref].push(callback); } else { callback(); } } }; const socialLogin = (e) => { e.preventDefault(); const social = e.target.getAttribute("data-social"); switch (social) { case "google": loginWithGoogle(); break; case "facebook": loginWithFacebook(); break; case "apple": loginWithApple(); break; } }; const loginWithGoogle = () => { loadExternalLibrary("https://apis.google.com/js/api:client.js", function () { gapi.load("auth2", function () { gapi.auth2.init({ client_id: window.SOCIAL_GOOGLE_CLIENT_ID, }); gapi.auth2 .getAuthInstance() .signIn() .then( function (response) { const id_token = response.getAuthResponse().id_token; const jwtData = jwt_decode(id_token); window._email = jwtData.email; socialLoginSubmission({ method: "google", token: id_token, }); }, function (error) { // console.log(error); } ); }); }); }; const loginWithApple = () => { loadExternalLibrary( "https://www.gstatic.com/firebasejs/8.6.3/firebase-app.js", function () { loadExternalLibrary( "https://www.gstatic.com/firebasejs/8.6.3/firebase-auth.js", function () { if (!window.appleAuth) { firebase.initializeApp(window.SOCIAL_APPLE_JSON); var provider = new firebase.auth.OAuthProvider("apple.com"); provider.addScope("email"); provider.addScope("name"); provider.setCustomParameters({ locale: "en", }); window.appleAuth = provider; } firebase .auth() .signInWithPopup(window.appleAuth) .then((result) => { return firebase .auth() .currentUser.getIdToken(true) .then(function (id_token) { const jwtData = jwt_decode(id_token); window._email = jwtData.email; socialLoginSubmission({ method: "apple", token: id_token, }); }) .catch((error) => { console.error( "Failed to verify token while Apple sign in via firebase", error ); }); }) .catch((error) => { console.error( "Failed to open modal while Apple sign in via firebase", error ); }); } ); } ); }; const loginWithFacebook = () => { loadExternalLibrary("https://connect.facebook.net/en_US/sdk.js", function () { FB.init({ appId: window.SOCIAL_FACEBOOK_APP_ID, autoLogAppEvents: true, xfbml: true, version: "v2.10", }); FB.AppEvents.logPageView(); FB.login( function (response) { if (!response || !response.authResponse) { // console.log("no response"); return; } window.id_token = response.authResponse.accessToken; FB.api("/me", { fields: "name, email" }, function (response) { window._email = response.email; socialLoginSubmission({ method: "facebook", token: window.id_token, }); }); }, { scope: "email" } ); }); }; const social_logins = document.querySelectorAll('[data-action="socialLogin"]'); if (social_logins.length) { for (var i = 0; i < social_logins.length; i++) { social_logins[i].addEventListener("click", socialLogin); } } const getInstrumentType = (name) => { return name === "Tradetech Alpha" ? "SPREAD_BETTING" : "CFD"; }; const socialLoginSubmission = (data) => { // console.log("[window.siteui.socialLoginSubmission()]") // document.querySelector('.loading-indicator').classList.remove('hide'); document .querySelector('form[data-action="submitLogin"]') .setAttribute("data-state", "disabled"); data.currency = window.__userGEO.currencyCode; data.tradingAccountInstrumentType = getInstrumentType( window.__userGEO.company ); data.country = window.__userGEO.countryCode; awaitAjaxPost("/account-creation/a/account/socialLogin", data).then(function ( result ) { if (result.code === 400) { // error document.querySelector( '[data-action="submitLogin"] .company-message' ).style.display = "block"; } if (result.code === 200) { window._uid = result.data.aid; joinNow(result.data.aid, window._email); } }); }; document.getElementById("email").addEventListener("blur",function(e){ this.value = this.value.trim(); }); /* modal end */