Replace acceleration API polling with websocket
This commit is contained in:
@@ -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']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user