Merge pull request #3941 from mempool/mononaut/reset-latest-txs

reset blocks$ and transactions$ observables when network changes
This commit is contained in:
softsimon 2023-07-12 17:52:06 +09:00 committed by GitHub
commit 7ad1ace8dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,11 +1,11 @@
import { Inject, Injectable, PLATFORM_ID, LOCALE_ID } from '@angular/core'; import { Inject, Injectable, PLATFORM_ID, LOCALE_ID } from '@angular/core';
import { ReplaySubject, BehaviorSubject, Subject, fromEvent, Observable, merge } from 'rxjs'; import { ReplaySubject, BehaviorSubject, Subject, fromEvent, Observable, merge } from 'rxjs';
import { Transaction } from '../interfaces/electrs.interface'; import { Transaction } from '../interfaces/electrs.interface';
import { IBackendInfo, MempoolBlock, MempoolBlockWithTransactions, MempoolBlockDelta, MempoolInfo, Recommendedfees, ReplacedTransaction, TransactionStripped } from '../interfaces/websocket.interface'; import { IBackendInfo, MempoolBlock, MempoolBlockDelta, MempoolInfo, Recommendedfees, ReplacedTransaction, TransactionStripped } from '../interfaces/websocket.interface';
import { BlockExtended, DifficultyAdjustment, MempoolPosition, OptimizedMempoolStats, RbfTree } from '../interfaces/node-api.interface'; import { BlockExtended, DifficultyAdjustment, MempoolPosition, OptimizedMempoolStats, RbfTree } from '../interfaces/node-api.interface';
import { Router, NavigationStart } from '@angular/router'; import { Router, NavigationStart } from '@angular/router';
import { isPlatformBrowser } from '@angular/common'; import { isPlatformBrowser } from '@angular/common';
import { map, scan, shareReplay, tap } from 'rxjs/operators'; import { map, scan, shareReplay } from 'rxjs/operators';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
export interface MarkBlockState { export interface MarkBlockState {
@ -198,6 +198,11 @@ export class StateService {
this.networkChanged$.next(this.env.BASE_MODULE); this.networkChanged$.next(this.env.BASE_MODULE);
} }
this.networkChanged$.subscribe((network) => {
this.transactions$ = new ReplaySubject<TransactionStripped>(6);
this.blocks$ = new ReplaySubject<[BlockExtended, string]>(this.env.KEEP_BLOCKS_AMOUNT);
});
this.blockVSize = this.env.BLOCK_WEIGHT_UNITS / 4; this.blockVSize = this.env.BLOCK_WEIGHT_UNITS / 4;
const savedTimePreference = this.storageService.getValue('time-preference-ltr'); const savedTimePreference = this.storageService.getValue('time-preference-ltr');