Frontend config support for AU. New absolute server url settings.

refs #104
This commit is contained in:
softsimon
2020-11-23 02:30:46 +07:00
parent bd1440ce96
commit d2cd595da6
16 changed files with 68 additions and 66 deletions

View File

@@ -3,7 +3,6 @@ import { HttpClient, HttpParams } from '@angular/common/http';
import { OptimizedMempoolStats } from '../interfaces/node-api.interface';
import { Observable } from 'rxjs';
import { StateService } from './state.service';
import { env } from '../app.constants';
import { WebsocketResponse } from '../interfaces/websocket.interface';
const API_BASE_URL = '{network}/api/v1';
@@ -19,18 +18,18 @@ export class ApiService {
private stateService: StateService,
) {
this.stateService.networkChanged$.subscribe((network) => {
if (network === 'bisq' && !env.BISQ_SEPARATE_BACKEND) {
if (network === 'bisq' && !this.stateService.env.BISQ_SEPARATE_BACKEND) {
network = '';
}
this.apiBaseUrl = API_BASE_URL.replace('{network}', network ? '/' + network : '');
if (!stateService.isBrowser) {
this.apiBaseUrl = 'http://localhost:8999' + this.apiBaseUrl;
this.apiBaseUrl = this.stateService.env.BACKEND_ABSOLUTE_URL + this.apiBaseUrl;
}
});
this.apiBaseUrl = API_BASE_URL.replace('{network}', '');
if (!stateService.isBrowser) {
this.apiBaseUrl = 'http://localhost:8999' + this.apiBaseUrl;
this.apiBaseUrl = this.stateService.env.BACKEND_ABSOLUTE_URL + this.apiBaseUrl;
}
}

View File

@@ -18,7 +18,7 @@ export class AssetsService {
) {
let baseApiUrl = '';
if (!this.stateService.isBrowser) {
baseApiUrl = 'http://localhost:4200/';
baseApiUrl = this.stateService.env.ELECTRS_ABSOLUTE_URL;
}
this.getAssetsJson$ = this.httpClient.get(baseApiUrl + '/resources/assets.json').pipe(shareReplay());

View File

@@ -17,7 +17,7 @@ export class ElectrsApiService {
private stateService: StateService,
) {
if (!stateService.isBrowser) {
API_BASE_URL = 'http://localhost:4200/api';
API_BASE_URL = this.stateService.env.ELECTRS_ABSOLUTE_URL + '/api';
}
this.apiBaseUrl = API_BASE_URL.replace('{network}', '');
this.stateService.networkChanged$.subscribe((network) => {

View File

@@ -4,7 +4,6 @@ import { Block, Transaction } from '../interfaces/electrs.interface';
import { MempoolBlock, MempoolInfo, TransactionStripped } from '../interfaces/websocket.interface';
import { OptimizedMempoolStats } from '../interfaces/node-api.interface';
import { Router, NavigationStart } from '@angular/router';
import { env } from '../app.constants';
import { isPlatformBrowser } from '@angular/common';
import { map, shareReplay } from 'rxjs/operators';
@@ -14,16 +13,39 @@ interface MarkBlockState {
txFeePerVSize?: number;
}
export interface Env {
TESTNET_ENABLED: boolean;
LIQUID_ENABLED: boolean;
BISQ_ENABLED: boolean;
BISQ_SEPARATE_BACKEND: boolean;
SPONSORS_ENABLED: boolean;
ELECTRS_ITEMS_PER_PAGE: number;
KEEP_BLOCKS_AMOUNT: number;
BACKEND_ABSOLUTE_URL?: string;
ELECTRS_ABSOLUTE_URL?: string;
}
const defaultEnv: Env = {
'TESTNET_ENABLED': false,
'LIQUID_ENABLED': false,
'BISQ_ENABLED': false,
'BISQ_SEPARATE_BACKEND': false,
'SPONSORS_ENABLED': false,
'ELECTRS_ITEMS_PER_PAGE': 25,
'KEEP_BLOCKS_AMOUNT': 8,
};
@Injectable({
providedIn: 'root'
})
export class StateService {
isBrowser: boolean = isPlatformBrowser(this.platformId);
network = '';
env: Env;
latestBlockHeight = 0;
networkChanged$ = new ReplaySubject<string>(1);
blocks$ = new ReplaySubject<[Block, boolean]>(env.KEEP_BLOCKS_AMOUNT);
blocks$: ReplaySubject<[Block, boolean]>;
transactions$ = new ReplaySubject<TransactionStripped>(6);
conversions$ = new ReplaySubject<any>(1);
bsqPrice$ = new ReplaySubject<number>(1);
@@ -64,6 +86,13 @@ export class StateService {
this.setNetworkBasedonUrl('/');
this.isTabHidden$ = new BehaviorSubject(false);
}
const browserWindow = window || {};
// @ts-ignore
const browserWindowEnv = browserWindow.__env || {};
this.env = Object.assign(defaultEnv, browserWindowEnv);
this.blocks$ = new ReplaySubject<[Block, boolean]>(this.env.KEEP_BLOCKS_AMOUNT);
}
setNetworkBasedonUrl(url: string) {

View File

@@ -4,12 +4,9 @@ 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 { ApiService } from './api.service';
import { take } from 'rxjs/operators';
const WEB_SOCKET_PROTOCOL = 'ws:';
const WEB_SOCKET_URL = WEB_SOCKET_PROTOCOL + '//localhost:8999{network}/api/v1/ws';
const OFFLINE_RETRY_AFTER_MS = 10000;
const OFFLINE_PING_CHECK_AFTER_MS = 30000;
@@ -19,6 +16,9 @@ const EXPECT_PING_RESPONSE_AFTER_MS = 4000;
providedIn: 'root'
})
export class WebsocketService {
private webSocketProtocol = (document.location.protocol === 'https:') ? 'wss:' : 'ws:';
private webSocketUrl = this.webSocketProtocol + '//' + document.location.hostname + ':' + document.location.port + '{network}/api/v1/ws';
private websocketSubject: WebSocketSubject<WebsocketResponse>;
private goneOffline = false;
private lastWant: string[] | null = null;
@@ -42,12 +42,12 @@ export class WebsocketService {
.subscribe((response) => this.handleResponse(response));
} else {
this.network = this.stateService.network === 'bisq' && !env.BISQ_SEPARATE_BACKEND ? '' : this.stateService.network;
this.websocketSubject = webSocket<WebsocketResponse>(WEB_SOCKET_URL.replace('{network}', this.network ? '/' + this.network : ''));
this.network = this.stateService.network === 'bisq' && !this.stateService.env.BISQ_SEPARATE_BACKEND ? '' : this.stateService.network;
this.websocketSubject = webSocket<WebsocketResponse>(this.webSocketUrl.replace('{network}', this.network ? '/' + this.network : ''));
this.startSubscription();
this.stateService.networkChanged$.subscribe((network) => {
if (network === 'bisq' && !env.BISQ_SEPARATE_BACKEND) {
if (network === 'bisq' && !this.stateService.env.BISQ_SEPARATE_BACKEND) {
network = '';
}
if (network === this.network) {
@@ -61,7 +61,9 @@ export class WebsocketService {
this.websocketSubject.complete();
this.subscription.unsubscribe();
this.websocketSubject = webSocket<WebsocketResponse>(WEB_SOCKET_URL.replace('{network}', this.network ? '/' + this.network : ''));
this.websocketSubject = webSocket<WebsocketResponse>(
this.webSocketUrl.replace('{network}', this.network ? '/' + this.network : '')
);
this.startSubscription();
});