Transaction, address and block page now works.

This commit is contained in:
softsimon 2020-11-22 23:47:27 +07:00
parent 75726df275
commit 83126b83f1
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
9 changed files with 61 additions and 29 deletions

View File

@ -26,10 +26,20 @@ win.matchMedia = () => {
// @ts-ignore // @ts-ignore
win.setTimeout = (fn) => { fn(); }; win.setTimeout = (fn) => { fn(); };
win.document.body.scrollTo = (() => {}); win.document.body.scrollTo = (() => {});
// @ts-ignore
global['window'] = win; global['window'] = win;
global['document'] = win.document; global['document'] = win.document;
global['history'] = { state: { data: {} } }; // @ts-ignore
global['history'] = { state: { } };
global['localStorage'] = {
getItem: () => '',
setItem: () => {},
removeItem: () => {},
clear: () => {},
length: 0,
key: () => '',
};
// The Express app is exported so that it can be used by serverless Functions. // The Express app is exported so that it can be used by serverless Functions.

View File

@ -1,5 +1,6 @@
import { Component, Input, AfterViewInit, OnDestroy, ViewChild, ElementRef } from '@angular/core'; import { Component, Input, AfterViewInit, OnDestroy, ViewChild, ElementRef } from '@angular/core';
import * as QRCode from 'qrcode/build/qrcode.js'; import * as QRCode from 'qrcode/build/qrcode.js';
import { StateService } from 'src/app/services/state.service';
@Component({ @Component({
selector: 'app-qrcode', selector: 'app-qrcode',
@ -14,9 +15,14 @@ export class QrcodeComponent implements AfterViewInit {
qrcodeObject: any; qrcodeObject: any;
constructor() { } constructor(
private stateService: StateService,
) { }
ngAfterViewInit() { ngAfterViewInit() {
if (!this.stateService.isBrowser) {
return;
}
const opts = { const opts = {
errorCorrectionLevel: 'H', errorCorrectionLevel: 'H',
margin: 0, margin: 0,

View File

@ -1,14 +1,18 @@
import { import {
Component, Component,
ElementRef, ElementRef,
Inject,
Input, Input,
OnChanges, OnChanges,
OnDestroy, OnDestroy,
OnInit, OnInit,
PLATFORM_ID,
SimpleChanges, SimpleChanges,
ViewEncapsulation ViewEncapsulation
} from '@angular/core'; } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import * as Chartist from '@mempool/chartist'; import * as Chartist from '@mempool/chartist';
/** /**
@ -63,16 +67,25 @@ export class ChartistComponent implements OnInit, OnChanges, OnDestroy {
// @ts-ignore // @ts-ignore
@Input() public events: ChartEvent; @Input() public events: ChartEvent;
isBrowser: boolean = isPlatformBrowser(this.platformId);
// @ts-ignore // @ts-ignore
public chart: ChartInterfaces; public chart: ChartInterfaces;
private element: HTMLElement; private element: HTMLElement;
constructor(element: ElementRef) { constructor(
element: ElementRef,
@Inject(PLATFORM_ID) private platformId: any,
) {
this.element = element.nativeElement; this.element = element.nativeElement;
} }
public ngOnInit(): Promise<ChartInterfaces> { public ngOnInit(): Promise<ChartInterfaces> {
if (!this.isBrowser) {
return;
}
if (!this.type || !this.data) { if (!this.type || !this.data) {
Promise.reject('Expected at least type and data.'); Promise.reject('Expected at least type and data.');
} }
@ -87,6 +100,10 @@ export class ChartistComponent implements OnInit, OnChanges, OnDestroy {
} }
public ngOnChanges(changes: SimpleChanges): void { public ngOnChanges(changes: SimpleChanges): void {
if (!this.isBrowser) {
return;
}
this.update(changes); this.update(changes);
} }

View File

@ -1,5 +1,5 @@
import { isPlatformBrowser } from '@angular/common';
import { Component, OnInit, OnDestroy, ChangeDetectionStrategy, Input, ChangeDetectorRef, OnChanges, PLATFORM_ID, Inject } from '@angular/core'; import { Component, OnInit, OnDestroy, ChangeDetectionStrategy, Input, ChangeDetectorRef, OnChanges, PLATFORM_ID, Inject } from '@angular/core';
import { StateService } from 'src/app/services/state.service';
@Component({ @Component({
selector: 'app-time-since', selector: 'app-time-since',
@ -7,7 +7,6 @@ import { Component, OnInit, OnDestroy, ChangeDetectionStrategy, Input, ChangeDet
changeDetection: ChangeDetectionStrategy.OnPush changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class TimeSinceComponent implements OnInit, OnChanges, OnDestroy { export class TimeSinceComponent implements OnInit, OnChanges, OnDestroy {
isBrowser: boolean = isPlatformBrowser(this.platformId);
interval: number; interval: number;
text: string; text: string;
intervals = {}; intervals = {};
@ -17,7 +16,7 @@ export class TimeSinceComponent implements OnInit, OnChanges, OnDestroy {
constructor( constructor(
private ref: ChangeDetectorRef, private ref: ChangeDetectorRef,
@Inject(PLATFORM_ID) private platformId: any, private stateService: StateService,
) { ) {
if (document.body.clientWidth < 768) { if (document.body.clientWidth < 768) {
this.intervals = { this.intervals = {
@ -43,7 +42,7 @@ export class TimeSinceComponent implements OnInit, OnChanges, OnDestroy {
} }
ngOnInit() { ngOnInit() {
if (!this.isBrowser) { if (!this.stateService.isBrowser) {
this.text = this.calculate(); this.text = this.calculate();
this.ref.markForCheck(); this.ref.markForCheck();
return; return;

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 { HttpClient, HttpParams } from '@angular/common/http';
import { OptimizedMempoolStats } from '../interfaces/node-api.interface'; import { OptimizedMempoolStats } from '../interfaces/node-api.interface';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { isPlatformBrowser } from '@angular/common';
import { StateService } from './state.service'; import { StateService } from './state.service';
import { env } from '../app.constants'; import { env } from '../app.constants';
import { WebsocketResponse } from '../interfaces/websocket.interface'; import { WebsocketResponse } from '../interfaces/websocket.interface';
@ -14,25 +13,23 @@ const API_BASE_URL = '{network}/api/v1';
}) })
export class ApiService { export class ApiService {
private apiBaseUrl: string; private apiBaseUrl: string;
private isBrowser: boolean = isPlatformBrowser(this.platformId);
constructor( constructor(
private httpClient: HttpClient, private httpClient: HttpClient,
private stateService: StateService, private stateService: StateService,
@Inject(PLATFORM_ID) private platformId: any,
) { ) {
this.stateService.networkChanged$.subscribe((network) => { this.stateService.networkChanged$.subscribe((network) => {
if (network === 'bisq' && !env.BISQ_SEPARATE_BACKEND) { if (network === 'bisq' && !env.BISQ_SEPARATE_BACKEND) {
network = ''; network = '';
} }
this.apiBaseUrl = API_BASE_URL.replace('{network}', network ? '/' + 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 = 'http://localhost:8999' + this.apiBaseUrl;
} }
}); });
this.apiBaseUrl = API_BASE_URL.replace('{network}', ''); this.apiBaseUrl = API_BASE_URL.replace('{network}', '');
if (!this.isBrowser) { if (!stateService.isBrowser) {
this.apiBaseUrl = 'http://localhost:8999' + this.apiBaseUrl; 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 { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { shareReplay } from 'rxjs/operators'; import { shareReplay } from 'rxjs/operators';
import { StateService } from './state.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -13,9 +14,15 @@ export class AssetsService {
constructor( constructor(
private httpClient: HttpClient, private httpClient: HttpClient,
private stateService: StateService,
) { ) {
this.getAssetsJson$ = this.httpClient.get('/resources/assets.json').pipe(shareReplay()); let baseApiUrl = '';
this.getAssetsMinimalJson$ = this.httpClient.get('/resources/assets.minimal.json').pipe(shareReplay()); if (!this.stateService.isBrowser) {
this.getMiningPools$ = this.httpClient.get('/resources/pools.json').pipe(shareReplay()); 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 { Injectable } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { Block, Transaction, Address, Outspend, Recent, Asset } from '../interfaces/electrs.interface'; import { Block, Transaction, Address, Outspend, Recent, Asset } from '../interfaces/electrs.interface';
@ -12,14 +11,12 @@ let API_BASE_URL = '{network}/api';
}) })
export class ElectrsApiService { export class ElectrsApiService {
private apiBaseUrl: string; private apiBaseUrl: string;
private isBrowser: boolean = isPlatformBrowser(this.platformId);
constructor( constructor(
private httpClient: HttpClient, private httpClient: HttpClient,
private stateService: StateService, private stateService: StateService,
@Inject(PLATFORM_ID) private platformId: any,
) { ) {
if (!this.isBrowser) { if (!stateService.isBrowser) {
API_BASE_URL = 'http://localhost:4200/api'; API_BASE_URL = 'http://localhost:4200/api';
} }
this.apiBaseUrl = API_BASE_URL.replace('{network}', ''); 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 { webSocket, WebSocketSubject } from 'rxjs/webSocket';
import { WebsocketResponse } from '../interfaces/websocket.interface'; import { WebsocketResponse } from '../interfaces/websocket.interface';
import { StateService } from './state.service'; import { StateService } from './state.service';
import { Block, Transaction } from '../interfaces/electrs.interface'; import { Block, Transaction } from '../interfaces/electrs.interface';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { env } from '../app.constants'; import { env } from '../app.constants';
import { isPlatformBrowser } from '@angular/common';
import { ApiService } from './api.service'; import { ApiService } from './api.service';
import { take } from 'rxjs/operators'; import { take } from 'rxjs/operators';
@ -29,14 +28,14 @@ export class WebsocketService {
private onlineCheckTimeoutTwo: number; private onlineCheckTimeoutTwo: number;
private subscription: Subscription; private subscription: Subscription;
private network = ''; private network = '';
private isBrowser: boolean = isPlatformBrowser(this.platformId);
constructor( constructor(
private stateService: StateService, private stateService: StateService,
private apiService: ApiService, 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.stateService.isLoadingWebSocket$.next(false);
this.apiService.getInitData$() this.apiService.getInitData$()
.pipe(take(1)) .pipe(take(1))
@ -147,7 +146,7 @@ export class WebsocketService {
} }
want(data: string[], force = false) { want(data: string[], force = false) {
if (!this.isBrowser) { if (!this.stateService.isBrowser) {
return; return;
} }
if (data === this.lastWant && !force) { if (data === this.lastWant && !force) {

View File

@ -5,7 +5,7 @@
import * as domino from 'domino'; import * as domino from 'domino';
const win = domino.createWindow(); const win = domino.createWindow();
// @ts-ignore
global['window'] = win; global['window'] = win;
global['document'] = win.document; global['document'] = win.document;