mirror of
https://github.com/mempool/mempool.git
synced 2024-12-28 01:04:28 +01:00
Refactor footer component to using OnPush.
This commit is contained in:
parent
d1c786e2f6
commit
c1caaa37aa
@ -1,24 +1,24 @@
|
|||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
<div class="container-xl">
|
<div class="container-xl">
|
||||||
<div class="row text-center" *ngIf="memPoolInfo">
|
<div class="row text-center" *ngIf="mempoolInfoData$ | async as mempoolInfoData">
|
||||||
<div class="col d-none d-sm-block">
|
<div class="col d-none d-sm-block">
|
||||||
<span class="txPerSecond">Tx weight per second:</span>
|
<span class="txPerSecond">Tx weight per second:</span>
|
||||||
<span class="" *ngIf="memPoolInfo?.vBytesPerSecond === 0; else inSync">
|
<span *ngIf="mempoolInfoData.memPoolInfo.vBytesPerSecond === 0; else inSync">
|
||||||
<span class="badge badge-pill badge-warning">Backend is synchronizing</span>
|
<span class="badge badge-pill badge-warning">Backend is synchronizing</span>
|
||||||
</span>
|
</span>
|
||||||
<ng-template #inSync>
|
<ng-template #inSync>
|
||||||
<div class="progress sub-text">
|
<div class="progress sub-text">
|
||||||
<div class="progress-bar {{ progressClass }}" role="progressbar" [ngStyle]="{'width': progressWidth}">{{ memPoolInfo?.vBytesPerSecond | ceil | number }} vBytes/s</div>
|
<div class="progress-bar {{ mempoolInfoData.progressClass }}" role="progressbar" [ngStyle]="{'width': mempoolInfoData.progressWidth}">{{ mempoolInfoData.memPoolInfo.vBytesPerSecond | ceil | number }} vBytes/s</div>
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<span class="unconfirmedTx">Unconfirmed<span class="extra-text"> transactions</span>:</span>
|
<span class="unconfirmedTx">Unconfirmed<span class="extra-text"> transactions</span>:</span>
|
||||||
<div class="sub-text">{{ memPoolInfo?.memPoolInfo?.size | number }}</div>
|
<div class="sub-text">{{ mempoolInfoData.memPoolInfo.memPoolInfo.size | number }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<span class="mempoolSize">Mempool size:</span>
|
<span class="mempoolSize">Mempool size:</span>
|
||||||
<div class="sub-text">{{ mempoolSize | bytes }} ({{ mempoolBlocks }} block<span [hidden]="mempoolBlocks <= 1">s</span>)</div>
|
<div class="sub-text" *ngIf="(mempoolBlocksData$ | async) as mempoolBlocksData">{{ mempoolBlocksData.size | bytes }} ({{ mempoolBlocksData.blocks }} block<span [hidden]="mempoolBlocksData.blocks <= 1">s</span>)</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,61 +1,72 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
|
||||||
import { StateService } from 'src/app/services/state.service';
|
import { StateService } from 'src/app/services/state.service';
|
||||||
import { MemPoolState } from 'src/app/interfaces/websocket.interface';
|
import { MemPoolState } from 'src/app/interfaces/websocket.interface';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
|
interface MempoolBlocksData {
|
||||||
|
blocks: number;
|
||||||
|
size: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MempoolInfoData {
|
||||||
|
memPoolInfo: MemPoolState;
|
||||||
|
progressWidth: string;
|
||||||
|
progressClass: string;
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-footer',
|
selector: 'app-footer',
|
||||||
templateUrl: './footer.component.html',
|
templateUrl: './footer.component.html',
|
||||||
styleUrls: ['./footer.component.scss']
|
styleUrls: ['./footer.component.scss'],
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class FooterComponent implements OnInit {
|
export class FooterComponent implements OnInit {
|
||||||
memPoolInfo: MemPoolState | undefined;
|
mempoolBlocksData$: Observable<MempoolBlocksData>;
|
||||||
mempoolBlocks = 0;
|
mempoolInfoData$: Observable<MempoolInfoData>;
|
||||||
progressWidth = '';
|
|
||||||
progressClass: string;
|
|
||||||
mempoolSize = 0;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.stateService.mempoolStats$
|
this.mempoolInfoData$ = this.stateService.mempoolStats$
|
||||||
.subscribe((mempoolState) => {
|
.pipe(
|
||||||
this.memPoolInfo = mempoolState;
|
map((mempoolState) => {
|
||||||
this.updateProgress();
|
const vBytesPerSecondLimit = 1667;
|
||||||
});
|
let vBytesPerSecond = mempoolState.vBytesPerSecond;
|
||||||
|
if (vBytesPerSecond > 1667) {
|
||||||
|
vBytesPerSecond = 1667;
|
||||||
|
}
|
||||||
|
|
||||||
this.stateService.mempoolBlocks$
|
const percent = Math.round((vBytesPerSecond / vBytesPerSecondLimit) * 100);
|
||||||
.subscribe((mempoolBlocks) => {
|
|
||||||
if (!mempoolBlocks.length) { return; }
|
|
||||||
const size = mempoolBlocks.map((m) => m.blockSize).reduce((a, b) => a + b);
|
|
||||||
const vsize = mempoolBlocks.map((m) => m.blockVSize).reduce((a, b) => a + b);
|
|
||||||
this.mempoolSize = size;
|
|
||||||
this.mempoolBlocks = Math.ceil(vsize / 1000000);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updateProgress() {
|
let progressClass = 'bg-danger';
|
||||||
if (!this.memPoolInfo) {
|
if (percent <= 75) {
|
||||||
return;
|
progressClass = 'bg-success';
|
||||||
}
|
} else if (percent <= 99) {
|
||||||
|
progressClass = 'bg-warning';
|
||||||
|
}
|
||||||
|
|
||||||
const vBytesPerSecondLimit = 1667;
|
return {
|
||||||
|
memPoolInfo: mempoolState,
|
||||||
|
progressWidth: percent + '%',
|
||||||
|
progressClass: progressClass,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
let vBytesPerSecond = this.memPoolInfo.vBytesPerSecond;
|
this.mempoolBlocksData$ = this.stateService.mempoolBlocks$
|
||||||
if (vBytesPerSecond > 1667) {
|
.pipe(
|
||||||
vBytesPerSecond = 1667;
|
map((mempoolBlocks) => {
|
||||||
}
|
const size = mempoolBlocks.map((m) => m.blockSize).reduce((a, b) => a + b, 0);
|
||||||
|
const vsize = mempoolBlocks.map((m) => m.blockVSize).reduce((a, b) => a + b, 0);
|
||||||
|
|
||||||
const percent = Math.round((vBytesPerSecond / vBytesPerSecondLimit) * 100);
|
return {
|
||||||
this.progressWidth = percent + '%';
|
size: size,
|
||||||
|
blocks: Math.ceil(vsize / 1000000)
|
||||||
if (percent <= 75) {
|
};
|
||||||
this.progressClass = 'bg-success';
|
})
|
||||||
} else if (percent <= 99) {
|
);
|
||||||
this.progressClass = 'bg-warning';
|
|
||||||
} else {
|
|
||||||
this.progressClass = 'bg-danger';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user