fix fee and reward graphs on networks without price indexing

This commit is contained in:
jramos0 2026-08-13 01:44:29 -06:00
parent 29afce710d
commit 49ca1856ee
7 changed files with 36 additions and 21 deletions

View file

@ -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);

View file

@ -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();

View file

@ -773,14 +773,16 @@ class BlocksRepository {
*/
public async $getHistoricalBlockFees(div: number, interval: string | null, timespan?: {from: number, to: number}): Promise<any> {
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<any> {
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
`;

View file

@ -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',

View file

@ -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',

View file

@ -16,7 +16,7 @@
i18n="mining.block-fee-rates">Block Fee Rates</a>
<a class="dropdown-item" routerLinkActive="active" [routerLink]="['/graphs/mining/block-fees' | relativeUrl]"
i18n="mining.block-fees">Block Fees</a>
<a class="dropdown-item" routerLinkActive="active" [routerLink]="['/graphs/mining/block-fees-subsidy' | relativeUrl]"
<a *ngIf="isMainnet" class="dropdown-item" routerLinkActive="active" [routerLink]="['/graphs/mining/block-fees-subsidy' | relativeUrl]"
i18n="mining.block-fees-subsidy-subsidy">Block Fees Vs Subsidy</a>
<a class="dropdown-item" routerLinkActive="active" [routerLink]="['/graphs/mining/block-rewards' | relativeUrl]"
i18n="mining.block-rewards">Block Rewards</a>

View file

@ -136,7 +136,7 @@ const routes: Routes = [
},
{
path: 'mining/block-fees-subsidy',
data: { networks: ['bitcoin'] },
data: { networks: ['bitcoin'], networkSpecific: true, onlySubnet: [''] },
component: BlockFeesSubsidyGraphComponent,
},
{