From 354c119e9990fe30788c6cc09e607d8847702533 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sat, 29 Jul 2023 15:16:28 +0900 Subject: [PATCH] fix websocket connection state observable --- .../src/app/dashboard/dashboard.component.ts | 20 +++++++++++++------ .../src/app/services/websocket.service.ts | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/dashboard/dashboard.component.ts b/frontend/src/app/dashboard/dashboard.component.ts index 05381453d..38ee5f436 100644 --- a/frontend/src/app/dashboard/dashboard.component.ts +++ b/frontend/src/app/dashboard/dashboard.component.ts @@ -1,6 +1,6 @@ import { AfterViewInit, ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core'; import { combineLatest, merge, Observable, of, Subscription } from 'rxjs'; -import { filter, map, scan, share, switchMap, tap } from 'rxjs/operators'; +import { catchError, filter, map, scan, share, switchMap, tap } from 'rxjs/operators'; import { BlockExtended, OptimizedMempoolStats } from '../interfaces/node-api.interface'; import { MempoolInfo, TransactionStripped, ReplacementInfo } from '../interfaces/websocket.interface'; import { ApiService } from '../services/api.service'; @@ -171,7 +171,11 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit { this.mempoolStats$ = this.stateService.connectionState$ .pipe( filter((state) => state === 2), - switchMap(() => this.apiService.list2HStatistics$()), + switchMap(() => this.apiService.list2HStatistics$().pipe( + catchError((e) => { + return of(null); + }) + )), switchMap((mempoolStats) => { return merge( this.stateService.live2Chart$ @@ -186,10 +190,14 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit { ); }), map((mempoolStats) => { - return { - mempool: mempoolStats, - weightPerSecond: this.handleNewMempoolData(mempoolStats.concat([])), - }; + if (mempoolStats) { + return { + mempool: mempoolStats, + weightPerSecond: this.handleNewMempoolData(mempoolStats.concat([])), + }; + } else { + return null; + } }), share(), ); diff --git a/frontend/src/app/services/websocket.service.ts b/frontend/src/app/services/websocket.service.ts index e70424cdc..4bd20e987 100644 --- a/frontend/src/app/services/websocket.service.ts +++ b/frontend/src/app/services/websocket.service.ts @@ -113,7 +113,7 @@ export class WebsocketService { this.stateService.connectionState$.next(2); } - if (this.stateService.connectionState$.value === 1) { + if (this.stateService.connectionState$.value !== 2) { this.stateService.connectionState$.next(2); }