Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
13 changes: 13 additions & 0 deletions src/botPage/view/blockly/blocks/tools/total_profit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
13 changes: 13 additions & 0 deletions src/botPage/view/blockly/blocks/tools/total_runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
1 change: 1 addition & 0 deletions src/botPage/view/blockly/blocks/trade/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Blockly.Blocks.trade = {
replaceInitializationBlocks(this, ev);
resetTradeFields(this, ev);
}

decorateTrade(ev);
},
};
Expand Down
21 changes: 21 additions & 0 deletions src/botPage/view/blockly/customBlockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};