2020-11-22 23:47:27 +07:00
|
|
|
import { Injectable } from '@angular/core';
|
2020-11-07 04:30:52 +07:00
|
|
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
2021-03-18 23:47:40 +07:00
|
|
|
import { CpfpInfo, 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';
|
2020-11-07 04:30:52 +07:00
|
|
|
import { WebsocketResponse } from '../interfaces/websocket.interface';
|
2019-07-21 17:59:47 +03:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class ApiService {
|
2020-11-27 23:01:47 +09:00
|
|
|
private apiBaseUrl: string; // base URL is protocol, hostname, and port
|
|
|
|
private apiBasePath: string; // network path is /testnet, etc. or '' for mainnet
|
2020-05-09 20:37:50 +07:00
|
|
|
|
2019-07-21 17:59:47 +03:00
|
|
|
constructor(
|
|
|
|
private httpClient: HttpClient,
|
2020-05-09 20:37:50 +07:00
|
|
|
private stateService: StateService,
|
|
|
|
) {
|
2020-11-27 23:01:47 +09:00
|
|
|
this.apiBaseUrl = ''; // use relative URL by default
|
|
|
|
if (!stateService.isBrowser) { // except when inside AU SSR process
|
|
|
|
this.apiBaseUrl = this.stateService.env.NGINX_PROTOCOL + '://' + this.stateService.env.NGINX_HOSTNAME + ':' + this.stateService.env.NGINX_PORT;
|
|
|
|
}
|
|
|
|
this.apiBasePath = ''; // assume mainnet by default
|
2020-05-09 20:37:50 +07:00
|
|
|
this.stateService.networkChanged$.subscribe((network) => {
|
2020-11-23 02:30:46 +07:00
|
|
|
if (network === 'bisq' && !this.stateService.env.BISQ_SEPARATE_BACKEND) {
|
2020-07-03 23:45:19 +07:00
|
|
|
network = '';
|
|
|
|
}
|
2020-11-27 23:01:47 +09:00
|
|
|
this.apiBasePath = network ? '/' + network : '';
|
2020-05-09 20:37:50 +07:00
|
|
|
});
|
|
|
|
}
|
2019-11-06 15:35:02 +08:00
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
list2HStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-11-27 23:01:47 +09:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/statistics/2h');
|
2019-11-12 16:39:59 +08:00
|
|
|
}
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
list24HStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-11-27 23:01:47 +09:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/statistics/24h');
|
2019-11-12 16:39:59 +08:00
|
|
|
}
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
list1WStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-11-27 23:01:47 +09:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/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-11-27 23:01:47 +09:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/statistics/1m');
|
2019-11-13 14:51:44 +08:00
|
|
|
}
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
list3MStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-11-27 23:01:47 +09:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/statistics/3m');
|
2019-11-13 14:51:44 +08:00
|
|
|
}
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
list6MStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-11-27 23:01:47 +09:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/statistics/6m');
|
2020-02-17 00:26:57 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
list1YStatistics$(): Observable<OptimizedMempoolStats[]> {
|
2020-11-27 23:01:47 +09:00
|
|
|
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/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-11-27 23:01:47 +09:00
|
|
|
return this.httpClient.get<number[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/transaction-times', { params });
|
2020-02-28 01:09:07 +07:00
|
|
|
}
|
2020-10-07 20:15:42 +07:00
|
|
|
|
|
|
|
requestDonation$(amount: number, orderId: string): Observable<any> {
|
|
|
|
const params = {
|
|
|
|
amount: amount,
|
|
|
|
orderId: orderId,
|
|
|
|
};
|
2020-11-27 23:01:47 +09:00
|
|
|
return this.httpClient.post<any>(this.apiBaseUrl + this.apiBasePath + '/api/v1/donations', params);
|
2020-10-07 20:15:42 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
getDonation$(): Observable<any[]> {
|
2020-11-27 23:01:47 +09:00
|
|
|
return this.httpClient.get<any[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/donations');
|
2020-10-07 20:15:42 +07:00
|
|
|
}
|
2020-11-07 04:30:52 +07:00
|
|
|
|
2021-03-09 03:56:41 +09:00
|
|
|
getContributor$(): Observable<any[]> {
|
|
|
|
return this.httpClient.get<any[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/contributors');
|
|
|
|
}
|
|
|
|
|
2021-02-07 02:20:07 +07:00
|
|
|
checkDonation$(orderId: string): Observable<any[]> {
|
|
|
|
return this.httpClient.get<any[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/donations/check?order_id=' + orderId);
|
|
|
|
}
|
|
|
|
|
2020-11-07 04:30:52 +07:00
|
|
|
getInitData$(): Observable<WebsocketResponse> {
|
2020-11-27 23:01:47 +09:00
|
|
|
return this.httpClient.get<WebsocketResponse>(this.apiBaseUrl + this.apiBasePath + '/api/v1/init-data');
|
2020-11-07 04:30:52 +07:00
|
|
|
}
|
2021-03-18 23:47:40 +07:00
|
|
|
|
|
|
|
getCpfpinfo$(txid: string): Observable<CpfpInfo> {
|
|
|
|
return this.httpClient.get<CpfpInfo>(this.apiBaseUrl + this.apiBasePath + '/api/v1/cpfp/' + txid);
|
|
|
|
}
|
2019-07-21 17:59:47 +03:00
|
|
|
}
|