Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
},
Expand Down
45 changes: 38 additions & 7 deletions src/botPage/view/blockly/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 23 additions & 2 deletions src/botPage/view/blockly/utils.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions templates/bot.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<p style="margin:0.7em" data-i18n-text="Binary Bot will not place any new trades. Current unexpired trades will be completed by our system. All unsaved changes will be lost."></p>
<p style="margin:0.7em" data-i18n-text="Note: Please see the Binary.com statement page for details of all confirmed transactions."></p>
</span>
<span id="unavailableMarkets" class="draggable-dialog" title="Warning">
<p style="margin:0.7em" data-i18n-text="This strategy is not available in your country."></p>
</span>
<div>
<div class="blocker"></div>
<div class="reality-check" style="display: none">
Expand Down