2020-03-22 11:44:36 +01:00
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
2020-03-17 15:53:20 +01:00
|
|
|
import { StateService } from 'src/app/services/state.service';
|
|
|
|
import { ActivatedRoute, ParamMap } from '@angular/router';
|
2020-03-22 19:43:03 +01:00
|
|
|
import { switchMap, map, tap } from 'rxjs/operators';
|
2020-03-17 15:53:20 +01:00
|
|
|
import { MempoolBlock } from 'src/app/interfaces/websocket.interface';
|
2020-03-22 19:43:03 +01:00
|
|
|
import { Observable } from 'rxjs';
|
2020-03-17 15:53:20 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-mempool-block',
|
|
|
|
templateUrl: './mempool-block.component.html',
|
|
|
|
styleUrls: ['./mempool-block.component.scss']
|
|
|
|
})
|
2020-03-22 11:44:36 +01:00
|
|
|
export class MempoolBlockComponent implements OnInit, OnDestroy {
|
2020-03-17 15:53:20 +01:00
|
|
|
mempoolBlockIndex: number;
|
2020-03-22 19:43:03 +01:00
|
|
|
mempoolBlock$: Observable<MempoolBlock>;
|
2020-03-17 15:53:20 +01:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private stateService: StateService,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-03-22 19:43:03 +01:00
|
|
|
this.mempoolBlock$ = this.route.paramMap
|
|
|
|
.pipe(
|
|
|
|
switchMap((params: ParamMap) => {
|
|
|
|
this.mempoolBlockIndex = parseInt(params.get('id'), 10) || 0;
|
|
|
|
return this.stateService.mempoolBlocks$
|
|
|
|
.pipe(
|
|
|
|
map((mempoolBlocks) => {
|
|
|
|
while (!mempoolBlocks[this.mempoolBlockIndex]) {
|
|
|
|
this.mempoolBlockIndex--;
|
|
|
|
}
|
|
|
|
return mempoolBlocks[this.mempoolBlockIndex];
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
tap(() => {
|
|
|
|
this.stateService.markBlock$.next({ mempoolBlockIndex: this.mempoolBlockIndex });
|
|
|
|
})
|
|
|
|
);
|
2020-03-17 15:53:20 +01:00
|
|
|
}
|
|
|
|
|
2020-03-22 11:44:36 +01:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.stateService.markBlock$.next({});
|
|
|
|
}
|
|
|
|
|
2020-03-17 15:53:20 +01:00
|
|
|
}
|