From 30abbf68c4d10f08002ae8479c078cbcad5f29d3 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Tue, 8 Jan 2019 13:33:44 +0800 Subject: [PATCH 1/9] 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 2/9] 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 3/9] 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 4/9] 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 c6bca5fd5be51f0d09fe438aafba2d5670d47104 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 9 Jan 2019 17:21:35 +0800 Subject: [PATCH 5/9] 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 6/9] 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 7/9] 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 @@

+ +

+