diff --git a/src/botPage/view/blockly/blocks/tools/total_profit.js b/src/botPage/view/blockly/blocks/tools/total_profit.js index 87adb27986..57aab906da 100644 --- a/src/botPage/view/blockly/blocks/tools/total_profit.js +++ b/src/botPage/view/blockly/blocks/tools/total_profit.js @@ -9,5 +9,18 @@ Blockly.Blocks.total_profit = { this.setTooltip(translate('Returns the total profit')); this.setHelpUrl('https://github.com/binary-com/binary-bot/wiki'); }, + onchange: function onchange(ev) { + if (!this.workspace || this.isInFlyout || this.workspace.isDragging()) { + return; + } + + if (ev.type === Blockly.Events.MOVE) { + const inputStatement = this.getRootInputTargetBlock(); + + if (inputStatement === 'INITIALIZATION') { + this.unplug(true); + } + } + }, }; Blockly.JavaScript.total_profit = () => ['Bot.getTotalProfit()', Blockly.JavaScript.ORDER_ATOMIC]; diff --git a/src/botPage/view/blockly/blocks/tools/total_runs.js b/src/botPage/view/blockly/blocks/tools/total_runs.js index 1bf170b3d2..e6b1e9f6f0 100644 --- a/src/botPage/view/blockly/blocks/tools/total_runs.js +++ b/src/botPage/view/blockly/blocks/tools/total_runs.js @@ -9,5 +9,18 @@ Blockly.Blocks.total_runs = { this.setTooltip(translate('Returns the number of runs since the beginning')); this.setHelpUrl('https://github.com/binary-com/binary-bot/wiki'); }, + onchange: function onchange(ev) { + if (!this.workspace || this.isInFlyout || this.workspace.isDragging()) { + return; + } + + if (ev.type === Blockly.Events.MOVE) { + const inputStatement = this.getRootInputTargetBlock(); + + if (inputStatement === 'INITIALIZATION') { + this.unplug(true); + } + } + }, }; Blockly.JavaScript.total_runs = () => ['Bot.getTotalRuns()', Blockly.JavaScript.ORDER_ATOMIC]; diff --git a/src/botPage/view/blockly/blocks/trade/index.js b/src/botPage/view/blockly/blocks/trade/index.js index 9468c61588..77dc0f9139 100644 --- a/src/botPage/view/blockly/blocks/trade/index.js +++ b/src/botPage/view/blockly/blocks/trade/index.js @@ -106,6 +106,7 @@ Blockly.Blocks.trade = { replaceInitializationBlocks(this, ev); resetTradeFields(this, ev); } + decorateTrade(ev); }, }; diff --git a/src/botPage/view/blockly/customBlockly.js b/src/botPage/view/blockly/customBlockly.js index b4f75f1cec..a2da174a43 100644 --- a/src/botPage/view/blockly/customBlockly.js +++ b/src/botPage/view/blockly/customBlockly.js @@ -403,3 +403,24 @@ const originalCustomContextLoopFn = Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN.customContextMenu = function(options) { addDownloadOption(originalCustomContextLoopFn.bind(this), options, this); }; + +/** + * Return the parent block or null if this block is at the top level. + * @return {Blockly.Block} The block that holds the current block. + */ +Blockly.Block.prototype.getRootInputTargetBlock = function() { + let inputName; + let currentBlock = this.getParent(); + + while (currentBlock) { + const rootBlock = this.getRootBlock(); + const currentInput = rootBlock.getInputWithBlock(currentBlock); + + if (currentInput && currentInput.name) { + inputName = currentInput.name; + } + currentBlock = currentBlock.getParent(); + } + + return inputName; +};