From 329eceba256237b131ccd9c9f87a48963aaa67de Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Fri, 11 Jan 2019 14:26:14 +0800 Subject: [PATCH 01/14] Add elevio script {{ mustache }} var --- gulp/build.js | 2 ++ templates/bot.mustache | 1 + 2 files changed, 3 insertions(+) diff --git a/gulp/build.js b/gulp/build.js index 43c1e6df10..0943a9b2aa 100644 --- a/gulp/build.js +++ b/gulp/build.js @@ -18,6 +18,8 @@ const getConfig = prefix => ({ language : 'templates/partials/language.mustache', loading : 'templates/partials/loading.mustache', binary_style_img: 'image/binary-style', + elevio_script : + '', }); const genHtml = min => diff --git a/templates/bot.mustache b/templates/bot.mustache index 5acf77548a..7ef9e64870 100644 --- a/templates/bot.mustache +++ b/templates/bot.mustache @@ -156,5 +156,6 @@ {{> bundle}} {{> bot}} + {{> elevio_script }} From 4e2fc19119f7d8c39f7671e85c0ca975d6ccc438 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Fri, 11 Jan 2019 18:57:46 +0800 Subject: [PATCH 02/14] Add Elevio.init() --- src/botPage/view/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/botPage/view/index.js b/src/botPage/view/index.js index 208448ae08..4a64f7c549 100644 --- a/src/botPage/view/index.js +++ b/src/botPage/view/index.js @@ -2,8 +2,9 @@ import 'babel-polyfill'; import 'jquery-ui/ui/widgets/dialog'; import 'notifyjs-browser'; -import View from './View'; import '../../common/binary-ui/dropdown'; +import Elevio from '../../common/elevio'; +import View from './View'; import { version } from '../../../package.json'; $.ajaxSetup({ @@ -29,6 +30,7 @@ view.initPromise.then(() => { $('.show-on-load').show(); $('.barspinner').hide(); window.dispatchEvent(new Event('resize')); + Elevio.init(); trackJs.addMetadata('version', version); trackJs.configure({ userId: $('.account-id') From a3d9a4184f550e243e0dedbd0136459842600b0f Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Fri, 11 Jan 2019 18:58:40 +0800 Subject: [PATCH 03/14] Change tour config to not collide with elevio --- src/botPage/view/tour/welcome.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/botPage/view/tour/welcome.js b/src/botPage/view/tour/welcome.js index e78c9fc093..f1e801bfaf 100644 --- a/src/botPage/view/tour/welcome.js +++ b/src/botPage/view/tour/welcome.js @@ -18,9 +18,13 @@ const steps = [ `, - selector: '#tour', + selector: '#center', position: 'top', style : { + textAlign: 'center', + arrow : { + display: 'none', + }, button: { display: 'none', }, @@ -38,8 +42,8 @@ const steps = [ ${translate('or')} ${translate('make your own strategies.')}

`, - selector: '#center', - position: 'bottom', + selector: '#workspace_center', + position: 'top', }, { title: translate('Blocks toolbox'), @@ -74,7 +78,12 @@ const steps = [

`, selector: '#center', - position: 'bottom', + position: 'top', + style : { + arrow: { + display: 'none', + }, + }, }, ]; From 7688e0d7d30af71bd51483aac1f9a03830db43ef Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Fri, 11 Jan 2019 19:00:42 +0800 Subject: [PATCH 04/14] Add workspace_center selector to get around joyride bug (can't have 2 following steps on same element --- static/css/bot.scss | 2 +- templates/bot.mustache | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/static/css/bot.scss b/static/css/bot.scss index a19c441605..026d8aed99 100644 --- a/static/css/bot.scss +++ b/static/css/bot.scss @@ -62,7 +62,7 @@ body { } } -#center { +#center, #workspace_center { position: fixed; width: 1em; height: 1em; diff --git a/templates/bot.mustache b/templates/bot.mustache index 7ef9e64870..f8ac0239dc 100644 --- a/templates/bot.mustache +++ b/templates/bot.mustache @@ -12,6 +12,7 @@
+
From 9ce1c95bfd22ba9e4a9f4977d53e0cba5933312b Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Fri, 11 Jan 2019 19:04:00 +0800 Subject: [PATCH 05/14] Center first popup buttons --- static/css/_tour.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/css/_tour.scss b/static/css/_tour.scss index 857c7bd40f..f6cc082aef 100644 --- a/static/css/_tour.scss +++ b/static/css/_tour.scss @@ -24,7 +24,7 @@ $joyride-tooltip-width: (15em, 20em, 20em); } .tour-custom-buttons { - text-align: right; + text-align: center; margin-top: 1em; button: { margin-left: 0.1em; From 4b65b3ad2a797c84532617a1ebaccbec497f174d Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Fri, 11 Jan 2019 19:16:19 +0800 Subject: [PATCH 06/14] Elevio logic for bot --- src/common/elevio.js | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/common/elevio.js diff --git a/src/common/elevio.js b/src/common/elevio.js new file mode 100644 index 0000000000..707fc3e57c --- /dev/null +++ b/src/common/elevio.js @@ -0,0 +1,56 @@ +import { generateLiveApiInstance } from './appId'; +import { getLanguage } from '../common/lang'; +import { getTokenList } from './utils/storageManager'; +import { translate } from '../common/i18n'; + +const Elevio = (() => { + const init = () => { + if (!window._elev) return; // eslint-disable-line no-underscore-dangle + window._elev.on('load', elev => { + // eslint-disable-line no-underscore-dangle + const availableElevLanguages = ['es', 'id', 'pt', 'ru']; + const currentLanguage = getLanguage().toLowerCase(); + if (availableElevLanguages.indexOf(currentLanguage) !== -1) { + window._elev.setLanguage(currentLanguage); // eslint-disable-line no-underscore-dangle + } + setUserInfo(elev); + setTranslations(elev); + }); + }; + + const setUserInfo = elev => { + const tokenList = getTokenList(); + if (tokenList.length) { + const api = generateLiveApiInstance(); // Refactor when reducing WS connections + const activeToken = tokenList[0]; + api.authorize(activeToken.token).then(() => { + api.send({ get_settings: 1 }).then(response => { + const isVirtual = activeToken.loginInfo.is_virtual; + const userObject = { + email : response.get_settings.email, + first_name: isVirtual ? 'Virtual' : response.get_settings.first_name, + last_name : isVirtual ? activeToken.loginInfo.loginid : response.get_settings.first_name, + user_hash : response.get_settings.user_hash, + }; + elev.setUser(userObject); + }); + }); + } + }; + + const setTranslations = elev => { + elev.setTranslations({ + modules: { + support: { + thankyou: translate('Thank you, we\'ll get back to you within 24 hours'), + }, + }, + }); + }; + + return { + init, + }; +})(); + +export default Elevio; From 2c0e1077ac54c009abb32e42c08dbe03d6285b62 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Mon, 14 Jan 2019 09:53:29 +0800 Subject: [PATCH 07/14] Logout Elevio user on logout & switching accounts --- src/botPage/view/View.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/botPage/view/View.js b/src/botPage/view/View.js index 5b49113b75..dbce8cb97d 100644 --- a/src/botPage/view/View.js +++ b/src/botPage/view/View.js @@ -374,6 +374,7 @@ export default class View { showPopup(getAccountSwitchPanelName()) .then(() => { this.stop(); + Elevio.logoutUser(); removeTokens(); }) .catch(() => {}); @@ -559,6 +560,7 @@ export default class View { showPopup(getAccountSwitchPanelName()) .then(() => { this.stop(); + Elevio.logoutUser(); const activeToken = $(e.currentTarget).attr('value'); const tokenList = getTokenList(); setStorage('tokenList', ''); From 40a5d6432f591ef12245d87a71eab60f7411a5c7 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Mon, 14 Jan 2019 09:58:48 +0800 Subject: [PATCH 08/14] Add Elevio import and re-order imports --- src/botPage/view/View.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/botPage/view/View.js b/src/botPage/view/View.js index dbce8cb97d..165f5a6645 100644 --- a/src/botPage/view/View.js +++ b/src/botPage/view/View.js @@ -1,30 +1,22 @@ import React from 'react'; import ReactDOM from 'react-dom'; import 'jquery-ui/ui/widgets/dialog'; -import { observer as globalObserver } from '../../common/utils/observer'; -import { - getTokenList, - removeAllTokens, - get as getStorage, - set as setStorage, - getToken, -} from '../../common/utils/storageManager'; import _Blockly from './blockly'; -import { translate } from '../../common/i18n'; -import Save from './Dialogs/Save'; +import Chart from './Dialogs/Chart'; import Limits from './Dialogs/Limits'; +import Save from './Dialogs/Save'; import TradingView from './Dialogs/TradingView'; -import Chart from './Dialogs/Chart'; -import { getLanguage } from '../../common/lang'; -import { roundBalance, isVirtual } from '../common/tools'; -import { symbolPromise } from './shared'; import logHandler from './logger'; -import Tour from './tour'; -import OfficialVersionWarning from './react-components/OfficialVersionWarning'; -import ServerTime from './react-components/HeaderWidgets'; -import NetworkMonitor from './NetworkMonitor'; import LogTable from './LogTable'; +import NetworkMonitor from './NetworkMonitor'; +import ServerTime from './react-components/HeaderWidgets'; +import OfficialVersionWarning from './react-components/OfficialVersionWarning'; +import { symbolPromise } from './shared'; +import Tour from './tour'; import TradeInfoPanel from './TradeInfoPanel'; +import Elevio from '../../common/elevio'; +import { updateConfigCurrencies } from '../common/const'; +import { roundBalance, isVirtual } from '../common/tools'; import { logoutAllTokens, getOAuthURL, @@ -32,8 +24,17 @@ import { AppConstants, addTokenIfValid, } from '../../common/appId'; +import { translate } from '../../common/i18n'; +import { getLanguage } from '../../common/lang'; +import { observer as globalObserver } from '../../common/utils/observer'; +import { + getTokenList, + removeAllTokens, + get as getStorage, + set as setStorage, + getToken, +} from '../../common/utils/storageManager'; import { isProduction } from '../../common/utils/tools'; -import { updateConfigCurrencies } from '../common/const'; let realityCheckTimeout; From 97b1bd7d72fb4ceaa88922e6755ff0034d38a667 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Mon, 14 Jan 2019 09:59:21 +0800 Subject: [PATCH 09/14] Logout Elevio user if token invalid --- src/common/appId.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/appId.js b/src/common/appId.js index 6a77f2dcf0..25cb80d32c 100644 --- a/src/common/appId.js +++ b/src/common/appId.js @@ -10,6 +10,7 @@ import { import { parseQueryString, isProduction, getExtension } from '../common/utils/tools'; import { getLanguage } from './lang'; import AppIdMap from './appIdResolver'; +import Elevio from './elevio'; export const AppConstants = Object.freeze({ STORAGE_ACTIVE_TOKEN: 'activeToken', @@ -114,9 +115,9 @@ export async function addTokenIfValid(token, tokenObjectList) { try { const { authorize } = await api.authorize(token); const { landing_company_name: lcName } = authorize; - const { landing_company_details: { has_reality_check: hasRealityCheck } } = await api.getLandingCompanyDetails( - lcName - ); + const { + landing_company_details: { has_reality_check: hasRealityCheck }, + } = await api.getLandingCompanyDetails(lcName); addToken(token, authorize, !!hasRealityCheck, ['iom', 'malta'].includes(lcName) && authorize.country === 'gb'); const { account_list: accountList } = authorize; @@ -132,6 +133,7 @@ export async function addTokenIfValid(token, tokenObjectList) { } } catch (e) { removeToken(tokenObjectList[0].token); + Elevio.logoutUser(); throw e; } return api.disconnect(); From 33aa59d5c76bc18c3fea06051e011af8c631b4c9 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Mon, 14 Jan 2019 10:00:05 +0800 Subject: [PATCH 10/14] Disconnect websocket and add logoutUser()-logic --- src/common/elevio.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/common/elevio.js b/src/common/elevio.js index 707fc3e57c..00623b47ed 100644 --- a/src/common/elevio.js +++ b/src/common/elevio.js @@ -33,11 +33,18 @@ const Elevio = (() => { user_hash : response.get_settings.user_hash, }; elev.setUser(userObject); + api.disconnect(); }); }); } }; + // Elevio has a window._elev.logoutUser() fn, but it doesn't work + const logoutUser = () => { + sessionStorage.removeItem('_elevaddon-6app'); + sessionStorage.removeItem('_elevaddon-6create'); + }; + const setTranslations = elev => { elev.setTranslations({ modules: { @@ -50,6 +57,7 @@ const Elevio = (() => { return { init, + logoutUser, }; })(); From 4d9976b8c65657b6e57ffc9dde9e052ebf16720e Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Mon, 14 Jan 2019 10:05:21 +0800 Subject: [PATCH 11/14] Add eslint ignore --- src/common/elevio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/elevio.js b/src/common/elevio.js index 00623b47ed..6d16264d4c 100644 --- a/src/common/elevio.js +++ b/src/common/elevio.js @@ -6,8 +6,8 @@ import { translate } from '../common/i18n'; const Elevio = (() => { const init = () => { if (!window._elev) return; // eslint-disable-line no-underscore-dangle + // eslint-disable-next-line no-underscore-dangle window._elev.on('load', elev => { - // eslint-disable-line no-underscore-dangle const availableElevLanguages = ['es', 'id', 'pt', 'ru']; const currentLanguage = getLanguage().toLowerCase(); if (availableElevLanguages.indexOf(currentLanguage) !== -1) { From 5852db0dc3dd22de02dedb5f4be58a143b63675c Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Tue, 22 Jan 2019 11:54:38 +0800 Subject: [PATCH 12/14] Comment out available_languages until translation-dependencies are resolved --- src/common/elevio.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/elevio.js b/src/common/elevio.js index 6d16264d4c..9231587bf7 100644 --- a/src/common/elevio.js +++ b/src/common/elevio.js @@ -8,11 +8,11 @@ const Elevio = (() => { if (!window._elev) return; // eslint-disable-line no-underscore-dangle // eslint-disable-next-line no-underscore-dangle window._elev.on('load', elev => { - const availableElevLanguages = ['es', 'id', 'pt', 'ru']; - const currentLanguage = getLanguage().toLowerCase(); - if (availableElevLanguages.indexOf(currentLanguage) !== -1) { - window._elev.setLanguage(currentLanguage); // eslint-disable-line no-underscore-dangle - } + // const availableElevLanguages = ['es', 'id', 'pt', 'ru']; + // const currentLanguage = getLanguage().toLowerCase(); + // if (availableElevLanguages.indexOf(currentLanguage) !== -1) { + // window._elev.setLanguage(currentLanguage); // eslint-disable-line no-underscore-dangle + // } setUserInfo(elev); setTranslations(elev); }); From 41a76e7108a77ea6f9ab06b1f64b91059b31365d Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Tue, 22 Jan 2019 11:57:39 +0800 Subject: [PATCH 13/14] Comment out import for eslint --- src/common/elevio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/elevio.js b/src/common/elevio.js index 9231587bf7..67d300a477 100644 --- a/src/common/elevio.js +++ b/src/common/elevio.js @@ -1,5 +1,5 @@ import { generateLiveApiInstance } from './appId'; -import { getLanguage } from '../common/lang'; +//import { getLanguage } from '../common/lang'; import { getTokenList } from './utils/storageManager'; import { translate } from '../common/i18n'; From b7b6f3e726f88b089821479f065a20e4130bd62b Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Tue, 22 Jan 2019 12:57:14 +0800 Subject: [PATCH 14/14] =?UTF-8?q?Eslint=20=F0=9F=99=83=F0=9F=94=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/elevio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/elevio.js b/src/common/elevio.js index 67d300a477..c1a6ad9f31 100644 --- a/src/common/elevio.js +++ b/src/common/elevio.js @@ -1,5 +1,5 @@ import { generateLiveApiInstance } from './appId'; -//import { getLanguage } from '../common/lang'; +// import { getLanguage } from '../common/lang'; import { getTokenList } from './utils/storageManager'; import { translate } from '../common/i18n';