diff --git a/frontend/src/app/components/difficulty/difficulty.component.ts b/frontend/src/app/components/difficulty/difficulty.component.ts index b22001ef1..927278f72 100644 --- a/frontend/src/app/components/difficulty/difficulty.component.ts +++ b/frontend/src/app/components/difficulty/difficulty.component.ts @@ -66,14 +66,7 @@ export class DifficultyComponent implements OnInit { } } - const timeAvgDiff = change * 0.1; - - let timeAvgMins = 10; - if (timeAvgDiff > 0) { - timeAvgMins -= Math.abs(timeAvgDiff); - } else { - timeAvgMins += Math.abs(timeAvgDiff); - } + const timeAvgMins = blocksInEpoch ? diff / blocksInEpoch / 60 : 10; const timeAvg = timeAvgMins.toFixed(0); const remainingTime = (remainingBlocks * timeAvgMins * 60 * 1000) + (now * 1000); diff --git a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html index 112b35df2..5244fbe2c 100644 --- a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html +++ b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html @@ -26,7 +26,7 @@ - + diff --git a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts index 05735c0be..ccfb8680a 100644 --- a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts +++ b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts @@ -33,6 +33,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy { networkSubscription: Subscription; network = ''; now = new Date().getTime(); + lastBlockTime: number; showMiningInfo = false; blockWidth = 125; @@ -129,24 +130,22 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy { this.stateService.lastDifficultyAdjustment$ ])), map(([block, DATime]) => { + this.lastBlockTime = block.timestamp * 1000; + this.now = new Date().getTime(); const now = new Date().getTime() / 1000; const diff = now - DATime; const blocksInEpoch = block.height % 2016; - let difficultyChange = 0; - if (blocksInEpoch > 0) { - difficultyChange = (600 / (diff / blocksInEpoch ) - 1) * 100; - } - const timeAvgDiff = difficultyChange * 0.1; - let timeAvgMins = 10; - if (timeAvgDiff > 0 ){ - timeAvgMins -= Math.abs(timeAvgDiff); - } else { - timeAvgMins += Math.abs(timeAvgDiff); + let timeAvg = blocksInEpoch ? diff / blocksInEpoch : 600; + + // testnet difficulty is set to 1 after 20 minutes of no blockSize + // therefore the time between blocks will always be below 20 minutes (1200s) + if (this.stateService.network === 'testnet' && now - block.timestamp + timeAvg > 1200) { + timeAvg = 1200; } - return timeAvgMins * 60 * 1000; + return timeAvg * 1000; }) );