frontend resync recent blocks when necessary

This commit is contained in:
Mononaut 2023-06-12 16:32:04 -04:00
parent ca6ddd609d
commit eaad63a082
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E
3 changed files with 11 additions and 2 deletions

View File

@ -116,7 +116,7 @@ class WebsocketHandler {
} }
// send initial data when a client first starts a subscription // 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']; response['blocks'] = this.socketData['blocks'];
} }

View File

@ -31,6 +31,7 @@ export interface WebsocketResponse {
'track-rbf'?: string; 'track-rbf'?: string;
'watch-mempool'?: boolean; 'watch-mempool'?: boolean;
'track-bisq-market'?: string; 'track-bisq-market'?: string;
'refresh-blocks'?: boolean;
} }
export interface ReplacedTransaction extends Transaction { export interface ReplacedTransaction extends Transaction {

View File

@ -235,6 +235,8 @@ export class WebsocketService {
} }
handleResponse(response: WebsocketResponse) { handleResponse(response: WebsocketResponse) {
let reinitBlocks = false;
if (response.blocks && response.blocks.length) { if (response.blocks && response.blocks.length) {
const blocks = response.blocks; const blocks = response.blocks;
let maxHeight = 0; let maxHeight = 0;
@ -256,9 +258,11 @@ export class WebsocketService {
} }
if (response.block) { 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.updateChainTip(response.block.height);
this.stateService.blocks$.next([response.block, response.txConfirmed || '']); this.stateService.blocks$.next([response.block, response.txConfirmed || '']);
} else if (response.block.height > this.stateService.latestBlockHeight + 1) {
reinitBlocks = true;
} }
if (response.txConfirmed) { if (response.txConfirmed) {
@ -369,5 +373,9 @@ export class WebsocketService {
if (response['git-commit']) { if (response['git-commit']) {
this.stateService.backendInfo$.next(response['git-commit']); this.stateService.backendInfo$.next(response['git-commit']);
} }
if (reinitBlocks) {
this.websocketSubject.next({'refresh-blocks': true});
}
} }
} }