2020-07-30 13:50:21 +07:00
|
|
|
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
|
2020-02-17 20:39:20 +07:00
|
|
|
import { StateService } from 'src/app/services/state.service';
|
2020-08-12 13:33:58 +07:00
|
|
|
import { Observable, combineLatest } from 'rxjs';
|
2020-07-30 13:50:21 +07:00
|
|
|
import { map } from 'rxjs/operators';
|
2020-08-12 13:33:58 +07:00
|
|
|
import { MempoolInfo } from 'src/app/interfaces/websocket.interface';
|
2020-07-30 13:50:21 +07:00
|
|
|
|
|
|
|
interface MempoolBlocksData {
|
|
|
|
blocks: number;
|
|
|
|
size: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface MempoolInfoData {
|
2020-08-12 13:33:58 +07:00
|
|
|
memPoolInfo: MempoolInfo;
|
|
|
|
vBytesPerSecond: number;
|
2020-07-30 13:50:21 +07:00
|
|
|
progressWidth: string;
|
|
|
|
progressClass: string;
|
|
|
|
}
|
2020-02-17 20:39:20 +07:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-footer',
|
|
|
|
templateUrl: './footer.component.html',
|
2020-07-30 13:50:21 +07:00
|
|
|
styleUrls: ['./footer.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
2020-02-17 20:39:20 +07:00
|
|
|
})
|
|
|
|
export class FooterComponent implements OnInit {
|
2020-07-30 13:50:21 +07:00
|
|
|
mempoolBlocksData$: Observable<MempoolBlocksData>;
|
|
|
|
mempoolInfoData$: Observable<MempoolInfoData>;
|
2020-08-19 11:33:18 +07:00
|
|
|
vBytesPerSecondLimit = 1667;
|
2020-02-17 20:39:20 +07:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private stateService: StateService,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-08-12 13:33:58 +07:00
|
|
|
this.mempoolInfoData$ = combineLatest([
|
|
|
|
this.stateService.mempoolInfo$,
|
|
|
|
this.stateService.vbytesPerSecond$
|
|
|
|
])
|
|
|
|
.pipe(
|
|
|
|
map(([mempoolInfo, vbytesPerSecond]) => {
|
2020-08-19 11:33:18 +07:00
|
|
|
const percent = Math.round((Math.min(vbytesPerSecond, this.vBytesPerSecondLimit) / this.vBytesPerSecondLimit) * 100);
|
2020-02-17 20:39:20 +07:00
|
|
|
|
2020-08-12 13:33:58 +07:00
|
|
|
let progressClass = 'bg-danger';
|
|
|
|
if (percent <= 75) {
|
|
|
|
progressClass = 'bg-success';
|
|
|
|
} else if (percent <= 99) {
|
|
|
|
progressClass = 'bg-warning';
|
|
|
|
}
|
2020-02-17 20:39:20 +07:00
|
|
|
|
2020-08-12 13:33:58 +07:00
|
|
|
return {
|
|
|
|
memPoolInfo: mempoolInfo,
|
2020-08-19 11:33:18 +07:00
|
|
|
vBytesPerSecond: vbytesPerSecond,
|
2020-08-12 13:33:58 +07:00
|
|
|
progressWidth: percent + '%',
|
|
|
|
progressClass: progressClass,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
2020-02-17 20:39:20 +07:00
|
|
|
|
2020-07-30 13:50:21 +07:00
|
|
|
this.mempoolBlocksData$ = this.stateService.mempoolBlocks$
|
|
|
|
.pipe(
|
|
|
|
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);
|
2020-02-17 20:39:20 +07:00
|
|
|
|
2020-07-30 13:50:21 +07:00
|
|
|
return {
|
|
|
|
size: size,
|
2021-07-31 17:30:35 +03:00
|
|
|
blocks: Math.ceil(vsize / this.stateService.blockVSize)
|
2020-07-30 13:50:21 +07:00
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
2020-02-17 20:39:20 +07:00
|
|
|
}
|
|
|
|
}
|