diff --git a/src/botPage/bot/Interpreter.js b/src/botPage/bot/Interpreter.js index 7c852b8617..d6fbb51939 100644 --- a/src/botPage/bot/Interpreter.js +++ b/src/botPage/bot/Interpreter.js @@ -156,4 +156,7 @@ export default class Interpreter { .catch(e => this.$scope.observer.emit('Error', e)); }); } + hasStarted() { + return !this.stopped; + } } diff --git a/src/botPage/common/ChartTicksService.js b/src/botPage/common/ChartTicksService.js index e592ca5f9c..6a0bf433d7 100644 --- a/src/botPage/common/ChartTicksService.js +++ b/src/botPage/common/ChartTicksService.js @@ -4,9 +4,7 @@ import TicksService from './TicksService'; export default class ChartTicksService extends TicksService { observe() { this.api.events.on('tick', r => { - const { - tick: { symbol, id }, - } = r; + const { tick: { symbol, id } } = r; if (this.ticks.has(symbol)) { this.subscriptions = this.subscriptions.setIn(['tick', symbol], id); @@ -15,9 +13,7 @@ export default class ChartTicksService extends TicksService { }); this.api.events.on('ohlc', r => { - const { - ohlc: { symbol, granularity, id }, - } = r; + const { ohlc: { symbol, granularity, id } } = r; if (this.candles.hasIn([symbol, Number(granularity)])) { this.subscriptions = this.subscriptions.setIn(['ohlc', symbol, Number(granularity)], id); diff --git a/src/botPage/common/TicksService.js b/src/botPage/common/TicksService.js index 214549442b..507d3b26ca 100644 --- a/src/botPage/common/TicksService.js +++ b/src/botPage/common/TicksService.js @@ -173,10 +173,7 @@ export default class TicksService { } observe() { this.api.events.on('tick', r => { - const { - tick, - tick: { symbol, id }, - } = r; + const { tick, tick: { symbol, id } } = r; if (this.ticks.has(symbol)) { this.subscriptions = this.subscriptions.setIn(['tick', symbol], id); @@ -185,10 +182,7 @@ export default class TicksService { }); this.api.events.on('ohlc', r => { - const { - ohlc, - ohlc: { symbol, granularity, id }, - } = r; + const { ohlc, ohlc: { symbol, granularity, id } } = r; if (this.candles.hasIn([symbol, Number(granularity)])) { this.subscriptions = this.subscriptions.setIn(['ohlc', symbol, Number(granularity)], id); diff --git a/src/botPage/view/View.js b/src/botPage/view/View.js index f7b89c6035..b5e098a91f 100644 --- a/src/botPage/view/View.js +++ b/src/botPage/view/View.js @@ -226,10 +226,10 @@ const applyToolboxPermissions = () => { } }; -const showReloadPopup = () => +const showPopup = selector => new Promise((resolve, reject) => { setBeforeUnload(true); - $('#reloadPanel').dialog({ + $(selector).dialog({ height: 'auto', width : 600, modal : true, @@ -258,7 +258,7 @@ const showReloadPopup = () => }, ], }); - $('#reloadPanel').dialog('open'); + $(selector).dialog('open'); }); export default class View { @@ -373,8 +373,9 @@ export default class View { }); }; const logout = () => { - showReloadPopup() + showPopup(getAccountSwitchPanelName()) .then(() => { + this.stop(); removeTokens(); }) .catch(() => {}); @@ -384,6 +385,10 @@ export default class View { setStorage(AppConstants.STORAGE_ACTIVE_TOKEN, ''); }; + const getReloadPanelName = () => (this.blockly.hasStarted() ? '#reloadPanelTrading' : '#reloadPanel'); + const getAccountSwitchPanelName = () => + this.blockly.hasStarted() ? '#switchAccountPanelTrading' : '#reloadPanel'; + $('.panelExitButton').click(function onClick() { $(this) .parent() @@ -468,6 +473,7 @@ export default class View { }); $('#logout').click(() => { + setBeforeUnload(true); logout(); hideRealityCheck(); }); @@ -542,13 +548,19 @@ export default class View { }); $('#resetButton').click(() => { - this.blockly.resetWorkspace(); - setTimeout(() => this.blockly.cleanUp(), 0); + showPopup(getReloadPanelName()) + .then(() => { + this.stop(); + this.blockly.resetWorkspace(); + setTimeout(() => this.blockly.cleanUp(), 0); + }) + .catch(() => {}); }); $('.login-id-list').on('click', 'a', e => { - showReloadPopup() + showPopup(getAccountSwitchPanelName()) .then(() => { + this.stop(); const activeToken = $(e.currentTarget).attr('value'); const tokenList = getTokenList(); setStorage('tokenList', ''); @@ -562,9 +574,10 @@ export default class View { $('#login') .bind('click.login', () => { + setBeforeUnload(true); document.location = getOAuthURL(); }) - .text('Log in'); + .text(translate('Log in')); $('#statement-reality-check').click(() => { document.location = `https://www.binary.com/${getLanguage()}/user/statementws.html#no-reality-check`; diff --git a/src/botPage/view/blockly/index.js b/src/botPage/view/blockly/index.js index 124679908d..0f121ce01b 100644 --- a/src/botPage/view/blockly/index.js +++ b/src/botPage/view/blockly/index.js @@ -349,8 +349,12 @@ while(true) { } stop(stopBeforeStart) { if (!stopBeforeStart) { - $('#runButton, #summaryRunButton').show(); - $('#stopButton, #summaryStopButton').hide(); + const $runButtons = $('#runButton, #summaryRunButton'); + const $stopButtons = $('#stopButton, #summaryStopButton'); + if ($runButtons.is(':visible') || $stopButtons.is(':visible')) { + $runButtons.show(); + $stopButtons.hide(); + } } if (this.interpreter) { this.interpreter.stop(); @@ -367,5 +371,9 @@ while(true) { redo() { Blockly.mainWorkspace.undo(true); } + /* eslint-disable class-methods-use-this */ + hasStarted() { + return this.interpreter && this.interpreter.hasStarted(); + } /* eslint-enable */ } diff --git a/src/botPage/view/tour/index.js b/src/botPage/view/tour/index.js index 81aa7eeabf..1d5e832432 100644 --- a/src/botPage/view/tour/index.js +++ b/src/botPage/view/tour/index.js @@ -1,6 +1,6 @@ import React, { PureComponent } from 'react'; import Joyride from 'react-joyride'; -import { setDone, isDone } from '../../../common/utils/storageManager'; +import { set as setStorage, get as getStorage, setDone, isDone } from '../../../common/utils/storageManager'; import { translate } from '../../../common/i18n'; import welcome from './welcome'; @@ -24,6 +24,7 @@ class Tour extends PureComponent { next: () => this.joyride.next(), stop: () => { setDoneCheck(); + setStorage('closedTourPopup', Date.now()); this.joyride.stop(); }, }; @@ -35,8 +36,13 @@ class Tour extends PureComponent { setDoneCheck(); } }; + const shouldShowTourPopup = () => { + const dayHasPassed = () => + Date.now() > (parseInt(getStorage('closedTourPopup')) || 0) + 24 * 60 * 60 * 1000; + return !isDone('welcomeFinished') && dayHasPassed(); + }; return ( - !isDone('welcomeFinished') && ( + shouldShowTourPopup() && (