diff --git a/src/botPage/bot/Interpreter.js b/src/botPage/bot/Interpreter.js index d6fbb51939..affa998278 100644 --- a/src/botPage/bot/Interpreter.js +++ b/src/botPage/bot/Interpreter.js @@ -10,6 +10,8 @@ const unrecoverableErrors = [ 'InvalidCurrency', 'ContractBuyValidationError', 'NotDefaultCurrency', + 'PleaseAuthenticate', + 'FinancialAssessmentRequired', ]; const botInitialized = bot => bot && bot.tradeEngine.options; const botStarted = bot => botInitialized(bot) && bot.tradeEngine.tradeOptions; diff --git a/src/botPage/bot/TradeEngine/Total.js b/src/botPage/bot/TradeEngine/Total.js index 68d389e2a3..355c7c6446 100644 --- a/src/botPage/bot/TradeEngine/Total.js +++ b/src/botPage/bot/TradeEngine/Total.js @@ -2,6 +2,7 @@ import { translate } from '../../../common/i18n'; import { roundBalance } from '../../common/tools'; import { info, notify } from '../broadcast'; import createError from '../../common/error'; +import { observer as globalObserver } from '../../../common/utils/observer'; const skeleton = { totalProfit: 0, @@ -20,6 +21,14 @@ export default Engine => super(); this.sessionRuns = 0; this.sessionProfit = 0; + + globalObserver.register('summary.clear', () => { + this.sessionRuns = 0; + this.sessionProfit = 0; + + const { loginid: accountID } = this.accountInfo; + globalStat[accountID] = { ...skeleton }; + }); } updateTotals(contract) { const { sell_price: sellPrice, buy_price: buyPrice, currency } = contract; @@ -87,7 +96,9 @@ export default Engine => return; } - const { limitations: { maxLoss, maxTrades } } = tradeOption; + const { + limitations: { maxLoss, maxTrades }, + } = tradeOption; if (maxLoss && maxTrades) { if (this.sessionRuns >= maxTrades) { diff --git a/src/botPage/bot/tools.js b/src/botPage/bot/tools.js index ae48022011..c55a722e72 100644 --- a/src/botPage/bot/tools.js +++ b/src/botPage/bot/tools.js @@ -157,3 +157,48 @@ export const createDetails = contract => { }; export const getUUID = () => `${new Date().getTime() * Math.random()}`; + +export const showDialog = options => + new Promise((resolve, reject) => { + const $dialog = $('
', { class: 'draggable-dialog', title: options.title }); + options.text.forEach(text => $dialog.append(`${text}
`)); + const defaultButtons = [ + { + text : translate('No'), + class: 'button-secondary', + click() { + $(this).dialog('close'); + $(this).remove(); + reject(); + }, + }, + { + text : translate('Yes'), + class: 'button-primary', + click() { + $(this).dialog('close'); + $(this).remove(); + resolve(); + }, + }, + ]; + const dialogOptions = { + autoOpen : false, + classes : { 'ui-dialog-titlebar-close': 'icon-close' }, + closeText: '', + height : 'auto', + width : 600, + modal : true, + resizable: false, + open() { + $(this) + .parent() + .find('.ui-dialog-buttonset > button') + .removeClass('ui-button ui-corner-all ui-widget'); + }, + }; + Object.assign(dialogOptions, { buttons: options.buttons || defaultButtons }); + + $dialog.dialog(dialogOptions); + $dialog.dialog('open'); + }); diff --git a/src/botPage/view/TradeInfoPanel/ClearButton.js b/src/botPage/view/TradeInfoPanel/ClearButton.js new file mode 100644 index 0000000000..66757e3cc8 --- /dev/null +++ b/src/botPage/view/TradeInfoPanel/ClearButton.js @@ -0,0 +1,39 @@ +import React from 'react'; +import { observer as globalObserver } from '../../../common/utils/observer'; +import { showDialog } from '../../bot/tools'; +import { translate } from '../../../common/utils/tools'; + +export default class ClearButton extends React.PureComponent { + constructor() { + super(); + this.state = { isButtonDisabled: true }; + } + componentDidMount() { + globalObserver.register('summary.enable_clear', () => this.setState({ isButtonDisabled: false })); + globalObserver.register('summary.disable_clear', () => this.setState({ isButtonDisabled: true })); + } + // eslint-disable-next-line class-methods-use-this + confirmClearLog() { + showDialog({ + title: translate('Are you sure?'), + text : [ + translate( + 'This will clear all transactions in the summary panel, and all counters will be reset to zero.' + ), + ], + }) + .then(() => globalObserver.emit('summary.clear')) + .catch(() => {}); + } + render() { + return ( + + ); + } +} diff --git a/src/botPage/view/TradeInfoPanel/RunButton.js b/src/botPage/view/TradeInfoPanel/RunButton.js index b820c2480a..74a73fbfbd 100644 --- a/src/botPage/view/TradeInfoPanel/RunButton.js +++ b/src/botPage/view/TradeInfoPanel/RunButton.js @@ -2,7 +2,7 @@ import React from 'react'; import { translate } from '../../../common/i18n'; const RunButton = () => ( -{translate( diff --git a/src/botPage/view/View.js b/src/botPage/view/View.js index 88cf9542fc..be027629c8 100644 --- a/src/botPage/view/View.js +++ b/src/botPage/view/View.js @@ -14,6 +14,7 @@ import OfficialVersionWarning from './react-components/OfficialVersionWarning'; import { symbolPromise } from './shared'; import Tour from './tour'; import TradeInfoPanel from './TradeInfoPanel'; +import { showDialog } from '../bot/tools'; import Elevio from '../../common/elevio'; import { updateConfigCurrencies } from '../common/const'; import { roundBalance, isVirtual } from '../common/tools'; @@ -220,41 +221,6 @@ const applyToolboxPermissions = () => { [fn](); }; -const showPopup = selector => - new Promise((resolve, reject) => { - setBeforeUnload(true); - $(selector).dialog({ - height: 'auto', - width : 600, - modal : true, - open() { - $(this) - .parent() - .find('.ui-dialog-buttonset > button') - .removeClass('ui-button ui-corner-all ui-widget'); - }, - buttons: [ - { - text : translate('No'), - class: 'button-secondary', - click() { - $(this).dialog('close'); - reject(); - }, - }, - { - text : translate('Yes'), - class: 'button-primary', - click() { - $(this).dialog('close'); - resolve(); - }, - }, - ], - }); - $(selector).dialog('open'); - }); - export default class View { constructor() { logHandler(); @@ -358,17 +324,25 @@ export default class View { this.stop(); }; - const removeTokens = () => { - logoutAllTokens().then(() => { - updateTokenList(); - globalObserver.emit('ui.log.info', translate('Logged you out!')); - clearRealityCheck(); - clearActiveTokens(); - window.location.reload(); - }); + const getAccountSwitchText = () => { + if (this.blockly.hasStarted()) { + return [ + translate( + 'Binary Bot will not place any new trades. Any trades already placed (but not expired) will be completed by our system. Any unsaved changes will be lost.' + ), + translate( + 'Note: Please see the Binary.com statement page for details of all confirmed transactions.' + ), + ]; + } + return [translate('Any unsaved changes will be lost.')]; }; + const logout = () => { - showPopup(getAccountSwitchPanelName()) + showDialog({ + title: translate('Are you sure?'), + text : getAccountSwitchText(), + }) .then(() => { this.stop(); Elevio.logoutUser(); @@ -377,14 +351,20 @@ export default class View { .catch(() => {}); }; + const removeTokens = () => { + logoutAllTokens().then(() => { + updateTokenList(); + globalObserver.emit('ui.log.info', translate('Logged you out!')); + clearRealityCheck(); + clearActiveTokens(); + window.location.reload(); + }); + }; + const clearActiveTokens = () => { 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() @@ -431,13 +411,16 @@ export default class View { $('#tradingViewButton').click(() => { tradingView.open(); }); + const exportContent = {}; exportContent.summaryPanel = () => { globalObserver.emit('summary.export'); }; + exportContent.logPanel = () => { globalObserver.emit('log.export'); }; + const addExportButtonToPanel = panelId => { const buttonHtml = ''; @@ -451,16 +434,16 @@ export default class View { }); } }; + const showSummary = () => { $('#summaryPanel').dialog('open'); addExportButtonToPanel('summaryPanel'); }; - const showLog = () => { + + $('#logButton').click(() => { $('#logPanel').dialog('open'); addExportButtonToPanel('logPanel'); - }; - - $('#logButton').click(showLog); + }); $('#showSummary').click(showSummary); @@ -516,6 +499,7 @@ export default class View { $('#stopButton, #summaryStopButton').show(); $('#runButton, #summaryRunButton').hide(); $('#runButton, #summaryRunButton').prop('disabled', true); + globalObserver.emit('summary.disable_clear'); showSummary(); this.blockly.run(limitations); }; @@ -546,7 +530,23 @@ export default class View { }); $('#resetButton').click(() => { - showPopup(getReloadPanelName()) + let dialogText; + if (this.blockly.hasStarted()) { + dialogText = [ + translate( + 'Binary Bot will not place any new trades. Any trades already placed (but not expired) will be completed by our system. Any unsaved changes will be lost.' + ), + translate( + 'Note: Please see the Binary.com statement page for details of all confirmed transactions.' + ), + ]; + } else { + dialogText = [translate('Any unsaved changes will be lost.')]; + } + showDialog({ + title: translate('Are you sure?'), + text : dialogText, + }) .then(() => { this.stop(); this.blockly.resetWorkspace(); @@ -556,7 +556,10 @@ export default class View { }); $('.login-id-list').on('click', 'a', e => { - showPopup(getAccountSwitchPanelName()) + showDialog({ + title: translate('Are you sure?'), + text : getAccountSwitchText(), + }) .then(() => { this.stop(); Elevio.logoutUser(); diff --git a/src/botPage/view/blockly/index.js b/src/botPage/view/blockly/index.js index 1ea3de507a..f446667107 100644 --- a/src/botPage/view/blockly/index.js +++ b/src/botPage/view/blockly/index.js @@ -19,6 +19,7 @@ import createError from '../../common/error'; import { translate, xml as translateXml } from '../../../common/i18n'; import { getLanguage } from '../../../common/lang'; import { observer as globalObserver } from '../../../common/utils/observer'; +import { showDialog } from '../../bot/tools'; const setBeforeUnload = off => { if (off) { @@ -52,16 +53,12 @@ const disposeBlocksWithLoaders = () => { }; const marketsWereRemoved = xml => { if (!Array.from(xml.children).every(block => !removeUnavailableMarkets(block))) { - $('#unavailableMarkets').dialog({ - height: 'auto', - width : 600, - modal : true, - open() { - $(this) - .parent() - .find('.ui-dialog-buttonset > button') - .removeClass('ui-button ui-corner-all ui-widget'); - }, + if (window.trackJs) { + trackJs.track('Invalid financial market'); + } + showDialog({ + title : translate('Warning'), + text : [translate('This strategy is not available in your country.')], buttons: [ { text : translate('OK'), @@ -71,11 +68,9 @@ const marketsWereRemoved = xml => { }, }, ], - }); - if (window.trackJs) { - trackJs.track('Invalid financial market'); - } - $('#unavailableMarkets').dialog('open'); + }) + .then(() => {}) + .catch(() => {}); return true; } return false; diff --git a/static/css/_fontello.scss b/static/css/_fontello.scss index d8b3e2eea9..01fa493b74 100755 --- a/static/css/_fontello.scss +++ b/static/css/_fontello.scss @@ -79,4 +79,13 @@ &.enabled { background: url("../image/expand_more.svg") no-repeat center; } -} \ No newline at end of file +} +.icon-clear { + &:before { + content: ' '; + } + background: url("../image/clear.svg") no-repeat center; + &:disabled { + background: url("../image/clear-disabled.svg") no-repeat center; + } +} diff --git a/static/css/_panel.scss b/static/css/_panel.scss index 5b511f59be..b0c85397ad 100644 --- a/static/css/_panel.scss +++ b/static/css/_panel.scss @@ -187,6 +187,7 @@ $disabled-color: #F2F2F2; } .summary-toolbox { text-align: center; + position: relative; .toolbox-button { border-radius: 50%; @@ -202,6 +203,10 @@ $disabled-color: #F2F2F2; .toolbox-button:focus { @include toolbox-button-focus; } + #summaryClearButton { + position: absolute; + right: 10px; + } } } diff --git a/static/css/bot.scss b/static/css/bot.scss index b565a92e0a..a4a2063f26 100644 --- a/static/css/bot.scss +++ b/static/css/bot.scss @@ -18,7 +18,6 @@ body { margin: 0em; max-width: 100%; max-height: 100%; - overflow: auto; font-size: 1em; } diff --git a/static/image/clear-disabled.svg b/static/image/clear-disabled.svg new file mode 100644 index 0000000000..90d4f12995 --- /dev/null +++ b/static/image/clear-disabled.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/image/clear.svg b/static/image/clear.svg new file mode 100644 index 0000000000..592c8f0af1 --- /dev/null +++ b/static/image/clear.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/templates/bot.mustache b/templates/bot.mustache index 35cf95867a..339b21e47d 100644 --- a/templates/bot.mustache +++ b/templates/bot.mustache @@ -20,22 +20,7 @@ - - - - - - - - - - - - - - +