import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { OptimizedMempoolStats } from '../interfaces/node-api.interface'; import { Observable } from 'rxjs'; import { StateService } from './state.service'; import { WebsocketResponse } from '../interfaces/websocket.interface'; const API_BASE_URL = '{network}/api/v1'; @Injectable({ providedIn: 'root' }) export class ApiService { private apiBaseUrl: string; constructor( private httpClient: HttpClient, private stateService: StateService, ) { this.stateService.networkChanged$.subscribe((network) => { if (network === 'bisq' && !this.stateService.env.BISQ_SEPARATE_BACKEND) { network = ''; } this.apiBaseUrl = API_BASE_URL.replace('{network}', network ? '/' + network : ''); if (!stateService.isBrowser) { this.apiBaseUrl = this.stateService.env.BACKEND_URL + this.apiBaseUrl; } }); this.apiBaseUrl = API_BASE_URL.replace('{network}', ''); if (!stateService.isBrowser) { this.apiBaseUrl = this.stateService.env.BACKEND_URL + this.apiBaseUrl; } } list2HStatistics$(): Observable { return this.httpClient.get(this.apiBaseUrl + '/statistics/2h'); } list24HStatistics$(): Observable { return this.httpClient.get(this.apiBaseUrl + '/statistics/24h'); } list1WStatistics$(): Observable { return this.httpClient.get(this.apiBaseUrl + '/statistics/1w'); } list1MStatistics$(): Observable { return this.httpClient.get(this.apiBaseUrl + '/statistics/1m'); } list3MStatistics$(): Observable { return this.httpClient.get(this.apiBaseUrl + '/statistics/3m'); } list6MStatistics$(): Observable { return this.httpClient.get(this.apiBaseUrl + '/statistics/6m'); } list1YStatistics$(): Observable { return this.httpClient.get(this.apiBaseUrl + '/statistics/1y'); } getTransactionTimes$(txIds: string[]): Observable { let params = new HttpParams(); txIds.forEach((txId: string) => { params = params.append('txId[]', txId); }); return this.httpClient.get(this.apiBaseUrl + '/transaction-times', { params }); } requestDonation$(amount: number, orderId: string): Observable { const params = { amount: amount, orderId: orderId, }; return this.httpClient.post(this.apiBaseUrl + '/donations', params); } getDonation$(): Observable { return this.httpClient.get(this.apiBaseUrl + '/donations'); } getInitData$(): Observable { return this.httpClient.get(this.apiBaseUrl + '/init-data'); } }