mempool/frontend/src/app/services/assets.service.ts

37 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-05-02 12:36:35 +07:00
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
2021-12-29 00:42:34 +04:00
import { shareReplay, switchMap } from 'rxjs/operators';
import { StateService } from './state.service';
2020-05-02 12:36:35 +07:00
@Injectable({
providedIn: 'root'
})
export class AssetsService {
getAssetsJson$: Observable<any>;
getAssetsMinimalJson$: Observable<any>;
getMiningPools$: Observable<any>;
2020-05-02 12:36:35 +07:00
constructor(
private httpClient: HttpClient,
private stateService: StateService,
2020-05-02 12:36:35 +07:00
) {
let apiBaseUrl = '';
if (!this.stateService.isBrowser) {
apiBaseUrl = this.stateService.env.NGINX_PROTOCOL + '://' + this.stateService.env.NGINX_HOSTNAME + ':' + this.stateService.env.NGINX_PORT;
}
2021-12-29 00:42:34 +04:00
this.getAssetsJson$ = this.stateService.networkChanged$
.pipe(
switchMap(() => this.httpClient.get(`${apiBaseUrl}/resources/assets${this.stateService.network === 'liquidtestnet' ? '-testnet' : ''}.json`)),
shareReplay(1),
);
this.getAssetsMinimalJson$ = this.stateService.networkChanged$
.pipe(
switchMap(() => this.httpClient.get(`${apiBaseUrl}/resources/assets${this.stateService.network === 'liquidtestnet' ? '-testnet' : ''}.minimal.json`)),
shareReplay(1),
);
this.getMiningPools$ = this.httpClient.get(apiBaseUrl + '/resources/pools.json').pipe(shareReplay(1));
}
2020-05-02 12:36:35 +07:00
}