From 35c4d9676ce931d4a0df40fb8c63204507f56778 Mon Sep 17 00:00:00 2001 From: Simon Lindh Date: Thu, 24 Oct 2019 15:37:39 +0800 Subject: [PATCH] Resume transaction tracking after reconnect. --- backend/src/api/projected-blocks.ts | 2 +- frontend/src/app/blockchain/blockchain.component.ts | 11 +++++++++++ frontend/src/app/services/api.service.ts | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/src/api/projected-blocks.ts b/backend/src/api/projected-blocks.ts index bdc9569e8..4f8b590a8 100644 --- a/backend/src/api/projected-blocks.ts +++ b/backend/src/api/projected-blocks.ts @@ -74,7 +74,7 @@ class ProjectedBlocks { return { blockSize: blockSize, blockWeight: blockWeight, - nTx: transactions.length - 1, + nTx: transactions.length, minFee: transactions[transactions.length - 1].feePerVsize, maxFee: transactions[0].feePerVsize, minWeightFee: transactions[transactions.length - 1].feePerWeightUnit, diff --git a/frontend/src/app/blockchain/blockchain.component.ts b/frontend/src/app/blockchain/blockchain.component.ts index 2c4748f13..66f5dfad2 100644 --- a/frontend/src/app/blockchain/blockchain.component.ts +++ b/frontend/src/app/blockchain/blockchain.component.ts @@ -41,6 +41,10 @@ export class BlockchainComponent implements OnInit, OnDestroy { this.route.paramMap .subscribe((params: ParamMap) => { + if (this.memPoolService.txTracking$.value.enabled) { + return; + } + const txId: string | null = params.get('id'); if (!txId) { return; @@ -52,6 +56,13 @@ export class BlockchainComponent implements OnInit, OnDestroy { this.memPoolService.txIdSearch$ .subscribe((txId) => { if (txId) { + + if (this.memPoolService.txTracking$.value.enabled + && this.memPoolService.txTracking$.value.tx + && this.memPoolService.txTracking$.value.tx.txid === txId) { + return; + } + console.log('enabling tracking loading from idSearch!'); this.txTrackingLoading = true; this.apiService.webSocketStartTrackTx(txId); } diff --git a/frontend/src/app/services/api.service.ts b/frontend/src/app/services/api.service.ts index 3b3f20185..32baab713 100644 --- a/frontend/src/app/services/api.service.ts +++ b/frontend/src/app/services/api.service.ts @@ -17,6 +17,7 @@ export class ApiService { private websocketSubject: Observable = webSocket(WEB_SOCKET_URL); private lastWant: string[] | null = null; private goneOffline = false; + private lastTrackedTxId = ''; constructor( private httpClient: HttpClient, @@ -68,7 +69,7 @@ export class ApiService { this.memPoolService.conversions$.next(response.conversions); } - if (response['track-tx']) { + if (response['track-tx'] && !this.goneOffline) { let txTrackingEnabled; let txTrackingBlockHeight; let txTrackingTx = null; @@ -104,6 +105,9 @@ export class ApiService { if (this.lastWant) { this.webSocketWant(this.lastWant); } + if (this.memPoolService.txTracking$.value.enabled) { + this.webSocketStartTrackTx(this.lastTrackedTxId); + } } }, (err: Error) => { @@ -117,6 +121,7 @@ export class ApiService { webSocketStartTrackTx(txId: string) { // @ts-ignore this.websocketSubject.next({'action': 'track-tx', 'txId': txId}); + this.lastTrackedTxId = txId; } webSocketWant(data: string[]) {