Split difficult adjustment table - Update indexing progress every 60sec

This commit is contained in:
nymkappa
2022-03-09 21:21:44 +01:00
parent 6d477a897d
commit b2423e28d9
9 changed files with 171 additions and 82 deletions

View File

@@ -1,6 +1,6 @@
<div [class]="widget === false ? 'full-container' : ''">
<div *ngIf="!tableOnly" class="card-header mb-0 mb-md-4" [style]="widget ? 'display:none' : ''">
<div class="card-header mb-0 mb-md-4" [style]="widget ? 'display:none' : ''">
<form [formGroup]="radioGroupForm" class="formRadioGroup" *ngIf="(hashrateObservable$ | async) as hashrates">
<div class="btn-group btn-group-toggle" ngbRadioGroup name="radioBasic" formControlName="dateSpan">
<label ngbButtonLabel class="btn-primary btn-sm" *ngIf="hashrates.availableTimespanDay >= 90">
@@ -25,39 +25,10 @@
</form>
</div>
<div *ngIf="!tableOnly" [class]="!widget ? 'chart' : 'chart-widget'"
<div [class]="!widget ? 'chart' : 'chart-widget'"
echarts [initOpts]="chartInitOptions" [options]="chartOptions"></div>
<div class="text-center loadingGraphs" *ngIf="isLoading && !tableOnly">
<div class="text-center loadingGraphs" *ngIf="isLoading">
<div class="spinner-border text-light"></div>
</div>
<table *ngIf="tableOnly" class="table latest-transactions" style="min-height: 295px">
<thead>
<tr>
<th class="d-none d-md-block" i18n="block.height">Height</th>
<th i18n="mining.adjusted" class="text-left">Adjusted</th>
<th i18n="mining.difficulty" class="text-right">Difficulty</th>
<th i18n="mining.change" class="text-right">Change</th>
</tr>
</thead>
<tbody *ngIf="(hashrateObservable$ | async) as data">
<tr *ngFor="let diffChange of data.difficulty">
<td class="d-none d-md-block"><a [routerLink]="['/block' | relativeUrl, diffChange.height]">{{ diffChange.height }}</a></td>
<td class="text-left"><app-time-since [time]="diffChange.timestamp" [fastRender]="true"></app-time-since></td>
<td class="text-right">{{ diffChange.difficultyShorten }}</td>
<td class="text-right" [style]="diffChange.change >= 0 ? 'color: #42B747' : 'color: #B74242'">
{{ diffChange.change >= 0 ? '+' : '' }}{{ formatNumber(diffChange.change, locale, '1.2-2') }}%
</td>
</tr>
</tbody>
<tbody *ngIf="isLoading">
<tr *ngFor="let item of [1,2,3,4,5]">
<td class="d-none d-md-block w-75"><span class="skeleton-loader"></span></td>
<td class="text-left"><span class="skeleton-loader w-75"></span></td>
<td class="text-right"><span class="skeleton-loader w-75"></span></td>
<td class="text-right"><span class="skeleton-loader w-75"></span></td>
</tr>
</tbody>
</table>
</div>

View File

@@ -48,44 +48,3 @@
}
}
}
.latest-transactions {
width: 100%;
text-align: left;
table-layout:fixed;
tr, td, th {
border: 0px;
}
td {
width: 25%;
}
.table-cell-satoshis {
display: none;
text-align: right;
@media (min-width: 576px) {
display: table-cell;
}
@media (min-width: 768px) {
display: none;
}
@media (min-width: 1100px) {
display: table-cell;
}
}
.table-cell-fiat {
display: none;
text-align: right;
@media (min-width: 485px) {
display: table-cell;
}
@media (min-width: 768px) {
display: none;
}
@media (min-width: 992px) {
display: table-cell;
}
}
.table-cell-fees {
text-align: right;
}
}

View File

@@ -1,7 +1,7 @@
import { Component, Inject, Input, LOCALE_ID, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, Input, LOCALE_ID, OnInit } from '@angular/core';
import { EChartsOption, graphic } from 'echarts';
import { Observable } from 'rxjs';
import { map, share, startWith, switchMap, tap } from 'rxjs/operators';
import { delay, map, retryWhen, share, startWith, switchMap, tap } from 'rxjs/operators';
import { ApiService } from 'src/app/services/api.service';
import { SeoService } from 'src/app/services/seo.service';
import { formatNumber } from '@angular/common';
@@ -20,6 +20,7 @@ import { selectPowerOfTen } from 'src/app/bitcoin.utils';
z-index: 100;
}
`],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class HashrateChartComponent implements OnInit {
@Input() tableOnly = false;
@@ -45,6 +46,7 @@ export class HashrateChartComponent implements OnInit {
private seoService: SeoService,
private apiService: ApiService,
private formBuilder: FormBuilder,
private cd: ChangeDetectorRef,
) {
this.radioGroupForm = this.formBuilder.group({ dateSpan: '1y' });
this.radioGroupForm.controls.dateSpan.setValue('1y');
@@ -96,6 +98,11 @@ export class HashrateChartComponent implements OnInit {
timestamp: data.oldestIndexedBlockTimestamp,
});
this.isLoading = false;
if (data.hashrates.length === 0) {
this.cd.markForCheck();
throw new Error();
}
}),
map((data: any) => {
const availableTimespanDay = (
@@ -116,9 +123,12 @@ export class HashrateChartComponent implements OnInit {
}
return {
availableTimespanDay: availableTimespanDay,
difficulty: this.tableOnly ? tableData.slice(0, 5) : tableData
difficulty: this.tableOnly ? tableData.slice(0, 5) : tableData,
};
}),
retryWhen((errors) => errors.pipe(
delay(60000)
))
);
}),
share()