From 1ae5f053169815b9f68ebb8027e28cc8c68296a8 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sat, 28 Oct 2023 23:30:58 +0000 Subject: [PATCH] SSR: init latest replacements on server side --- .../src/app/services/websocket.service.ts | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/services/websocket.service.ts b/frontend/src/app/services/websocket.service.ts index 25829ea3a..2256d174d 100644 --- a/frontend/src/app/services/websocket.service.ts +++ b/frontend/src/app/services/websocket.service.ts @@ -3,7 +3,7 @@ import { webSocket, WebSocketSubject } from 'rxjs/webSocket'; import { WebsocketResponse } from '../interfaces/websocket.interface'; import { StateService } from './state.service'; import { Transaction } from '../interfaces/electrs.interface'; -import { Subscription } from 'rxjs'; +import { firstValueFrom, Subscription } from 'rxjs'; import { ApiService } from './api.service'; import { take } from 'rxjs/operators'; import { TransferState, makeStateKey } from '@angular/core'; @@ -224,6 +224,7 @@ export class WebsocketService { } startTrackRbfSummary() { + this.initRbfSummary(); this.websocketSubject.next({ 'track-rbf-summary': true }); this.isTrackingRbfSummary = true; } @@ -446,4 +447,30 @@ export class WebsocketService { this.websocketSubject.next({'refresh-blocks': true}); } } + + async initRbfSummary(): Promise { + if (!this.stateService.isBrowser) { + const rbfList = await firstValueFrom(this.apiService.getRbfList$(false)); + if (rbfList) { + const rbfSummary = rbfList.slice(0, 6).map(rbfTree => { + let oldFee = 0; + let oldVsize = 0; + for (const replaced of rbfTree.replaces) { + oldFee += replaced.tx.fee; + oldVsize += replaced.tx.vsize; + } + return { + txid: rbfTree.tx.txid, + mined: !!rbfTree.tx.mined, + fullRbf: !!rbfTree.tx.fullRbf, + oldFee, + oldVsize, + newFee: rbfTree.tx.fee, + newVsize: rbfTree.tx.vsize, + }; + }); + this.stateService.rbfLatestSummary$.next(rbfSummary); + } + } + } }