From 89b2e110837ae3d61478d8bf06ae538116f74332 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Tue, 12 Jul 2022 09:03:39 +0200 Subject: [PATCH] [Hashrate chart] Fix javascript error if difficulty array is empty --- .../hashrate-chart/hashrate-chart.component.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts b/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts index 385be0669..2a7cc07f2 100644 --- a/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts +++ b/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts @@ -109,7 +109,7 @@ export class HashrateChartComponent implements OnInit { while (hashIndex < data.hashrates.length) { diffFixed.push({ timestamp: data.hashrates[hashIndex].timestamp, - difficulty: data.difficulty[data.difficulty.length - 1].difficulty + difficulty: data.difficulty.length > 0 ? data.difficulty[data.difficulty.length - 1].difficulty : null }); ++hashIndex; } @@ -231,11 +231,15 @@ export class HashrateChartComponent implements OnInit { } else if (tick.seriesIndex === 1) { // Difficulty let difficultyPowerOfTen = hashratePowerOfTen; let difficulty = tick.data[1]; - if (this.isMobile()) { - difficultyPowerOfTen = selectPowerOfTen(tick.data[1]); - difficulty = Math.round(tick.data[1] / difficultyPowerOfTen.divider); + if (difficulty === null) { + difficultyString = `${tick.marker} ${tick.seriesName}: No data
`; + } else { + if (this.isMobile()) { + difficultyPowerOfTen = selectPowerOfTen(tick.data[1]); + difficulty = Math.round(tick.data[1] / difficultyPowerOfTen.divider); + } + difficultyString = `${tick.marker} ${tick.seriesName}: ${formatNumber(difficulty, this.locale, '1.2-2')} ${difficultyPowerOfTen.unit}
`; } - difficultyString = `${tick.marker} ${tick.seriesName}: ${formatNumber(difficulty, this.locale, '1.2-2')} ${difficultyPowerOfTen.unit}
`; } else if (tick.seriesIndex === 2) { // Hashrate MA let hashrate = tick.data[1]; if (this.isMobile()) {