From 30abbf68c4d10f08002ae8479c078cbcad5f29d3 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Tue, 8 Jan 2019 13:33:44 +0800 Subject: [PATCH 01/22] Restore original code from before singapore-fix to allow for correctly loading of blocks --- src/botPage/view/blockly/blocks/trade/backwardCompatibility.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/botPage/view/blockly/blocks/trade/backwardCompatibility.js b/src/botPage/view/blockly/blocks/trade/backwardCompatibility.js index cf6e2bb250..89df0052de 100644 --- a/src/botPage/view/blockly/blocks/trade/backwardCompatibility.js +++ b/src/botPage/view/blockly/blocks/trade/backwardCompatibility.js @@ -46,6 +46,9 @@ export default () => { init: function init() { duration(this); payout(this); + prediction(this); + barrierOffset(this); + secondBarrierOffset(this); this.setInputsInline(false); this.setPreviousStatement(true, 'Condition'); }, From ddb6f79fcd1128ab0123c9ed18f11d1d61d5635e Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Tue, 8 Jan 2019 18:00:52 +0800 Subject: [PATCH 02/22] Pass each block through removeUnavailableMarkets() and re-order imports --- src/botPage/view/blockly/index.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/botPage/view/blockly/index.js b/src/botPage/view/blockly/index.js index 0f121ce01b..b02cc41743 100644 --- a/src/botPage/view/blockly/index.js +++ b/src/botPage/view/blockly/index.js @@ -1,6 +1,5 @@ -import { observer as globalObserver } from '../../../common/utils/observer'; -import { translate, xml as translateXml } from '../../../common/i18n'; -import createError from '../../common/error'; +import './customBlockly'; +import blocks from './blocks'; import { isMainBlock, save, @@ -12,11 +11,13 @@ import { backwardCompatibility, fixCollapsedBlocks, fixArgumentAttribute, + removeUnavailableMarkets, } from './utils'; -import blocks from './blocks'; import Interpreter from '../../bot/Interpreter'; +import createError from '../../common/error'; +import { translate, xml as translateXml } from '../../../common/i18n'; import { getLanguage } from '../../../common/lang'; -import './customBlockly'; +import { observer as globalObserver } from '../../../common/utils/observer'; const setBeforeUnload = off => { if (off) { @@ -51,7 +52,10 @@ const disposeBlocksWithLoaders = () => { const loadWorkspace = xml => { Blockly.Events.setGroup('load'); Blockly.mainWorkspace.clear(); - Array.from(xml.children).forEach(block => backwardCompatibility(block)); + Array.from(xml.children).forEach(block => { + backwardCompatibility(block); + removeUnavailableMarkets(block); + }); fixArgumentAttribute(xml); Blockly.Xml.domToWorkspace(xml, Blockly.mainWorkspace); addLoadersFirst(xml).then( From 3408742e9229503263778fe8819dbd28b8a4fa6b Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Tue, 8 Jan 2019 18:02:08 +0800 Subject: [PATCH 03/22] add removeUnavailableMarkets() function --- src/botPage/view/blockly/utils.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/botPage/view/blockly/utils.js b/src/botPage/view/blockly/utils.js index 152060fe54..3bd041378e 100644 --- a/src/botPage/view/blockly/utils.js +++ b/src/botPage/view/blockly/utils.js @@ -1,7 +1,8 @@ -import { observer as globalObserver } from '../../../common/utils/observer'; +import { fieldGeneratorMapping } from './blocks/shared'; +import { saveAs } from '../shared'; import config from '../../common/const'; import { translate } from '../../../common/i18n'; -import { saveAs } from '../shared'; +import { observer as globalObserver } from '../../../common/utils/observer'; export const isMainBlock = blockType => config.mainBlocks.indexOf(blockType) >= 0; @@ -25,6 +26,28 @@ export const backwardCompatibility = block => { } }; +export const removeUnavailableMarkets = block => { + const containsUnavailableMarket = () => + Array.from(block.getElementsByTagName('field')).some(field => { + if (field.getAttribute('name') === 'MARKET_LIST') { + const availableMarkets = fieldGeneratorMapping.MARKET_LIST().map(markets => markets[1]); + return !availableMarkets.includes(field.innerText); + } + }); + if (containsUnavailableMarket()) { + const nodes_to_remove = ['MARKET_LIST', 'SUBMARKET_LIST', 'SYMBOL_LIST', 'TRADETYPECAT_LIST', 'TRADETYPE_LIST']; + Array.from(block.getElementsByTagName('field')).forEach(field => { + if (nodes_to_remove.includes(field.getAttribute('name'))) { + block.removeChild(field); + } + }); + globalObserver.emit( + 'ui.log.info', + translate('The markets for this strategy have been defaulted as they\'re not available in your jurisdiction') + ); + } +}; + const getCollapsedProcedures = () => Blockly.mainWorkspace .getTopBlocks() From 5775ab7160698e644b18c464a223b2f34782d6c5 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Tue, 8 Jan 2019 18:16:14 +0800 Subject: [PATCH 04/22] Fix linting errors --- src/botPage/view/blockly/utils.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/botPage/view/blockly/utils.js b/src/botPage/view/blockly/utils.js index 3bd041378e..459c43d993 100644 --- a/src/botPage/view/blockly/utils.js +++ b/src/botPage/view/blockly/utils.js @@ -28,16 +28,18 @@ export const backwardCompatibility = block => { export const removeUnavailableMarkets = block => { const containsUnavailableMarket = () => - Array.from(block.getElementsByTagName('field')).some(field => { - if (field.getAttribute('name') === 'MARKET_LIST') { - const availableMarkets = fieldGeneratorMapping.MARKET_LIST().map(markets => markets[1]); - return !availableMarkets.includes(field.innerText); - } - }); + Array.from(block.getElementsByTagName('field')).some( + field => + field.getAttribute('name') === 'MARKET_LIST' && + !fieldGeneratorMapping + .MARKET_LIST() + .map(markets => markets[1]) + .includes(field.innerText) + ); if (containsUnavailableMarket()) { - const nodes_to_remove = ['MARKET_LIST', 'SUBMARKET_LIST', 'SYMBOL_LIST', 'TRADETYPECAT_LIST', 'TRADETYPE_LIST']; + const nodesToRemove = ['MARKET_LIST', 'SUBMARKET_LIST', 'SYMBOL_LIST', 'TRADETYPECAT_LIST', 'TRADETYPE_LIST']; Array.from(block.getElementsByTagName('field')).forEach(field => { - if (nodes_to_remove.includes(field.getAttribute('name'))) { + if (nodesToRemove.includes(field.getAttribute('name'))) { block.removeChild(field); } }); From 50ee0e09e0cc549cf60aff4d85d5152b0200a5b0 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 9 Jan 2019 13:54:56 +0800 Subject: [PATCH 05/22] Refactor and add separator logic to applyToolboxPermissions --- src/botPage/view/View.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/botPage/view/View.js b/src/botPage/view/View.js index b5e098a91f..5b49113b75 100644 --- a/src/botPage/view/View.js +++ b/src/botPage/view/View.js @@ -60,7 +60,9 @@ api.send({ time: '1' }).then(response => { }); api.events.on('balance', response => { - const { balance: { balance: b, currency } } = response; + const { + balance: { balance: b, currency }, + } = response; const balance = (+roundBalance({ currency, balance: b })).toLocaleString(getLanguage().replace('_', '-')); $('.topMenuBalance').text(`${balance} ${currency}`); @@ -215,15 +217,11 @@ const updateTokenList = () => { }; const applyToolboxPermissions = () => { - if (getTokenList().length) { - $('#runButton').show(); - $('#showSummary').show(); - $('#logButton').show(); - } else { - $('#runButton').hide(); - $('#showSummary').hide(); - $('#logButton').hide(); - } + const fn = getTokenList().length ? 'show' : 'hide'; + $('#runButton, #showSummary, #logButton') + [fn]() + .prevAll('.toolbox-separator:first') + [fn](); }; const showPopup = selector => From 5d37d8b48e19010aa9a9288dd8b6a93a99646ac2 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 9 Jan 2019 13:55:49 +0800 Subject: [PATCH 06/22] Remove stroke so lines don't overlap with top toolbar --- static/css/_blockly-toolbox.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/static/css/_blockly-toolbox.scss b/static/css/_blockly-toolbox.scss index 977227ca3b..b496c212fd 100644 --- a/static/css/_blockly-toolbox.scss +++ b/static/css/_blockly-toolbox.scss @@ -92,3 +92,7 @@ .blocklySvg { position: absolute; } + +.blocklyMainBackground { + stroke: none; +} From ddf50fe53e45cd36046b9beed21c27254bbc425c Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 9 Jan 2019 13:56:14 +0800 Subject: [PATCH 07/22] Add rules for toolbox-separator --- static/css/_toolbox.scss | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/static/css/_toolbox.scss b/static/css/_toolbox.scss index 60cef28fa6..31e79496dc 100644 --- a/static/css/_toolbox.scss +++ b/static/css/_toolbox.scss @@ -12,8 +12,8 @@ } @mixin toolbox-runButton-disabled { - background-color: #f2f2f2; - color: #dedede; + background-color: $brand-gray; + color: $brand-dark-gray; } @mixin toolbox-runButton-hover { @@ -21,20 +21,15 @@ } #toolbox { - position: absolute; - z-index: 99; - right: 0; - width: 4em; - text-align: center; - padding: 2px 10px; + background-color: $brand-gray; + border-bottom: 1px solid $brand-dark-gray; + padding: 2px 3px; #runButton[disabled], #runButton[disabled]:hover { @include toolbox-runButton-disabled; } .toolbox-button { - float: right; - margin-bottom: 0.313em; @include toolbox-button-base; } @@ -49,4 +44,13 @@ .box.is-dragover { background-color: grey; } + + .toolbox-separator { + background-color: $brand-dark-gray; + display: inline-block; + height: 15px; + margin: 0 5px; + user-select: none; + width: 2px; + } } From ee1f96eb001b77a091fa2602c91d57fd4a416b80 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 9 Jan 2019 13:56:56 +0800 Subject: [PATCH 08/22] Move toolbox to top --- templates/bot.mustache | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/templates/bot.mustache b/templates/bot.mustache index 1c3b907e2c..67d199bb24 100644 --- a/templates/bot.mustache +++ b/templates/bot.mustache @@ -116,28 +116,36 @@ -
-
- - -
+
+ + + + + + + + + -
+
+
+ + From 1a38b836a3e4a52b740201b59bf0db4c4e3f84bf Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 9 Jan 2019 15:12:44 +0800 Subject: [PATCH 09/22] Attach 'Bot controls' tour-step to button for correct positioning --- src/botPage/view/tour/welcome.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/botPage/view/tour/welcome.js b/src/botPage/view/tour/welcome.js index abcdb48053..e78c9fc093 100644 --- a/src/botPage/view/tour/welcome.js +++ b/src/botPage/view/tour/welcome.js @@ -62,7 +62,7 @@ const steps = [ text : `

${translate('Control your blocks. Hold the cursor on each button for more info.')}

`, - selector: '#toolbox', + selector: '#zoomIn', position: 'left', }, { From c6bca5fd5be51f0d09fe438aafba2d5670d47104 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 9 Jan 2019 17:21:35 +0800 Subject: [PATCH 10/22] Show dialog when user imports strategy with unavailable financial market --- src/botPage/view/blockly/index.js | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/botPage/view/blockly/index.js b/src/botPage/view/blockly/index.js index b02cc41743..7e0eb53b29 100644 --- a/src/botPage/view/blockly/index.js +++ b/src/botPage/view/blockly/index.js @@ -52,17 +52,45 @@ const disposeBlocksWithLoaders = () => { const loadWorkspace = xml => { Blockly.Events.setGroup('load'); Blockly.mainWorkspace.clear(); + Array.from(xml.children).forEach(block => { backwardCompatibility(block); - removeUnavailableMarkets(block); }); + + const marketsWereRemoved = !Array.from(xml.children).every(block => !removeUnavailableMarkets(block)); + fixArgumentAttribute(xml); Blockly.Xml.domToWorkspace(xml, Blockly.mainWorkspace); addLoadersFirst(xml).then( () => { fixCollapsedBlocks(); - globalObserver.emit('ui.log.success', translate('Blocks are loaded successfully')); Blockly.Events.setGroup(false); + if (marketsWereRemoved) { + // Inform user strategy was partially loaded + $('#unavailableMarkets').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('OK'), + class: 'button-primary', + click() { + $(this).dialog('close'); + }, + }, + ], + }); + $('#unavailableMarkets').dialog('open'); + } else { + globalObserver.emit('ui.log.success', translate('Blocks are loaded successfully')); + } }, e => { Blockly.Events.setGroup(false); From 69dbcac35d001126c065376109c899af63372d53 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 9 Jan 2019 17:22:13 +0800 Subject: [PATCH 11/22] Refactor removeUnavailableMarkets(), also return boolean --- src/botPage/view/blockly/utils.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/botPage/view/blockly/utils.js b/src/botPage/view/blockly/utils.js index 459c43d993..760fb02d76 100644 --- a/src/botPage/view/blockly/utils.js +++ b/src/botPage/view/blockly/utils.js @@ -27,27 +27,23 @@ export const backwardCompatibility = block => { }; export const removeUnavailableMarkets = block => { - const containsUnavailableMarket = () => - Array.from(block.getElementsByTagName('field')).some( - field => - field.getAttribute('name') === 'MARKET_LIST' && - !fieldGeneratorMapping - .MARKET_LIST() - .map(markets => markets[1]) - .includes(field.innerText) - ); - if (containsUnavailableMarket()) { + const containsUnavailableMarket = Array.from(block.getElementsByTagName('field')).some( + field => + field.getAttribute('name') === 'MARKET_LIST' && + !fieldGeneratorMapping + .MARKET_LIST() + .map(markets => markets[1]) + .includes(field.innerText) + ); + if (containsUnavailableMarket) { const nodesToRemove = ['MARKET_LIST', 'SUBMARKET_LIST', 'SYMBOL_LIST', 'TRADETYPECAT_LIST', 'TRADETYPE_LIST']; Array.from(block.getElementsByTagName('field')).forEach(field => { if (nodesToRemove.includes(field.getAttribute('name'))) { block.removeChild(field); } }); - globalObserver.emit( - 'ui.log.info', - translate('The markets for this strategy have been defaulted as they\'re not available in your jurisdiction') - ); } + return containsUnavailableMarket; }; const getCollapsedProcedures = () => From 276369a94223586aebbd038b7939e1f35614817a Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 9 Jan 2019 17:22:46 +0800 Subject: [PATCH 12/22] Add dialog for users trying to load xml with unavailable financial market --- templates/bot.mustache | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/bot.mustache b/templates/bot.mustache index 1c3b907e2c..fcff3a3695 100644 --- a/templates/bot.mustache +++ b/templates/bot.mustache @@ -32,6 +32,9 @@

+ +

+
-
+