2022-02-08 18:56:51 +09:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2022-02-10 19:16:00 +09:00
|
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
2022-02-09 19:41:05 +09:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
2022-02-10 19:16:00 +09:00
|
|
|
import { once } from 'process';
|
|
|
|
import { BehaviorSubject, combineLatest, from, merge, Observable } from 'rxjs';
|
|
|
|
import { delay, distinctUntilChanged, map, scan, startWith, switchMap, tap } from 'rxjs/operators';
|
2022-02-09 19:41:05 +09:00
|
|
|
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>;
|
2022-02-10 19:16:00 +09:00
|
|
|
blocks$: Observable<BlockExtended[]>;
|
2022-02-09 19:41:05 +09:00
|
|
|
|
2022-02-10 19:16:00 +09:00
|
|
|
fromHeight: number = -1;
|
|
|
|
fromHeightSubject: BehaviorSubject<number> = new BehaviorSubject(this.fromHeight);
|
2022-02-09 19:41:05 +09:00
|
|
|
|
2022-02-10 19:16:00 +09:00
|
|
|
blocks: BlockExtended[] = [];
|
|
|
|
poolId: number = undefined;
|
|
|
|
isLoading = false;
|
|
|
|
radioGroupForm: FormGroup;
|
2022-02-09 19:41:05 +09:00
|
|
|
|
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-10 19:16:00 +09:00
|
|
|
private formBuilder: FormBuilder,
|
|
|
|
) {
|
|
|
|
this.radioGroupForm = this.formBuilder.group({ dateSpan: '1w' });
|
|
|
|
this.radioGroupForm.controls.dateSpan.setValue('1w');
|
|
|
|
}
|
2022-02-08 18:56:51 +09:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2022-02-10 19:16:00 +09:00
|
|
|
this.poolStats$ = combineLatest([
|
|
|
|
this.route.params.pipe(map((params) => params.poolId)),
|
|
|
|
this.radioGroupForm.get('dateSpan').valueChanges.pipe(startWith('1w')),
|
|
|
|
])
|
2022-02-09 19:41:05 +09:00
|
|
|
.pipe(
|
2022-02-10 19:16:00 +09:00
|
|
|
switchMap((params: any) => {
|
|
|
|
this.poolId = params[0];
|
|
|
|
if (this.blocks.length === 0) {
|
|
|
|
this.fromHeightSubject.next(undefined);
|
|
|
|
}
|
|
|
|
return this.apiService.getPoolStats$(this.poolId, params[1] ?? '1w');
|
2022-02-09 19:41:05 +09:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2022-02-10 19:16:00 +09:00
|
|
|
this.blocks$ = this.fromHeightSubject
|
|
|
|
.pipe(
|
|
|
|
distinctUntilChanged(),
|
|
|
|
switchMap((fromHeight) => {
|
|
|
|
return this.apiService.getPoolBlocks$(this.poolId, fromHeight);
|
|
|
|
}),
|
|
|
|
tap((newBlocks) => {
|
|
|
|
this.blocks = this.blocks.concat(newBlocks);
|
|
|
|
}),
|
|
|
|
map(() => this.blocks)
|
|
|
|
)
|
|
|
|
}
|
2022-02-09 19:41:05 +09:00
|
|
|
|
2022-02-10 19:16:00 +09:00
|
|
|
loadMore() {
|
|
|
|
this.fromHeightSubject.next(this.blocks[this.blocks.length - 1]?.height);
|
2022-02-09 19:41:05 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
trackByBlock(index: number, block: BlockExtended) {
|
|
|
|
return block.height;
|
2022-02-08 18:56:51 +09:00
|
|
|
}
|
|
|
|
}
|