diff --git a/gulpfile.babel.js b/gulpfile.babel.js index e0c39d11fa..12c597d1c6 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -12,7 +12,7 @@ gulp.task( gulp.series(done => { connect.server({ root : 'www', - port : 8080, + port : 80, livereload: true, }); done(); @@ -24,7 +24,7 @@ gulp.task( gulp.series(done => { gulp.src('www/index.html').pipe( open({ - uri: 'http://localhost:8080/', + uri: 'http://localhost:80/', }) ); done(); diff --git a/src/botPage/common/TicksService.js b/src/botPage/common/TicksService.js index 507d3b26ca..86520787f8 100644 --- a/src/botPage/common/TicksService.js +++ b/src/botPage/common/TicksService.js @@ -2,6 +2,7 @@ import { Map } from 'immutable'; import { historyToTicks, getLast } from 'binary-utils'; import { observer as globalObserver } from '../../common/utils/observer'; import { doUntilDone, getUUID } from '../bot/tools'; +import { getTokenList, removeAllTokens } from '../../common/utils/storageManager'; const parseTick = tick => ({ epoch: +tick.epoch, @@ -54,13 +55,30 @@ export default class TicksService { } return new Promise(resolve => { - this.api.getActiveSymbolsBrief().then(r => { - const { active_symbols: symbols } = r; - this.pipSizes = symbols - .reduce((s, i) => s.set(i.symbol, +(+i.pip).toExponential().substring(3)), new Map()) - .toObject(); - resolve(this.pipSizes); - }); + const getActiveSymbols = () => { + this.api.getActiveSymbolsBrief().then(r => { + const { active_symbols: symbols } = r; + this.pipSizes = symbols.reduce((accumulator, currSymbol) => { + // eslint-disable-next-line no-param-reassign + accumulator[currSymbol.symbol] = `${currSymbol.pip}`.length - 2; + return accumulator; + }, {}); + resolve(this.pipSizes); + }); + }; + + const tokenList = getTokenList(); + if (tokenList.length) { + this.api + .authorize(tokenList[0].token) + .then(() => getActiveSymbols()) + .catch(() => { + removeAllTokens(); + getActiveSymbols(); + }); + } else { + getActiveSymbols(); + } }); } request(options) { @@ -173,7 +191,10 @@ export default class TicksService { } observe() { this.api.events.on('tick', r => { - const { tick, tick: { symbol, id } } = r; + const { + tick, + tick: { symbol, id }, + } = r; if (this.ticks.has(symbol)) { this.subscriptions = this.subscriptions.setIn(['tick', symbol], id); @@ -182,7 +203,10 @@ export default class TicksService { }); this.api.events.on('ohlc', r => { - const { ohlc, ohlc: { symbol, granularity, id } } = r; + const { + ohlc, + ohlc: { symbol, granularity, id }, + } = r; if (this.candles.hasIn([symbol, Number(granularity)])) { this.subscriptions = this.subscriptions.setIn(['ohlc', symbol, Number(granularity)], id); diff --git a/src/botPage/view/Dialogs/Chart.js b/src/botPage/view/Dialogs/Chart.js index 8c255f96f7..81a1ef9c37 100644 --- a/src/botPage/view/Dialogs/Chart.js +++ b/src/botPage/view/Dialogs/Chart.js @@ -54,7 +54,7 @@ class ChartContent extends PureComponent { componentDidMount() { globalObserver.register('bot.init', s => { - if (this.state.symbol !== s) { + if (s && this.state.symbol !== s) { this.setState({ symbol: s }); } }); diff --git a/src/botPage/view/TradeInfoPanel/TradeTable.js b/src/botPage/view/TradeInfoPanel/TradeTable.js index 1974a4d7fe..22dd6a79d0 100644 --- a/src/botPage/view/TradeInfoPanel/TradeTable.js +++ b/src/botPage/view/TradeInfoPanel/TradeTable.js @@ -3,7 +3,7 @@ import json2csv from 'json2csv'; import React, { Component } from 'react'; import ReactDataGrid from 'react-data-grid'; import { observer as globalObserver } from '../../../common/utils/observer'; -import { appendRow, updateRow, saveAs, ticksService } from '../shared'; +import { appendRow, updateRow, saveAs } from '../shared'; import { translate } from '../../../common/i18n'; import { roundBalance } from '../../common/tools'; import * as style from '../style'; @@ -58,8 +58,7 @@ export default class TradeTable extends Component { ]; } - static getTradeObject(pipSizes, contract) { - const symbolPipSize = pipSizes[contract.underlying]; + static getTradeObject(contract) { const tradeObj = { ...contract, reference: `${contract.transaction_ids.buy}`, @@ -68,11 +67,11 @@ export default class TradeTable extends Component { }; if (contract.entry_tick) { - tradeObj.entry_tick = (+contract.entry_tick).toFixed(symbolPipSize); + tradeObj.entry_tick = contract.entry_spot_display_value; } if (contract.exit_tick) { - tradeObj.exit_tick = (+contract.exit_tick).toFixed(symbolPipSize); + tradeObj.exit_tick = contract.exit_tick_display_value; } return tradeObj; @@ -105,30 +104,28 @@ export default class TradeTable extends Component { return; } - ticksService.requestPipSizes().then(pipSizes => { - const tradeObj = TradeTable.getTradeObject(pipSizes, contract); - const trade = { - ...tradeObj, - profit : getProfit(tradeObj), - contract_status : translate('Pending'), - contract_settled: false, - }; - - const { accountID } = tradeObj; - const accountStat = this.getAccountStat(accountID); - const { rows } = accountStat; - const prevRowIndex = rows.findIndex(t => t.reference === trade.reference); - - if (trade.is_expired && trade.is_sold && !trade.exit_tick) { - trade.exit_tick = '-'; - } + const tradeObj = TradeTable.getTradeObject(contract); + const trade = { + ...tradeObj, + profit : getProfit(tradeObj), + contract_status : translate('Pending'), + contract_settled: false, + }; + + const { accountID } = tradeObj; + const accountStat = this.getAccountStat(accountID); + const { rows } = accountStat; + const prevRowIndex = rows.findIndex(t => t.reference === trade.reference); + + if (trade.is_expired && trade.is_sold && !trade.exit_tick) { + trade.exit_tick = '-'; + } - if (prevRowIndex >= 0) { - this.setState({ [accountID]: updateRow(prevRowIndex, trade, accountStat) }); - } else { - this.setState({ [accountID]: appendRow(trade, accountStat) }); - } - }); + if (prevRowIndex >= 0) { + this.setState({ [accountID]: updateRow(prevRowIndex, trade, accountStat) }); + } else { + this.setState({ [accountID]: appendRow(trade, accountStat) }); + } }); globalObserver.register('contract.settled', contract => { @@ -166,38 +163,36 @@ export default class TradeTable extends Component { refreshContract(api, contractID) { return api.getContractInfo(contractID).then(r => { - ticksService.requestPipSizes().then(pipSizes => { - const contract = r.proposal_open_contract; - const tradeObj = TradeTable.getTradeObject(pipSizes, contract); - const trade = { - ...tradeObj, - profit: getProfit(tradeObj), - }; - - if (trade.is_expired && trade.is_sold && !trade.exit_tick) { - trade.exit_tick = '-'; - } + const contract = r.proposal_open_contract; + const tradeObj = TradeTable.getTradeObject(contract); + const trade = { + ...tradeObj, + profit: getProfit(tradeObj), + }; + + if (trade.is_expired && trade.is_sold && !trade.exit_tick) { + trade.exit_tick = '-'; + } - const { accountID } = this.props; - const { id } = this.state[accountID]; - const rows = this.state[accountID].rows.slice(); + const { accountID } = this.props; + const { id } = this.state[accountID]; + const rows = this.state[accountID].rows.slice(); - const updatedRows = rows.map(row => { - const { reference } = row; - - if (reference === trade.reference) { - return { - contract_status : translate('Settled'), - contract_settled: true, - reference, - ...trade, - }; - } - return row; - }); - - this.setState({ [accountID]: { id, rows: updatedRows } }); + const updatedRows = rows.map(row => { + const { reference } = row; + + if (reference === trade.reference) { + return { + contract_status : translate('Settled'), + contract_settled: true, + reference, + ...trade, + }; + } + return row; }); + + this.setState({ [accountID]: { id, rows: updatedRows } }); }); }