mempool/frontend/src/app/components/rbf-list/rbf-list.component.ts

81 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-12-14 16:51:53 -06:00
import { Component, OnInit, ChangeDetectionStrategy, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, EMPTY, merge, Observable, Subscription } from 'rxjs';
import { catchError, switchMap, tap } from 'rxjs/operators';
import { WebsocketService } from 'src/app/services/websocket.service';
2022-12-17 09:39:06 -06:00
import { RbfTree } from '../../interfaces/node-api.interface';
2022-12-14 16:51:53 -06:00
import { ApiService } from '../../services/api.service';
import { StateService } from '../../services/state.service';
@Component({
selector: 'app-rbf-list',
templateUrl: './rbf-list.component.html',
styleUrls: ['./rbf-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RbfList implements OnInit, OnDestroy {
2022-12-17 09:39:06 -06:00
rbfTrees$: Observable<RbfTree[]>;
nextRbfSubject = new BehaviorSubject(null);
2022-12-14 16:51:53 -06:00
urlFragmentSubscription: Subscription;
fullRbfEnabled: boolean;
fullRbf: boolean;
isLoading = true;
constructor(
private route: ActivatedRoute,
private router: Router,
private apiService: ApiService,
public stateService: StateService,
private websocketService: WebsocketService,
) {
this.fullRbfEnabled = stateService.env.FULL_RBF_ENABLED;
}
ngOnInit(): void {
this.urlFragmentSubscription = this.route.fragment.subscribe((fragment) => {
this.fullRbf = (fragment === 'fullrbf');
this.websocketService.startTrackRbf(this.fullRbf ? 'fullRbf' : 'all');
2022-12-17 09:39:06 -06:00
this.nextRbfSubject.next(null);
2022-12-14 16:51:53 -06:00
});
2022-12-17 09:39:06 -06:00
this.rbfTrees$ = merge(
this.nextRbfSubject.pipe(
switchMap(() => {
return this.apiService.getRbfList$(this.fullRbf);
2022-12-14 16:51:53 -06:00
}),
catchError((e) => {
return EMPTY;
})
),
this.stateService.rbfLatest$
)
.pipe(
2022-12-17 09:39:06 -06:00
tap(() => {
2022-12-14 16:51:53 -06:00
this.isLoading = false;
})
);
}
toggleFullRbf(event) {
this.router.navigate([], {
relativeTo: this.route,
fragment: this.fullRbf ? null : 'fullrbf'
});
}
2022-12-17 09:39:06 -06:00
isFullRbf(tree: RbfTree): boolean {
return tree.fullRbf;
2022-12-14 16:51:53 -06:00
}
2022-12-17 09:39:06 -06:00
isMined(tree: RbfTree): boolean {
return tree.mined;
2022-12-14 16:51:53 -06:00
}
// pageChange(page: number) {
2022-12-17 09:39:06 -06:00
// this.fromTreeSubject.next(this.lastTreeId);
2022-12-14 16:51:53 -06:00
// }
ngOnDestroy(): void {
this.websocketService.stopTrackRbf();
}
}