Merge pull request #1811 from mempool/simon/reload-mempool-visualizer-on-reconnect

Reload mempool visualization on reconnect
This commit is contained in:
wiz 2022-06-06 21:35:05 +09:00 committed by GitHub
commit e99a684354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

@ -116,12 +116,10 @@ class WebsocketHandler {
const index = parsedMessage['track-mempool-block']; const index = parsedMessage['track-mempool-block'];
client['track-mempool-block'] = index; client['track-mempool-block'] = index;
const mBlocksWithTransactions = mempoolBlocks.getMempoolBlocksWithTransactions(); const mBlocksWithTransactions = mempoolBlocks.getMempoolBlocksWithTransactions();
if (mBlocksWithTransactions[index]) { response['projected-block-transactions'] = {
response['projected-block-transactions'] = { index: index,
index: index, blockTransactions: mBlocksWithTransactions[index]?.transactions || [],
blockTransactions: mBlocksWithTransactions[index].transactions };
};
}
} else { } else {
client['track-mempool-block'] = null; client['track-mempool-block'] = null;
} }

View File

@ -1,8 +1,9 @@
import { Component, ElementRef, ViewChild, HostListener, Input, Output, EventEmitter, OnInit, import { Component, ElementRef, ViewChild, HostListener, Input, Output, EventEmitter, OnInit,
OnDestroy, OnChanges, ChangeDetectionStrategy, NgZone, AfterViewInit } from '@angular/core'; OnDestroy, OnChanges, ChangeDetectionStrategy, NgZone, AfterViewInit } from '@angular/core';
import { StateService } from 'src/app/services/state.service'; import { StateService } from 'src/app/services/state.service';
import { MempoolBlockWithTransactions, MempoolBlockDelta, TransactionStripped } from 'src/app/interfaces/websocket.interface'; import { MempoolBlockDelta, TransactionStripped } from 'src/app/interfaces/websocket.interface';
import { Subscription, BehaviorSubject } from 'rxjs'; import { Subscription, BehaviorSubject, merge, of } from 'rxjs';
import { switchMap, filter } from 'rxjs/operators';
import { WebsocketService } from 'src/app/services/websocket.service'; import { WebsocketService } from 'src/app/services/websocket.service';
import { FastVertexArray } from './fast-vertex-array'; import { FastVertexArray } from './fast-vertex-array';
import BlockScene from './block-scene'; import BlockScene from './block-scene';
@ -48,9 +49,14 @@ export class MempoolBlockOverviewComponent implements OnInit, OnDestroy, OnChang
} }
ngOnInit(): void { ngOnInit(): void {
this.blockSub = this.stateService.mempoolBlockTransactions$.subscribe((transactionsStripped) => { this.blockSub = merge(
this.replaceBlock(transactionsStripped); of(true),
}); this.stateService.connectionState$.pipe(filter((state) => state === 2))
)
.pipe(switchMap(() => this.stateService.mempoolBlockTransactions$))
.subscribe((transactionsStripped) => {
this.replaceBlock(transactionsStripped);
});
this.deltaSub = this.stateService.mempoolBlockDelta$.subscribe((delta) => { this.deltaSub = this.stateService.mempoolBlockDelta$.subscribe((delta) => {
this.updateBlock(delta); this.updateBlock(delta);
}); });