Live 2H graph is now fetched through the websocket.

Tell the web socket what to fetch with "want" request.
This commit is contained in:
Simon Lindh
2019-07-26 12:48:32 +03:00
parent 2b6426a126
commit 8dd58db42a
10 changed files with 122 additions and 105 deletions

View File

@@ -13,7 +13,7 @@ const API_BASE_URL = '/api/v1';
providedIn: 'root'
})
export class ApiService {
private websocketSubject: Observable<IMempoolDefaultResponse> = webSocket<IMempoolDefaultResponse | any>(WEB_SOCKET_URL)
private websocketSubject: Observable<IMempoolDefaultResponse> = webSocket<IMempoolDefaultResponse | any>(WEB_SOCKET_URL);
constructor(
private httpClient: HttpClient,
@@ -91,12 +91,16 @@ export class ApiService {
notFound: txShowTxNotFound,
});
}
}),
if (response['live-2h-chart']) {
this.memPoolService.live2Chart$.next(response['live-2h-chart']);
}
},
(err: Error) => {
console.log(err);
console.log('Error, retrying in 10 sec');
setTimeout(() => this.startSubscription(), 10000);
};
});
}
sendWebSocket(data: any) {
@@ -112,15 +116,6 @@ export class ApiService {
return this.httpClient.get<IBlockTransaction[]>(API_BASE_URL + '/transactions/projected/' + index);
}
listLiveStatistics$(lastId: number): Observable<IMempoolStats[]> {
const params = new HttpParams()
.set('lastId', lastId.toString());
return this.httpClient.get<IMempoolStats[]>(API_BASE_URL + '/statistics/live', {
params: params
});
}
list2HStatistics$(): Observable<IMempoolStats[]> {
return this.httpClient.get<IMempoolStats[]>(API_BASE_URL + '/statistics/2h');
}

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { ReplaySubject, BehaviorSubject } from 'rxjs';
import { IMempoolInfo, IBlock, IProjectedBlock, ITransaction } from '../blockchain/interfaces';
import { ReplaySubject, BehaviorSubject, Subject } from 'rxjs';
import { IMempoolInfo, IBlock, IProjectedBlock, ITransaction, IMempoolStats } from '../blockchain/interfaces';
export interface IMemPoolState {
memPoolInfo: IMempoolInfo;
@@ -24,6 +24,7 @@ export class MemPoolService {
txIdSearch$ = new ReplaySubject<string>();
conversions$ = new ReplaySubject<any>();
mempoolWeight$ = new ReplaySubject<number>();
live2Chart$ = new Subject<IMempoolStats>();
txTracking$ = new BehaviorSubject<ITxTracking>({
enabled: false,
tx: null,