From 49ca1856ee335c77f8f516397e4e0b70dd7974c7 Mon Sep 17 00:00:00 2001 From: jramos0 Date: Thu, 13 Aug 2026 01:44:29 -0600 Subject: [PATCH] fix fee and reward graphs on networks without price indexing --- backend/src/api/common.ts | 9 +++++++++ backend/src/indexer.ts | 2 +- backend/src/repositories/BlocksRepository.ts | 20 +++++++++++-------- .../block-fees-graph.component.ts | 11 +++++----- .../block-rewards-graph.component.ts | 11 +++++----- .../components/graphs/graphs.component.html | 2 +- .../src/app/graphs/graphs.routing.module.ts | 2 +- 7 files changed, 36 insertions(+), 21 deletions(-) diff --git a/backend/src/api/common.ts b/backend/src/api/common.ts index 6786bf1c8..6e64c04a6 100644 --- a/backend/src/api/common.ts +++ b/backend/src/api/common.ts @@ -902,6 +902,15 @@ export class Common { ); } + // must match the conditions under which the indexer runs the 'blocksPrices' task, + // otherwise queries will join against a blocks_prices table that is never populated + static blockPricesIndexingEnabled(): boolean { + return ( + !['testnet', 'signet', 'testnet4', 'regtest'].includes(config.MEMPOOL.NETWORK) && + config.FIAT_PRICE.ENABLED === true + ); + } + static setDateMidnight(date: Date): void { date.setUTCHours(0); date.setUTCMinutes(0); diff --git a/backend/src/indexer.ts b/backend/src/indexer.ts index ff10d701e..30970e073 100644 --- a/backend/src/indexer.ts +++ b/backend/src/indexer.ts @@ -137,7 +137,7 @@ class Indexer { switch (task) { case 'blocksPrices': { - if (!['testnet', 'signet', 'testnet4', 'regtest'].includes(config.MEMPOOL.NETWORK) && config.FIAT_PRICE.ENABLED) { + if (Common.blockPricesIndexingEnabled()) { let latestPriceId; try { latestPriceId = await PricesRepository.$getLatestPriceId(); diff --git a/backend/src/repositories/BlocksRepository.ts b/backend/src/repositories/BlocksRepository.ts index 20d0a6e46..db4b62f6c 100644 --- a/backend/src/repositories/BlocksRepository.ts +++ b/backend/src/repositories/BlocksRepository.ts @@ -773,14 +773,16 @@ class BlocksRepository { */ public async $getHistoricalBlockFees(div: number, interval: string | null, timespan?: {from: number, to: number}): Promise { try { + const withPrices = Common.blockPricesIndexingEnabled(); + let query = `SELECT CAST(AVG(blocks.height) as INT) as avgHeight, CAST(AVG(UNIX_TIMESTAMP(blockTimestamp)) as INT) as timestamp, - CAST(AVG(fees) as INT) as avgFees, - prices.USD - FROM blocks + CAST(AVG(fees) as INT) as avgFees${withPrices ? `, + prices.USD` : ''} + FROM blocks${withPrices ? ` JOIN blocks_prices on blocks_prices.height = blocks.height - JOIN prices on prices.id = blocks_prices.price_id + JOIN prices on prices.id = blocks_prices.price_id` : ''} WHERE stale = 0 `; @@ -806,14 +808,16 @@ class BlocksRepository { */ public async $getHistoricalBlockRewards(div: number, interval: string | null): Promise { try { + const withPrices = Common.blockPricesIndexingEnabled(); + let query = `SELECT CAST(AVG(blocks.height) as INT) as avgHeight, CAST(AVG(UNIX_TIMESTAMP(blockTimestamp)) as INT) as timestamp, - CAST(AVG(reward) as INT) as avgRewards, - prices.USD - FROM blocks + CAST(AVG(reward) as INT) as avgRewards${withPrices ? `, + prices.USD` : ''} + FROM blocks${withPrices ? ` JOIN blocks_prices on blocks_prices.height = blocks.height - JOIN prices on prices.id = blocks_prices.price_id + JOIN prices on prices.id = blocks_prices.price_id` : ''} WHERE stale = 0 `; diff --git a/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts b/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts index 4c3d7f3a0..77dd9e5a5 100644 --- a/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts +++ b/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts @@ -110,6 +110,7 @@ export class BlockFeesGraphComponent implements OnInit { } prepareChartOptions(data) { + const showFiat = !this.stateService.isAnyTestnet(); const feesBtcLabel = $localize`:@@graphs.blockFees.feesBtc:Fees BTC`; const feesFiatLabel = $localize`:@@graphs.blockFees.feesFiat:Fees ${this.currency}:currency:`; @@ -186,7 +187,7 @@ export class BlockFeesGraphComponent implements OnInit { hideOverlap: true, } }, - legend: data.blockFees.length === 0 ? undefined : { + legend: (data.blockFees.length === 0 || !showFiat) ? undefined : { top: 'top', data: [ { @@ -224,7 +225,7 @@ export class BlockFeesGraphComponent implements OnInit { } }, }, - { + ...(showFiat ? [{ type: 'value', position: 'right', axisLabel: { @@ -236,7 +237,7 @@ export class BlockFeesGraphComponent implements OnInit { splitLine: { show: false, }, - }, + }] : []), ], series: data.blockFees.length === 0 ? undefined : [ { @@ -253,7 +254,7 @@ export class BlockFeesGraphComponent implements OnInit { opacity: 1, } }, - { + ...(showFiat ? [{ legendHoverLink: false, zlevel: 1, yAxisIndex: 1, @@ -266,7 +267,7 @@ export class BlockFeesGraphComponent implements OnInit { width: 2, opacity: 1, } - }, + }] : []), ], dataZoom: data.blockFees.length === 0 ? undefined : [{ type: 'inside', diff --git a/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts b/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts index 8dabd236c..fa4f210e8 100644 --- a/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts +++ b/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts @@ -107,6 +107,7 @@ export class BlockRewardsGraphComponent implements OnInit { } prepareChartOptions(data) { + const showFiat = !this.stateService.isAnyTestnet(); let title: object; if (data.blockRewards.length === 0) { title = { @@ -182,7 +183,7 @@ export class BlockRewardsGraphComponent implements OnInit { hideOverlap: true, } }, - legend: data.blockRewards.length === 0 ? undefined : { + legend: (data.blockRewards.length === 0 || !showFiat) ? undefined : { top: 'top', data: [ { @@ -226,7 +227,7 @@ export class BlockRewardsGraphComponent implements OnInit { } }, }, - { + ...(showFiat ? [{ min: (value) => { return Math.round(value.min * (1.0 - scaleFactor) * 10) / 10; }, @@ -244,7 +245,7 @@ export class BlockRewardsGraphComponent implements OnInit { splitLine: { show: false, }, - }, + }] : []), ], series: data.blockRewards.length === 0 ? undefined : [ { @@ -257,7 +258,7 @@ export class BlockRewardsGraphComponent implements OnInit { smooth: 0.25, symbol: 'none', }, - { + ...(showFiat ? [{ legendHoverLink: false, zlevel: 1, yAxisIndex: 1, @@ -273,7 +274,7 @@ export class BlockRewardsGraphComponent implements OnInit { areaStyle: { opacity: 0.05, } - }, + }] : []), ], dataZoom: data.blockRewards.length === 0 ? undefined : [{ type: 'inside', diff --git a/frontend/src/app/components/graphs/graphs.component.html b/frontend/src/app/components/graphs/graphs.component.html index 74e37d298..ab8b2791a 100644 --- a/frontend/src/app/components/graphs/graphs.component.html +++ b/frontend/src/app/components/graphs/graphs.component.html @@ -16,7 +16,7 @@ i18n="mining.block-fee-rates">Block Fee Rates Block Fees - Block Fees Vs Subsidy Block Rewards diff --git a/frontend/src/app/graphs/graphs.routing.module.ts b/frontend/src/app/graphs/graphs.routing.module.ts index f0399f410..3d698542d 100644 --- a/frontend/src/app/graphs/graphs.routing.module.ts +++ b/frontend/src/app/graphs/graphs.routing.module.ts @@ -136,7 +136,7 @@ const routes: Routes = [ }, { path: 'mining/block-fees-subsidy', - data: { networks: ['bitcoin'] }, + data: { networks: ['bitcoin'], networkSpecific: true, onlySubnet: [''] }, component: BlockFeesSubsidyGraphComponent, }, {