From f1e4528ba7576b1f0d16de6d26abce5a56a023ca Mon Sep 17 00:00:00 2001 From: nazaninreihani Date: Fri, 14 Jun 2019 11:03:05 -0400 Subject: [PATCH 1/3] fix issue of decimal placed in chart --- www/js/share/services/chart.service.js | 29 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/www/js/share/services/chart.service.js b/www/js/share/services/chart.service.js index 90177cf463..ff3cb5d9bb 100644 --- a/www/js/share/services/chart.service.js +++ b/www/js/share/services/chart.service.js @@ -254,10 +254,13 @@ angular.module("binary").factory("chartService", $rootScope => { let historyData = []; const addTick = function addTick(tick) { + const options = JSON.parse(localStorage.options); + const pip = options.underlying.pip; + const fractionalLength = utils.fractionalLength(pip); if (parseInt(tick.epoch) > parseInt(historyData.slice(-1)[0].time)) { historyData.push({ time : tick.epoch, - price: tick.quote + price: parseFloat(tick.quote).toFixed(fractionalLength) }); historyData.shift(); } @@ -500,33 +503,43 @@ angular.module("binary").factory("chartService", $rootScope => { }; const addRegions = function addRegions(lastTime, lastPrice) { + const options = JSON.parse(localStorage.options); + const pip = options.underlying.pip; + const fractionalLength = utils.fractionalLength(pip); + if (hasEntrySpot() && broadcastable) { if (tickPriceList.length === 0) { if (contract.entrySpotTime !== lastTime && betweenExistingSpots(lastTime)) { - tickPriceList.push(parseFloat(contract.entrySpotPrice)); - if (utils.conditions[contract.type](contract.barrier, contract.entrySpotPrice, + tickPriceList.push(parseFloat(contract.entrySpotPrice).toFixed(fractionalLength)); + const barrier = parseFloat(contract.barrier).toFixed(fractionalLength); + const entrySpotPrice = parseFloat(contract.entrySpotPrice).toFixed(fractionalLength); + + if (utils.conditions[contract.type](barrier, entrySpotPrice, tickPriceList, contract.selectedTick)) { contract.result = "win"; } else { contract.result = "lose"; } - $rootScope.$broadcast("contract:spot", contract, contract.entrySpotPrice); + $rootScope.$broadcast("contract:spot", contract, entrySpotPrice); } else { - tickPriceList.push(parseFloat(lastPrice)); + tickPriceList.push(parseFloat(lastPrice).toFixed(fractionalLength)); } } else { - tickPriceList.push(parseFloat(lastPrice)); + tickPriceList.push(parseFloat(lastPrice).toFixed(fractionalLength)); } if (betweenExistingSpots(lastTime)) { - if (utils.conditions[contract.type](contract.barrier, lastPrice, + const barrier = parseFloat(contract.barrier).toFixed(fractionalLength); + const lastPriceFloat = parseFloat(lastPrice).toFixed(fractionalLength); + + if (utils.conditions[contract.type](barrier, lastPriceFloat, tickPriceList, contract.selectedTick)) { contract.result = "win"; } else { contract.result = "lose"; } - $rootScope.$broadcast("contract:spot", contract, lastPrice); + $rootScope.$broadcast("contract:spot", contract, lastPriceFloat); if (isFinished() && broadcastable) { tickPriceList = []; From f5a3d34a5643d285f37c2be72c51b2114ed102c6 Mon Sep 17 00:00:00 2001 From: nazaninreihani Date: Fri, 14 Jun 2019 11:56:55 -0400 Subject: [PATCH 2/3] refactor --- www/js/share/services/chart.service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/js/share/services/chart.service.js b/www/js/share/services/chart.service.js index ff3cb5d9bb..00cbaad638 100644 --- a/www/js/share/services/chart.service.js +++ b/www/js/share/services/chart.service.js @@ -510,9 +510,9 @@ angular.module("binary").factory("chartService", $rootScope => { if (hasEntrySpot() && broadcastable) { if (tickPriceList.length === 0) { if (contract.entrySpotTime !== lastTime && betweenExistingSpots(lastTime)) { - tickPriceList.push(parseFloat(contract.entrySpotPrice).toFixed(fractionalLength)); - const barrier = parseFloat(contract.barrier).toFixed(fractionalLength); const entrySpotPrice = parseFloat(contract.entrySpotPrice).toFixed(fractionalLength); + const barrier = parseFloat(contract.barrier).toFixed(fractionalLength); + tickPriceList.push(entrySpotPrice); if (utils.conditions[contract.type](barrier, entrySpotPrice, tickPriceList, contract.selectedTick)) { From 2c692c8b438f651a1761c26aa5d424c6976b71c6 Mon Sep 17 00:00:00 2001 From: nazaninreihani Date: Fri, 14 Jun 2019 13:11:27 -0400 Subject: [PATCH 3/3] show spots in transaction details with correct decimals --- .../transaction-detail.controller.js | 20 ++++++++++++++++--- .../transaction-detail.template.html | 7 +++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/www/js/pages/transaction-detail/transaction-detail.controller.js b/www/js/pages/transaction-detail/transaction-detail.controller.js index 474409baa1..4d4e34f6e8 100644 --- a/www/js/pages/transaction-detail/transaction-detail.controller.js +++ b/www/js/pages/transaction-detail/transaction-detail.controller.js @@ -16,11 +16,20 @@ function TransactionDetail($scope, $timeout, appStateService, websocketService) { const vm = this; vm.currency = sessionStorage.getItem("currency"); + vm.fractionalLength = 2; + const activeSymbols = JSON.parse(sessionStorage.getItem("all_active_symbols")); const id = sessionStorage.getItem("id"); const contractId = parseInt(id); const extraParams = { req_id: contractId }; + + const getFractionalLength = (floatNumber) => { + const stringNumber = floatNumber.toString(); + const decimalLength = stringNumber.indexOf("."); + return stringNumber.length - decimalLength - 1; + }; + const sendDetailsRequest = () => { if (appStateService.isLoggedin) { websocketService.sendRequestFor.openContract(id, extraParams); @@ -32,10 +41,15 @@ $scope.$on("proposal:open-contract", (e, proposal_open_contract, req_id) => { const proposalOpenContract = proposal_open_contract; const reqId = req_id; + if (reqId === contractId) { - $scope.$applyAsync(() => { - vm.contract = proposalOpenContract; - }); + const activeSymbol = + activeSymbols.find((activeSymbol) => activeSymbol.symbol === proposalOpenContract.underlying); + const pip = activeSymbol.pip || 0.01; + vm.fractionalLength = getFractionalLength(pip); + vm.contract = proposalOpenContract; + $scope.$apply(); + } }); diff --git a/www/js/pages/transaction-detail/transaction-detail.template.html b/www/js/pages/transaction-detail/transaction-detail.template.html index c932ebea18..7860d6895d 100644 --- a/www/js/pages/transaction-detail/transaction-detail.template.html +++ b/www/js/pages/transaction-detail/transaction-detail.template.html @@ -61,7 +61,8 @@

    • {{'transaction-details.entry_spot' | translate}}
    • -
    • {{vm.contract.entry_spot}}
    • +
  • @@ -87,7 +88,9 @@

    • {{'transaction-details.exit_spot' | translate}}
    • -
    • {{vm.contract.exit_tick}}
    • +
    • +