Improved how mempool blocks handle updates

This commit is contained in:
softsimon 2020-03-23 01:43:03 +07:00
parent bd641271a9
commit 245af5fa8f
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
2 changed files with 22 additions and 16 deletions

View File

@ -1,4 +1,4 @@
<div class="container-xl" *ngIf="mempoolBlock"> <div class="container-xl" *ngIf="mempoolBlock$ | async as mempoolBlock">
<div class="title-block"> <div class="title-block">
<h1>Mempool block</h1> <h1>Mempool block</h1>

View File

@ -1,8 +1,9 @@
import { Component, OnInit, OnDestroy } from '@angular/core'; import { Component, OnInit, OnDestroy } from '@angular/core';
import { StateService } from 'src/app/services/state.service'; import { StateService } from 'src/app/services/state.service';
import { ActivatedRoute, ParamMap } from '@angular/router'; import { ActivatedRoute, ParamMap } from '@angular/router';
import { switchMap, map } from 'rxjs/operators'; import { switchMap, map, tap } from 'rxjs/operators';
import { MempoolBlock } from 'src/app/interfaces/websocket.interface'; import { MempoolBlock } from 'src/app/interfaces/websocket.interface';
import { Observable } from 'rxjs';
@Component({ @Component({
selector: 'app-mempool-block', selector: 'app-mempool-block',
@ -11,7 +12,7 @@ import { MempoolBlock } from 'src/app/interfaces/websocket.interface';
}) })
export class MempoolBlockComponent implements OnInit, OnDestroy { export class MempoolBlockComponent implements OnInit, OnDestroy {
mempoolBlockIndex: number; mempoolBlockIndex: number;
mempoolBlock: MempoolBlock; mempoolBlock$: Observable<MempoolBlock>;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
@ -19,19 +20,24 @@ export class MempoolBlockComponent implements OnInit, OnDestroy {
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.route.paramMap.pipe( this.mempoolBlock$ = this.route.paramMap
.pipe(
switchMap((params: ParamMap) => { switchMap((params: ParamMap) => {
this.mempoolBlockIndex = parseInt(params.get('id'), 10) || 0; this.mempoolBlockIndex = parseInt(params.get('id'), 10) || 0;
this.stateService.markBlock$.next({ mempoolBlockIndex: this.mempoolBlockIndex });
return this.stateService.mempoolBlocks$ return this.stateService.mempoolBlocks$
.pipe( .pipe(
map((mempoolBlocks) => mempoolBlocks[this.mempoolBlockIndex]) map((mempoolBlocks) => {
); while (!mempoolBlocks[this.mempoolBlockIndex]) {
this.mempoolBlockIndex--;
}
return mempoolBlocks[this.mempoolBlockIndex];
}) })
) );
.subscribe((mempoolBlock) => { }),
this.mempoolBlock = mempoolBlock; tap(() => {
}); this.stateService.markBlock$.next({ mempoolBlockIndex: this.mempoolBlockIndex });
})
);
} }
ngOnDestroy(): void { ngOnDestroy(): void {