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'); }, diff --git a/src/botPage/view/blockly/index.js b/src/botPage/view/blockly/index.js index 0f121ce01b..7028e169ff 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) { @@ -49,16 +50,46 @@ const disposeBlocksWithLoaders = () => { }); }; const loadWorkspace = xml => { + const marketsWereRemoved = !Array.from(xml.children).every(block => !removeUnavailableMarkets(block)); + if (marketsWereRemoved) { + $('#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'); + return; + } + Blockly.Events.setGroup('load'); Blockly.mainWorkspace.clear(); - Array.from(xml.children).forEach(block => backwardCompatibility(block)); + + Array.from(xml.children).forEach(block => { + backwardCompatibility(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); + globalObserver.emit('ui.log.success', translate('Blocks are loaded successfully')); }, e => { Blockly.Events.setGroup(false); diff --git a/src/botPage/view/blockly/utils.js b/src/botPage/view/blockly/utils.js index 152060fe54..760fb02d76 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,26 @@ 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 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); + } + }); + } + return containsUnavailableMarket; +}; + const getCollapsedProcedures = () => Blockly.mainWorkspace .getTopBlocks() diff --git a/templates/bot.mustache b/templates/bot.mustache index 1c3b907e2c..48faeff069 100644 --- a/templates/bot.mustache +++ b/templates/bot.mustache @@ -32,6 +32,9 @@
+