diff --git a/gulpfile.js b/gulpfile.js index cb4b92c8f7..88fe7594ca 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -113,7 +113,8 @@ gulp.task('mocha', () => { gulp.task('test', ['mocha'], function() { return gulp.src(['./src/**/*.js', '!./src/**/*.min.js']) .pipe(jshint()) - .pipe(jshint.reporter('default')); + .pipe(jshint.reporter('default')) + .pipe(jshint.reporter('fail')); }); gulp.task('i18n-xml', ['static'], function () { @@ -248,9 +249,7 @@ gulp.task('build-min', ['build-bot-min', 'build-index-min', 'pack-css-min', 'mus gulp.task('deploy', ['build-min'], function () { return gulp.src(['404.md', 'LICENSE', 'README.md', 'CNAME', './www/**']) - .pipe(ghPages({ - branch: 'master' - })); + .pipe(ghPages()); }); gulp.task('serve', ['open', 'connect'], function () { diff --git a/src/bot/definitions/conditions/ticktrades.js b/src/bot/definitions/conditions/ticktrades.js index 661d209618..c131d1a674 100644 --- a/src/bot/definitions/conditions/ticktrades.js +++ b/src/bot/definitions/conditions/ticktrades.js @@ -1,4 +1,4 @@ -// https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#cur8so +// https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#zuc7w9 var blockly = require('blockly'); var i18n = require('i18n'); var config = require('../../globals/config'); @@ -10,13 +10,15 @@ Object.keys(config.opposites).forEach(function(opposites){ init: function() { var option_names = []; config.opposites[opposites].forEach(function(options){ - var option_alias = Object.keys(options)[0]; var option_name = options[option_alias]; option_names.push(option_name); }); this.appendDummyInput() - .appendField(option_names[0] + '/' + option_names[1]); + .setAlign(Blockly.ALIGN_CENTRE) + .appendField(utils.getCategoryName(opposites)); + this.appendDummyInput() + .appendField('> ' + option_names[0] + '/' + option_names[1]); this.appendValueInput("DURATION") .setCheck("Number") .appendField(i18n._("Ticks:")); diff --git a/src/bot/definitions/markets/index.js b/src/bot/definitions/markets/index.js index 9bd89a543c..51106cc3e7 100644 --- a/src/bot/definitions/markets/index.js +++ b/src/bot/definitions/markets/index.js @@ -1,7 +1,8 @@ -// https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#abpy8a +// https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#zr2375 var blockly = require('blockly'); var i18n = require('i18n'); var globals = require('../../globals/globals'); +var botUtils = require('../../utils/utils'); var relationChecker = require('../../utils/relationChecker'); var symbolNames = globals.activeSymbols.getSymbolNames(); Object.keys(symbolNames).forEach(function(symbol){ @@ -9,9 +10,11 @@ Object.keys(symbolNames).forEach(function(symbol){ init: function() { this.appendDummyInput() .appendField(symbolNames[symbol]); + this.appendDummyInput() + .appendField(i18n._('Accepts') + ': (' + botUtils.getAllowedCategoryNames(symbol) + ')'); this.appendStatementInput("CONDITION") .setCheck("Condition"); - this.setInputsInline(true); + this.setInputsInline(false); this.setPreviousStatement(true, "Submarket"); this.setColour(345); this.setTooltip(i18n._('Chooses the symbol:') + ' ' + symbolNames[symbol]); diff --git a/src/bot/globals/config.js b/src/bot/globals/config.js index e5da45826d..92de2d7992 100644 --- a/src/bot/globals/config.js +++ b/src/bot/globals/config.js @@ -28,19 +28,19 @@ module.exports = { [i18n._('Loss'), 'loss'], ], CHECK_DIRECTION: [ - [i18n._('Up'), 'up'], - [i18n._('Down'), 'down'], + [i18n._('Rise'), 'rise'], + [i18n._('Fall'), 'fall'], [i18n._('No Change'), ''], ], }, opposites: { - UPDOWN: [{ - 'CALL': i18n._('Up') + RISEFALL: [{ + 'CALL': i18n._('Rise') }, { - 'PUT': i18n._('Down') + 'PUT': i18n._('Fall') }], - ASIAN: [{ + ASIANS: [{ 'ASIANU': i18n._('Asian Up') }, { 'ASIAND': i18n._('Asian Down') @@ -61,15 +61,19 @@ module.exports = { 'DIGITUNDER': i18n._('Under') }], }, - opposites_have_barrier: [ 'MATCHESDIFFERS', 'OVERUNDER', ], conditionsCategory: { - callput: ['updown'], - asian: ['asian'], + callput: ['risefall'], + asian: ['asians'], digits: ['matchesdiffers', 'evenodd', 'overunder'] }, - conditions: ['updown', 'asian', 'matchesdiffers', 'evenodd', 'overunder'], + conditionsCategoryName: { + callput: i18n._('Up/Down'), + asian: i18n._('Asians'), + digits: i18n._('Digits'), + }, + conditions: ['risefall', 'asians', 'matchesdiffers', 'evenodd', 'overunder'], }; diff --git a/src/bot/tours/welcome.js b/src/bot/tours/welcome.js index 8835b7d149..50a763e741 100644 --- a/src/bot/tours/welcome.js +++ b/src/bot/tours/welcome.js @@ -156,8 +156,10 @@ module.exports = { started = true; globals.tour = tour; globals.tour.start(); + return true; } } + return false; }, stop: function stop() { view.setOpacityForAll(true, 1); diff --git a/src/bot/trade/trade.js b/src/bot/trade/trade.js index f9e8606407..4e6f649bf2 100644 --- a/src/bot/trade/trade.js +++ b/src/bot/trade/trade.js @@ -82,10 +82,10 @@ var callStrategy = function callStrategy() { if (ticks.length > 1) { if (+ticks.slice(-1)[0].quote > +ticks.slice(-2) .quote) { - direction = 'up'; + direction = 'rise'; } else if (+ticks.slice(-1)[0].quote < +ticks.slice(-2) .quote) { - direction = 'down'; + direction = 'fall'; } } globals.on_strategy(+ticks.slice(-1)[0].quote, direction); diff --git a/src/bot/utils/__tests__/active_symbols.js b/src/bot/utils/__tests__/active_symbols.js index d42393a904..faf18ca748 100644 --- a/src/bot/utils/__tests__/active_symbols.js +++ b/src/bot/utils/__tests__/active_symbols.js @@ -74,7 +74,7 @@ describe('ActiveSymbols', function() { }); it('Should getMarkets output match the market snapshot', function() { var markets = activeSymbols.getMarkets(active_symbols); - var deepDiff = deep(set_checks(markets), set_checks(JSON.parse(expected_markets_str))) + var deepDiff = deep(set_checks(markets), set_checks(JSON.parse(expected_markets_str))); if (deepDiff) { deepDiff.forEach(function(diff){ expect(diff).to.have.property('kind') diff --git a/src/bot/utils/relationChecker.js b/src/bot/utils/relationChecker.js index eb78484413..552f657bb8 100644 --- a/src/bot/utils/relationChecker.js +++ b/src/bot/utils/relationChecker.js @@ -89,7 +89,9 @@ var condition = function condition(_condition, ev, calledByParent) { _condition.unplug(); } else if ( !botUtils.isConditionAllowedInSymbol(_condition.parentBlock_.type, _condition.type) ){ var symbol = botUtils.findSymbol(_condition.parentBlock_.type); - botUtils.log(symbol[Object.keys(symbol)[0]] + ' ' + i18n._('does not support this condition'), 'warning'); + botUtils.log(symbol[Object.keys(symbol)[0]] + ' ' + i18n._('does not support category:') + + ' ' + botUtils.getCategoryName(_condition.type) + + ', ' + i18n._('Allowed categories are') + ' ' + botUtils.getAllowedCategoryNames(_condition.parentBlock_.type), 'warning'); _condition.unplug(); } else { botUtils.broadcast('tour:condition'); diff --git a/src/bot/utils/utils.js b/src/bot/utils/utils.js index a2c031f551..1fff5ed1df 100644 --- a/src/bot/utils/utils.js +++ b/src/bot/utils/utils.js @@ -8,23 +8,56 @@ var commonUtils = require('utils'); var i18n = require('i18n'); var isConditionAllowedInSymbol = function isConditionAllowedInSymbol(symbol, condition) { - var allowedConditions = getAllowedConditions(symbol); + var allowedConditions = getAllowedConditions(symbol).conditions; return allowedConditions.indexOf(condition) >= 0; }; +var getFirstObjectValue = function getFirstObjectValue(obj) { + return obj[Object.keys(obj)[0]]; +}; + +var getConditionName = function getConditionName(condition) { + var opposites = config.opposites[condition.toUpperCase()]; + return getFirstObjectValue(opposites[0]) + '/' + getFirstObjectValue(opposites[1]); +}; + +var getCategory = function getCategory(condition) { + for( var category in config.conditionsCategory ) { + if ( config.conditionsCategory[category].indexOf(condition.toLowerCase()) >= 0 ) { + return category; + } + } +}; + +var getCategoryName = function getCategoryName(condition) { + return config.conditionsCategoryName[getCategory(condition)]; +}; + +var getAllowedCategoryNames = function getAllowedCategoryNames(symbol) { + var allowedCategories = getAllowedConditions(symbol).categories; + return allowedCategories.map(function(el){ + return config.conditionsCategoryName[el]; + }); +}; + var getAllowedConditions = function getAllowedConditions(symbol) { var allowedConditions = []; + var allowedCategories = []; globals.assetIndex.forEach(function(assetIndex){ if (assetIndex[0].toLowerCase() === symbol.toLowerCase()) { assetIndex[2].forEach(function(conditionInfo){ var conditionName = conditionInfo[0]; if ( config.conditionsCategory.hasOwnProperty(conditionName) ) { allowedConditions = allowedConditions.concat(config.conditionsCategory[conditionName]); + allowedCategories.push(conditionName); } }); } }); - return allowedConditions; + return { + conditions: allowedConditions, + categories: allowedCategories + }; }; var findSymbol = function findSymbol(symbol) { @@ -320,5 +353,8 @@ module.exports = { xmlToStr: xmlToStr, findSymbol: findSymbol, getAssetIndex: getAssetIndex, - isConditionAllowedInSymbol: isConditionAllowedInSymbol + isConditionAllowedInSymbol: isConditionAllowedInSymbol, + getAllowedCategoryNames: getAllowedCategoryNames, + getCategoryName: getCategoryName, + getConditionName: getConditionName }; diff --git a/src/bot/view.js b/src/bot/view.js index 71e313dc0a..27b9978f77 100644 --- a/src/bot/view.js +++ b/src/bot/view.js @@ -14,7 +14,13 @@ require('./utils/draggable'); var initTours = function initTours() { tours.introduction = require('./tours/introduction').init(); tours.welcome = require('./tours/welcome').init(); - tours.welcome.welcome(); + if ( tours.welcome.welcome() ){ + activeTutorial = tours.welcome; + $('#tutorialButton') + .unbind('click.startTutorial') + .bind('click.stopTutorial', stopTutorial) + .text(i18n._('Stop!')); + } }; var uiComponents = { @@ -53,10 +59,8 @@ var startTutorial = function startTutorial(e) { .val()]; activeTutorial.start(); $('#tutorialButton') - .unbind('click', startTutorial); - $('#tutorialButton') - .bind('click', stopTutorial); - $('#tutorialButton') + .unbind('click.startTutorial') + .bind('click.stopTutorial', stopTutorial) .text(i18n._('Stop!')); }; @@ -71,10 +75,8 @@ var stopTutorial = function stopTutorial(e) { activeTutorial = null; } $('#tutorialButton') - .unbind('click', stopTutorial); - $('#tutorialButton') - .bind('click', startTutorial); - $('#tutorialButton') + .unbind('click.stopTutorial') + .bind('click.startTutorial', startTutorial) .text(i18n._('Go!')); }; @@ -271,7 +273,7 @@ var show = function show(done) { .addEventListener('change', handleFileSelect, false); $('#tutorialButton') - .bind('click', startTutorial); + .bind('click.startTutorial', startTutorial); $('#stopButton') .text(i18n._('Reset')); $('#stopButton') diff --git a/src/common/appId.js b/src/common/appId.js index e50ae399d5..bc9f0b4bdf 100644 --- a/src/common/appId.js +++ b/src/common/appId.js @@ -1,7 +1,7 @@ var utils = require('utils'); var AppId = { - app_id: ( document.location.port === '8080' ) ? 1168 : 1169, + app_id: ( document.location.port === '8080' ) ? 1168 : ( ( document.location.hostname.indexOf('github.io') >= 0 ) ? 1180 : 1169 ), redirectOauth: function oauthLogin(){ document.location = 'https://oauth.binary.com/oauth2/authorize?app_id=' + this.app_id + '&l=' + window.lang.toUpperCase(); }, @@ -15,7 +15,7 @@ var AppId = { }); if (tokenList.length) { utils.addAllTokens(tokenList, function(){ - document.location.pathname = '/bot.html'; + document.location.pathname += ((document.location.pathname.slice(-1) === '/')?'':'/') + 'bot.html'; }); } else { if (done) { @@ -26,7 +26,7 @@ var AppId = { removeTokenFromUrl: function removeTokenFromUrl(){ var queryStr = utils.parseQueryString(); if (queryStr.token1) { - document.location.search = ''; + document.location.href = document.location.href.split('?')[0]; } }, getAppId: function getAppId(){ diff --git a/static/xml/toolbox.xml b/static/xml/toolbox.xml index d3ecce580b..7bf60c7a8d 100644 --- a/static/xml/toolbox.xml +++ b/static/xml/toolbox.xml @@ -237,11 +237,17 @@ - - - - - + + + + + + + + + + + diff --git a/templates/bot.mustache b/templates/bot.mustache index 0f1500ce76..5266c2e628 100644 --- a/templates/bot.mustache +++ b/templates/bot.mustache @@ -6,7 +6,7 @@ {{> bundle_css }} -
+
diff --git a/templates/index.mustache b/templates/index.mustache index 90801c1a48..86bdd8f87c 100644 --- a/templates/index.mustache +++ b/templates/index.mustache @@ -6,7 +6,7 @@ {{> main_css }} -
+