mempool/frontend/src/app/components/pool/pool.component.ts

67 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-02-08 18:56:51 +09:00
import { Component, OnInit } from '@angular/core';
2022-02-09 19:41:05 +09:00
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { map, switchMap, tap } from 'rxjs/operators';
import { BlockExtended, PoolStat } from 'src/app/interfaces/node-api.interface';
import { ApiService } from 'src/app/services/api.service';
import { StateService } from 'src/app/services/state.service';
2022-02-08 18:56:51 +09:00
@Component({
selector: 'app-pool',
templateUrl: './pool.component.html',
styleUrls: ['./pool.component.scss']
})
export class PoolComponent implements OnInit {
2022-02-09 19:41:05 +09:00
poolStats$: Observable<PoolStat>;
isLoading = false;
poolId: number;
interval: string;
blocks: any[] = [];
2022-02-08 18:56:51 +09:00
constructor(
2022-02-09 19:41:05 +09:00
private apiService: ApiService,
private route: ActivatedRoute,
public stateService: StateService,
2022-02-08 18:56:51 +09:00
) { }
ngOnInit(): void {
2022-02-09 19:41:05 +09:00
this.poolStats$ = this.route.params
.pipe(
switchMap((params) => {
this.poolId = params.poolId;
this.interval = params.interval;
this.loadMore(2);
return this.apiService.getPoolStats$(params.poolId, params.interval ?? 'all');
}),
);
}
loadMore(chunks = 0) {
let fromHeight: number | undefined;
if (this.blocks.length > 0) {
fromHeight = this.blocks[this.blocks.length - 1].height - 1;
}
this.apiService.getPoolBlocks$(this.poolId, fromHeight)
.subscribe((blocks) => {
this.blocks = this.blocks.concat(blocks);
const chunksLeft = chunks - 1;
if (chunksLeft > 0) {
this.loadMore(chunksLeft);
}
// this.cd.markForCheck();
},
(error) => {
console.log(error);
// this.cd.markForCheck();
});
}
trackByBlock(index: number, block: BlockExtended) {
return block.height;
2022-02-08 18:56:51 +09:00
}
}