Transaction, address and block page now works.

This commit is contained in:
softsimon
2020-11-22 23:47:27 +07:00
parent 24aed09489
commit bd1440ce96
9 changed files with 61 additions and 29 deletions

View File

@@ -1,8 +1,7 @@
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { OptimizedMempoolStats } from '../interfaces/node-api.interface';
import { Observable } from 'rxjs';
import { isPlatformBrowser } from '@angular/common';
import { StateService } from './state.service';
import { env } from '../app.constants';
import { WebsocketResponse } from '../interfaces/websocket.interface';
@@ -14,25 +13,23 @@ const API_BASE_URL = '{network}/api/v1';
})
export class ApiService {
private apiBaseUrl: string;
private isBrowser: boolean = isPlatformBrowser(this.platformId);
constructor(
private httpClient: HttpClient,
private stateService: StateService,
@Inject(PLATFORM_ID) private platformId: any,
) {
this.stateService.networkChanged$.subscribe((network) => {
if (network === 'bisq' && !env.BISQ_SEPARATE_BACKEND) {
network = '';
}
this.apiBaseUrl = API_BASE_URL.replace('{network}', network ? '/' + network : '');
if (!this.isBrowser) {
if (!stateService.isBrowser) {
this.apiBaseUrl = 'http://localhost:8999' + this.apiBaseUrl;
}
});
this.apiBaseUrl = API_BASE_URL.replace('{network}', '');
if (!this.isBrowser) {
if (!stateService.isBrowser) {
this.apiBaseUrl = 'http://localhost:8999' + this.apiBaseUrl;
}
}

View File

@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { shareReplay } from 'rxjs/operators';
import { StateService } from './state.service';
@Injectable({
providedIn: 'root'
@@ -13,9 +14,15 @@ export class AssetsService {
constructor(
private httpClient: HttpClient,
private stateService: StateService,
) {
this.getAssetsJson$ = this.httpClient.get('/resources/assets.json').pipe(shareReplay());
this.getAssetsMinimalJson$ = this.httpClient.get('/resources/assets.minimal.json').pipe(shareReplay());
this.getMiningPools$ = this.httpClient.get('/resources/pools.json').pipe(shareReplay());
let baseApiUrl = '';
if (!this.stateService.isBrowser) {
baseApiUrl = 'http://localhost:4200/';
}
this.getAssetsJson$ = this.httpClient.get(baseApiUrl + '/resources/assets.json').pipe(shareReplay());
this.getAssetsMinimalJson$ = this.httpClient.get(baseApiUrl + '/resources/assets.minimal.json').pipe(shareReplay());
this.getMiningPools$ = this.httpClient.get(baseApiUrl + '/resources/pools.json').pipe(shareReplay());
}
}

View File

@@ -1,5 +1,4 @@
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Block, Transaction, Address, Outspend, Recent, Asset } from '../interfaces/electrs.interface';
@@ -12,14 +11,12 @@ let API_BASE_URL = '{network}/api';
})
export class ElectrsApiService {
private apiBaseUrl: string;
private isBrowser: boolean = isPlatformBrowser(this.platformId);
constructor(
private httpClient: HttpClient,
private stateService: StateService,
@Inject(PLATFORM_ID) private platformId: any,
) {
if (!this.isBrowser) {
if (!stateService.isBrowser) {
API_BASE_URL = 'http://localhost:4200/api';
}
this.apiBaseUrl = API_BASE_URL.replace('{network}', '');

View File

@@ -1,11 +1,10 @@
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { Injectable } from '@angular/core';
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
import { WebsocketResponse } from '../interfaces/websocket.interface';
import { StateService } from './state.service';
import { Block, Transaction } from '../interfaces/electrs.interface';
import { Subscription } from 'rxjs';
import { env } from '../app.constants';
import { isPlatformBrowser } from '@angular/common';
import { ApiService } from './api.service';
import { take } from 'rxjs/operators';
@@ -29,14 +28,14 @@ export class WebsocketService {
private onlineCheckTimeoutTwo: number;
private subscription: Subscription;
private network = '';
private isBrowser: boolean = isPlatformBrowser(this.platformId);
constructor(
private stateService: StateService,
private apiService: ApiService,
@Inject(PLATFORM_ID) private platformId: any,
) {
if (!this.isBrowser) {
if (!this.stateService.isBrowser) {
// @ts-ignore
this.websocketSubject = { next: () => {}};
this.stateService.isLoadingWebSocket$.next(false);
this.apiService.getInitData$()
.pipe(take(1))
@@ -147,7 +146,7 @@ export class WebsocketService {
}
want(data: string[], force = false) {
if (!this.isBrowser) {
if (!this.stateService.isBrowser) {
return;
}
if (data === this.lastWant && !force) {