frontend resync recent blocks when necessary

This commit is contained in:
Mononaut committed 2023-06-30 19:43:04 -04:00
1 parent ca6ddd609d
commit eaad63a082
3 files changed
+11 -2

No files matched your search

+1 -1
View File
@@ -116,7 +116,7 @@ class WebsocketHandler {
}
// send initial data when a client first starts a subscription
if (wantNow['want-blocks']) {
if (wantNow['want-blocks'] || (parsedMessage && parsedMessage['refresh-blocks'])) {
response['blocks'] = this.socketData['blocks'];
}
@@ -31,6 +31,7 @@ export interface WebsocketResponse {
'track-rbf'?: string;
'watch-mempool'?: boolean;
'track-bisq-market'?: string;
'refresh-blocks'?: boolean;
}
export interface ReplacedTransaction extends Transaction {
@@ -235,6 +235,8 @@ export class WebsocketService {
}
handleResponse(response: WebsocketResponse) {
let reinitBlocks = false;
if (response.blocks && response.blocks.length) {
const blocks = response.blocks;
let maxHeight = 0;
@@ -256,9 +258,11 @@ export class WebsocketService {
}
if (response.block) {
if (response.block.height > this.stateService.latestBlockHeight) {
if (response.block.height === this.stateService.latestBlockHeight + 1) {
this.stateService.updateChainTip(response.block.height);
this.stateService.blocks$.next([response.block, response.txConfirmed || '']);
} else if (response.block.height > this.stateService.latestBlockHeight + 1) {
reinitBlocks = true;
}
if (response.txConfirmed) {
@@ -369,5 +373,9 @@ export class WebsocketService {
if (response['git-commit']) {
this.stateService.backendInfo$.next(response['git-commit']);
}
if (reinitBlocks) {
this.websocketSubject.next({'refresh-blocks': true});
}
}
}