2019-07-21 17:59:47 +03:00
|
|
|
import { Injectable } from '@angular/core';
|
2020-02-28 01:09:07 +07:00
|
|
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
2020-02-17 00:26:57 +07:00
|
|
|
import { OptimizedMempoolStats } from '../interfaces/node-api.interface';
|
2019-07-21 17:59:47 +03:00
|
|
|
import { Observable } from 'rxjs';
|
2020-05-09 20:37:50 +07:00
|
|
|
import { StateService } from './state.service';
|
2019-07-21 17:59:47 +03:00
|
|
|
|
2020-05-09 20:37:50 +07:00
|
|
|
const API_BASE_URL = '/api{network}/v1';
|
2019-07-21 17:59:47 +03:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class ApiService {
|
2020-05-09 20:37:50 +07:00
|
|
|
apiBaseUrl: string;
|
|
|
|
|
2019-07-21 17:59:47 +03:00
|
|
|
constructor(
|
|
|
|
private httpClient: HttpClient,
|
2020-05-09 20:37:50 +07:00
|
|
|
private stateService: StateService,
|
|
|
|
) {
|
|
|
|
this.apiBaseUrl = API_BASE_URL.replace('{network}', '');
|
|
|
|
this.stateService.networkChanged$.subscribe((network) => {
|
|
|
|
this.apiBaseUrl = API_BASE_URL.replace('{network}', network ? '/' + network : '');
|
|
|
|
});
|
|
|
|
}
|
2019-11-06 15:35:02 +08:00
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
list2HStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-05-09 20:37:50 +07:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + '/statistics/2h');
|
2019-11-12 16:39:59 +08:00
|
|
|
}
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
list24HStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-05-09 20:37:50 +07:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + '/statistics/24h');
|
2019-11-12 16:39:59 +08:00
|
|
|
}
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
list1WStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-05-09 20:37:50 +07:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + '/statistics/1w');
|
2019-11-10 16:44:00 +08:00
|
|
|
}
|
2019-11-13 14:51:44 +08:00
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
list1MStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-05-09 20:37:50 +07:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + '/statistics/1m');
|
2019-11-13 14:51:44 +08:00
|
|
|
}
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
list3MStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-05-09 20:37:50 +07:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + '/statistics/3m');
|
2019-11-13 14:51:44 +08:00
|
|
|
}
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
list6MStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-05-09 20:37:50 +07:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + '/statistics/6m');
|
2020-02-17 00:26:57 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
list1YStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-05-09 20:37:50 +07:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + '/statistics/1y');
|
2019-11-13 14:51:44 +08:00
|
|
|
}
|
2020-02-28 01:09:07 +07:00
|
|
|
|
|
|
|
getTransactionTimes$(txIds: string[]): Observable<number[]> {
|
|
|
|
let params = new HttpParams();
|
|
|
|
txIds.forEach((txId: string) => {
|
|
|
|
params = params.append('txId[]', txId);
|
|
|
|
});
|
2020-05-09 20:37:50 +07:00
|
|
|
return this.httpClient.get<number[]>(this.apiBaseUrl + '/transaction-times', { params });
|
2020-02-28 01:09:07 +07:00
|
|
|
}
|
2019-07-21 17:59:47 +03:00
|
|
|
}
|