Replace acceleration API polling with websocket

This commit is contained in:
Mononaut
2024-05-04 00:18:33 +00:00
parent 8ec5dd70e0
commit a29b29300e
8 changed files with 136 additions and 32 deletions

View File

@@ -33,6 +33,7 @@ export class WebsocketService {
private isTrackingRbfSummary = false;
private isTrackingAddress: string | false = false;
private isTrackingAddresses: string[] | false = false;
private isTrackingAccelerations: boolean = false;
private trackingMempoolBlock: number;
private latestGitCommit = '';
private onlineCheckTimeout: number;
@@ -132,6 +133,9 @@ export class WebsocketService {
if (this.isTrackingAddresses) {
this.startTrackAddresses(this.isTrackingAddresses);
}
if (this.isTrackingAccelerations) {
this.startTrackAccelerations();
}
this.stateService.connectionState$.next(2);
}
@@ -235,6 +239,24 @@ export class WebsocketService {
this.isTrackingRbfSummary = false;
}
startTrackAccelerations() {
this.websocketSubject.next({ 'track-accelerations': true });
this.isTrackingAccelerations = true;
}
stopTrackAccelerations() {
if (this.isTrackingAccelerations) {
this.websocketSubject.next({ 'track-accelerations': false });
this.isTrackingAccelerations = false;
}
}
ensureTrackAccelerations() {
if (!this.isTrackingAccelerations) {
this.startTrackAccelerations();
}
}
fetchStatistics(historicalDate: string) {
this.websocketSubject.next({ historicalDate });
}
@@ -416,6 +438,18 @@ export class WebsocketService {
}
}
if (response['accelerations']) {
if (response['accelerations'].accelerations) {
this.stateService.accelerations$.next({
added: response['accelerations'].accelerations,
removed: [],
reset: true,
});
} else {
this.stateService.accelerations$.next(response['accelerations']);
}
}
if (response['live-2h-chart']) {
this.stateService.live2Chart$.next(response['live-2h-chart']);
}