Use amount shortener pipe for hashrate related data

This commit is contained in:
natsoni
2025-07-24 15:55:51 +02:00
parent 090d2cc467
commit b0a1254ff5
5 changed files with 16 additions and 33 deletions

View File

@@ -3,7 +3,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { ApiService } from '@app/services/api.service'; import { ApiService } from '@app/services/api.service';
import { formatNumber } from '@angular/common'; import { formatNumber } from '@angular/common';
import { selectPowerOfTen } from '@app/bitcoin.utils'; import { AmountShortenerPipe } from '@app/shared/pipes/amount-shortener.pipe';
import { StateService } from '@app/services/state.service'; import { StateService } from '@app/services/state.service';
@Component({ @Component({
@@ -27,6 +27,7 @@ export class DifficultyAdjustmentsTable implements OnInit {
constructor( constructor(
@Inject(LOCALE_ID) public locale: string, @Inject(LOCALE_ID) public locale: string,
private apiService: ApiService, private apiService: ApiService,
public amountShortenerPipe: AmountShortenerPipe,
public stateService: StateService public stateService: StateService
) { ) {
} }
@@ -43,14 +44,11 @@ export class DifficultyAdjustmentsTable implements OnInit {
const data = response.body; const data = response.body;
const tableData = []; const tableData = [];
for (const adjustment of data) { for (const adjustment of data) {
const selectedPowerOfTen: any = selectPowerOfTen(adjustment[2]);
tableData.push({ tableData.push({
height: adjustment[1], height: adjustment[1],
timestamp: adjustment[0], timestamp: adjustment[0],
change: (adjustment[3] - 1) * 100, change: (adjustment[3] - 1) * 100,
difficultyShorten: formatNumber( difficultyShorten: this.amountShortenerPipe.transform(adjustment[2], decimals)
adjustment[2] / selectedPowerOfTen.divider,
this.locale, `1.${decimals}-${decimals}`) + selectedPowerOfTen.unit
}); });
} }
this.isLoading = false; this.isLoading = false;

View File

@@ -7,7 +7,7 @@
<div class="item"> <div class="item">
<h5 class="card-title" i18n="mining.hashrate">Hashrate (1w)</h5> <h5 class="card-title" i18n="mining.hashrate">Hashrate (1w)</h5>
<p class="card-text"> <p class="card-text">
{{ hashrates.currentHashrate | amountShortener: 1 : 'H/s' }} {{ hashrates.currentHashrate | amountShortener: 3 : 'H/s' : false : true }}
</p> </p>
</div> </div>
<div class="item"> <div class="item">

View File

@@ -13,6 +13,7 @@ import { download } from '@app/shared/graphs.utils';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { StateService } from '@app/services/state.service'; import { StateService } from '@app/services/state.service';
import { seoDescriptionNetwork } from '@app/shared/common.utils'; import { seoDescriptionNetwork } from '@app/shared/common.utils';
import { AmountShortenerPipe } from '@app/shared/pipes/amount-shortener.pipe';
@Component({ @Component({
selector: 'app-hashrate-chart', selector: 'app-hashrate-chart',
@@ -60,6 +61,7 @@ export class HashrateChartComponent implements OnInit {
private storageService: StorageService, private storageService: StorageService,
private miningService: MiningService, private miningService: MiningService,
private route: ActivatedRoute, private route: ActivatedRoute,
private amountShortenerPipe: AmountShortenerPipe,
public stateService: StateService public stateService: StateService
) { ) {
} }
@@ -250,29 +252,19 @@ export class HashrateChartComponent implements OnInit {
let hashrateString = ''; let hashrateString = '';
let difficultyString = ''; let difficultyString = '';
let hashrateStringMA = ''; let hashrateStringMA = '';
let hashratePowerOfTen: any = selectPowerOfTen(1);
for (const tick of ticks) { for (const tick of ticks) {
if (tick.seriesIndex === 0) { // Hashrate if (tick.seriesIndex === 0) { // Hashrate
let hashrate = tick.data[1]; hashrateString = `${tick.marker} ${tick.seriesName}: ${this.amountShortenerPipe.transform(tick.data[1], 3, 'H/s', false, true)}<br>`;
hashratePowerOfTen = selectPowerOfTen(tick.data[1], 10);
hashrate = tick.data[1] / hashratePowerOfTen.divider;
hashrateString = `${tick.marker} ${tick.seriesName}: ${formatNumber(hashrate, this.locale, '1.0-0')} ${hashratePowerOfTen.unit}H/s<br>`;
} else if (tick.seriesIndex === 1) { // Difficulty } else if (tick.seriesIndex === 1) { // Difficulty
let difficultyPowerOfTen = hashratePowerOfTen;
let difficulty = tick.data[1]; let difficulty = tick.data[1];
if (difficulty === null) { if (difficulty === null) {
difficultyString = `${tick.marker} ${tick.seriesName}: No data<br>`; difficultyString = `${tick.marker} ${tick.seriesName}: No data<br>`;
} else { } else {
difficultyPowerOfTen = selectPowerOfTen(tick.data[1]); difficultyString = `${tick.marker} ${tick.seriesName}: ${this.amountShortenerPipe.transform(tick.data[1], 2, '', false)}<br>`;
difficulty = tick.data[1] / difficultyPowerOfTen.divider;
difficultyString = `${tick.marker} ${tick.seriesName}: ${formatNumber(difficulty, this.locale, '1.2-2')} ${difficultyPowerOfTen.unit}<br>`;
} }
} else if (tick.seriesIndex === 2) { // Hashrate MA } else if (tick.seriesIndex === 2) { // Hashrate MA
let hashrate = tick.data[1]; hashrateStringMA = `${tick.marker} ${tick.seriesName}: ${this.amountShortenerPipe.transform(tick.data[1], 3, 'H/s', false, true)}<br>`;
hashratePowerOfTen = selectPowerOfTen(tick.data[1], 10);
hashrate = tick.data[1] / hashratePowerOfTen.divider;
hashrateStringMA = `${tick.marker} ${tick.seriesName}: ${formatNumber(hashrate, this.locale, '1.0-0')} ${hashratePowerOfTen.unit}H/s`;
} }
} }
@@ -346,9 +338,7 @@ export class HashrateChartComponent implements OnInit {
axisLabel: { axisLabel: {
color: 'rgb(110, 112, 121)', color: 'rgb(110, 112, 121)',
formatter: (val): string => { formatter: (val): string => {
const selectedPowerOfTen: any = selectPowerOfTen(val); return this.amountShortenerPipe.transform(val, 3, 'H/s', false, true).toString();
const newVal = Math.round(val / selectedPowerOfTen.divider);
return `${newVal} ${selectedPowerOfTen.unit}H/s`;
}, },
showMinLabel: false, showMinLabel: false,
showMaxLabel: false, showMaxLabel: false,
@@ -384,9 +374,7 @@ export class HashrateChartComponent implements OnInit {
if (this.stateService.network === 'signet') { if (this.stateService.network === 'signet') {
return `${val}`; return `${val}`;
} }
const selectedPowerOfTen: any = selectPowerOfTen(val); return this.amountShortenerPipe.transform(val, 3, '', false, true).toString();
const newVal = Math.round(val / selectedPowerOfTen.divider);
return `${newVal} ${selectedPowerOfTen.unit}`;
}, },
showMinLabel: false, showMinLabel: false,
showMaxLabel: false, showMaxLabel: false,

View File

@@ -98,7 +98,7 @@
</thead> </thead>
<tbody> <tbody>
<td class="text-center"><app-amount [satoshis]="poolStats.totalReward" digitsInfo="1.0-0" [noFiat]="true" [ignoreViewMode]="true"></app-amount></td> <td class="text-center"><app-amount [satoshis]="poolStats.totalReward" digitsInfo="1.0-0" [noFiat]="true" [ignoreViewMode]="true"></app-amount></td>
<td class="text-center">{{ poolStats.estimatedHashrate | amountShortener : 1 : 'H/s' }}</td> <td class="text-center">{{ poolStats.estimatedHashrate | amountShortener : 3 : 'H/s' : false : true }}</td>
<td class="text-center" *ngIf="auditAvailable; else emptyTd"><span class="health-badge badge" [class.badge-success]="poolStats.avgBlockHealth >= 99" <td class="text-center" *ngIf="auditAvailable; else emptyTd"><span class="health-badge badge" [class.badge-success]="poolStats.avgBlockHealth >= 99"
[class.badge-warning]="poolStats.avgBlockHealth >= 75 && poolStats.avgBlockHealth < 99" [class.badge-danger]="poolStats.avgBlockHealth < 75" [class.badge-warning]="poolStats.avgBlockHealth >= 75 && poolStats.avgBlockHealth < 99" [class.badge-danger]="poolStats.avgBlockHealth < 75"
*ngIf="poolStats.avgBlockHealth != null; else nullHealth">{{ poolStats.avgBlockHealth }}%</span> *ngIf="poolStats.avgBlockHealth != null; else nullHealth">{{ poolStats.avgBlockHealth }}%</span>

View File

@@ -6,7 +6,7 @@ import { catchError, distinctUntilChanged, filter, map, share, switchMap, tap }
import { BlockExtended, PoolStat } from '@interfaces/node-api.interface'; import { BlockExtended, PoolStat } from '@interfaces/node-api.interface';
import { ApiService } from '@app/services/api.service'; import { ApiService } from '@app/services/api.service';
import { StateService } from '@app/services/state.service'; import { StateService } from '@app/services/state.service';
import { selectPowerOfTen } from '@app/bitcoin.utils'; import { AmountShortenerPipe } from '@app/shared/pipes/amount-shortener.pipe';
import { formatNumber } from '@angular/common'; import { formatNumber } from '@angular/common';
import { SeoService } from '@app/services/seo.service'; import { SeoService } from '@app/services/seo.service';
import { HttpErrorResponse } from '@angular/common/http'; import { HttpErrorResponse } from '@angular/common/http';
@@ -63,6 +63,7 @@ export class PoolComponent implements OnInit {
private websocketService: WebsocketService, private websocketService: WebsocketService,
private miningService: MiningService, private miningService: MiningService,
private seoService: SeoService, private seoService: SeoService,
public amountShortenerPipe: AmountShortenerPipe,
) { ) {
this.auditAvailable = this.stateService.env.AUDIT; this.auditAvailable = this.stateService.env.AUDIT;
} }
@@ -217,9 +218,7 @@ export class PoolComponent implements OnInit {
for (const tick of ticks) { for (const tick of ticks) {
if (tick.seriesIndex === 0) { if (tick.seriesIndex === 0) {
let hashratePowerOfTen = selectPowerOfTen(tick.data[1], 10); hashrateString = `${tick.marker} ${tick.seriesName}: ${this.amountShortenerPipe.transform(tick.data[1], 3, 'H/s', false, true)}<br>`;
let hashrateData = tick.data[1] / hashratePowerOfTen.divider;
hashrateString = `${tick.marker} ${tick.seriesName}: ${formatNumber(hashrateData, this.locale, '1.0-0')} ${hashratePowerOfTen.unit}H/s<br>`;
} else if (tick.seriesIndex === 1) { } else if (tick.seriesIndex === 1) {
dominanceString = `${tick.marker} ${tick.seriesName}: ${formatNumber(tick.data[1], this.locale, '1.0-2')}%`; dominanceString = `${tick.marker} ${tick.seriesName}: ${formatNumber(tick.data[1], this.locale, '1.0-2')}%`;
} }
@@ -271,9 +270,7 @@ export class PoolComponent implements OnInit {
axisLabel: { axisLabel: {
color: 'rgb(110, 112, 121)', color: 'rgb(110, 112, 121)',
formatter: (val) => { formatter: (val) => {
const selectedPowerOfTen: any = selectPowerOfTen(val); return this.amountShortenerPipe.transform(val, 3, 'H/s', false, true).toString();
const newVal = Math.round(val / selectedPowerOfTen.divider);
return `${newVal} ${selectedPowerOfTen.unit}H/s`
} }
}, },
splitLine: { splitLine: {