diff --git a/src/app/core/services/daemon/daemon-data.service.ts b/src/app/core/services/daemon/daemon-data.service.ts index 4674757..a612401 100644 --- a/src/app/core/services/daemon/daemon-data.service.ts +++ b/src/app/core/services/daemon/daemon-data.service.ts @@ -1,6 +1,6 @@ import { EventEmitter, Injectable, NgZone } from '@angular/core'; import { DaemonService } from './daemon.service'; -import { BlockCount, BlockHeader, Chain, Connection, CoreIsBusyError, DaemonInfo, MinerData, MiningStatus, NetHashRateHistory, NetStats, NetStatsHistory, PeerInfo, ProcessStats, PublicNode, SyncInfo, TimeUtils, TxBacklogEntry, TxPool, TxPoolStats } from '../../../../common'; +import { BlockCount, BlockHeader, Chain, CoreIsBusyError, DaemonInfo, MinerData, MiningStatus, NetHashRateHistory, NetStats, NetStatsHistory, ProcessStats, SyncInfo, TimeUtils, TxBacklogEntry, TxPool, TxPoolStats } from '../../../../common'; import { ElectronService } from '../electron/electron.service'; @Injectable({ @@ -13,7 +13,6 @@ export class DaemonDataService { private _refreshing: boolean = false; private _firstRefresh: boolean = true; private _lastRefresh: number = Date.now(); - private _lastRefreshHeight: number = -1; private _daemonRunning: boolean = false; @@ -51,18 +50,9 @@ export class DaemonDataService { private _minerDataCoreBusyError: boolean = false; private _gettingMinerData: boolean = false; - private _publicNodes: PublicNode[] = []; - private _gettingPublicNodes: boolean = false; - private _transactionPool?: TxPool; private _gettingTransactionPool: boolean = false; - private _connections: Connection[] = []; - private _gettingConnections: boolean = false; - - private _peerList: PeerInfo[] = []; - private _gettingPeerList: boolean = false; - private _txPoolBacklog: TxBacklogEntry[] = []; private _gettingTxPoolBackLog: boolean = false; @@ -217,14 +207,6 @@ export class DaemonDataService { return this._gettingMinerData; } - public get publicNodes(): PublicNode[] { - return this._publicNodes; - } - - public get gettingPublicNodes(): boolean { - return this._gettingPublicNodes; - } - public get transactionPool(): TxPool | undefined { return this._transactionPool; } @@ -233,22 +215,6 @@ export class DaemonDataService { return this._gettingTransactionPool; } - public get connections(): Connection[] { - return this._connections; - } - - public get gettingConnections(): boolean { - return this._gettingConnections; - } - - public get peerList(): PeerInfo[] { - return this._peerList; - } - - public get gettingPeerList(): boolean { - return this._gettingPeerList; - } - public get txPoolBacklog(): TxBacklogEntry[] { return this._txPoolBacklog; } @@ -512,14 +478,6 @@ export class DaemonDataService { await this.refreshMinerData(); } - this._gettingPeerList = true; - this._peerList = await this.daemonService.getPeerList(); - this._gettingPeerList = false; - - this._gettingPublicNodes = true; - this._publicNodes = await this.daemonService.getPublicNodes(true, true); - this._gettingPublicNodes = false; - if (this._daemonInfo.synchronized && this._daemonInfo.txPoolSize > 0) { this._gettingTransactionPool = true; this._transactionPool = await this.daemonService.getTransactionPool(); @@ -538,13 +496,6 @@ export class DaemonDataService { this._txPoolStats = undefined; } - if (!this.daemonService.settings.offline) { - this._gettingConnections = true; - this._connections = await this.daemonService.getConnections(); - this._gettingConnections = false; - } - - this._lastRefreshHeight = this._daemonInfo.heightWithoutBootstrap; this._lastRefresh = Date.now(); } catch(error: any) { console.error(error); @@ -555,10 +506,7 @@ export class DaemonDataService { this._gettingIsBlockchainPruned = false; this._gettingAltChains = false; this._gettingNetStats = false; - this._gettingPublicNodes = false; this._gettingTransactionPool = false; - this._gettingConnections = false; - this._gettingPeerList = false; this._gettingTxPoolStats = false; this.syncError.emit(error); diff --git a/src/app/pages/network/network.component.html b/src/app/pages/network/network.component.html index 89202e5..a41be92 100644 --- a/src/app/pages/network/network.component.html +++ b/src/app/pages/network/network.component.html @@ -59,6 +59,13 @@ + + +
+ + + +
diff --git a/src/app/pages/network/network.component.ts b/src/app/pages/network/network.component.ts index bc5b8f0..165033f 100644 --- a/src/app/pages/network/network.component.ts +++ b/src/app/pages/network/network.component.ts @@ -3,7 +3,7 @@ import { NavbarService } from '../../shared/components/navbar/navbar.service'; import { DaemonDataService, DaemonService } from '../../core/services'; import { NavbarLink } from '../../shared/components/navbar/navbar.model'; import { Chart, ChartData } from 'chart.js/auto' -import { NetStats, NetStatsHistoryEntry } from '../../../common'; +import { Connection, NetStats, NetStatsHistoryEntry } from '../../../common'; import { Subscription } from 'rxjs'; import { BasePageComponent } from '../base-page/base-page.component'; @@ -14,6 +14,7 @@ import { BasePageComponent } from '../base-page/base-page.component'; }) export class NetworkComponent extends BasePageComponent implements AfterViewInit, OnDestroy { + private connections?: Connection[]; private netStatsBytesInChart?: Chart; private netStatsBytesOutChart?: Chart; @@ -33,6 +34,8 @@ export class NetworkComponent extends BasePageComponent implements AfterViewInit public setLimitError: string = ''; public currentNetStats: NetStats; + public getConnectionsError: string = ''; + public refreshingConnectionsTable: boolean = false; constructor(navbarService: NavbarService, private daemonService: DaemonService, private daemonData: DaemonDataService) { super(navbarService); @@ -49,10 +52,6 @@ export class NetworkComponent extends BasePageComponent implements AfterViewInit this.refreshNetStatsHistory(); }); - const syncEndSub: Subscription = this.daemonData.syncEnd.subscribe(() => { - this.loadConnectionsTable(); - }); - const daemonStatusSub: Subscription = this.daemonService.onDaemonStatusChanged.subscribe((running: boolean) => { if (!running) { if (this.netStatsBytesInChart) { @@ -72,16 +71,31 @@ export class NetworkComponent extends BasePageComponent implements AfterViewInit } }); - this.subscriptions.push(netStatsRefreshStartSub, syncEndSub, daemonStatusSub); + this.subscriptions.push(netStatsRefreshStartSub, daemonStatusSub); } public ngAfterViewInit(): void { this.initNetStatsHistoryChart(); + this.refreshConnectionsTable().then().catch((error: any) => console.error(error)); + } + + public async refreshConnectionsTable(): Promise { + this.refreshingConnectionsTable = true; + + try { + this.connections = await this.daemonService.getConnections(); + } + catch(error: any) { + console.error(error); + this.connections = undefined; + } + this.loadConnectionsTable(); + this.refreshingConnectionsTable = false; } private loadConnectionsTable(): void { - this.loadTable('connectionsTable', this.daemonData.connections); + this.loadTable('connectionsTable', this.connections ? this.connections : [], this.connections === undefined && this.getConnectionsError == ''); } private buildChartBytesInData(): ChartData { diff --git a/src/app/pages/peers/peers.component.html b/src/app/pages/peers/peers.component.html index 7ad3d9e..83c83a1 100644 --- a/src/app/pages/peers/peers.component.html +++ b/src/app/pages/peers/peers.component.html @@ -68,6 +68,12 @@
+ +
+ + + +
diff --git a/src/app/pages/peers/peers.component.ts b/src/app/pages/peers/peers.component.ts index 72b34d2..36e526f 100644 --- a/src/app/pages/peers/peers.component.ts +++ b/src/app/pages/peers/peers.component.ts @@ -4,6 +4,7 @@ import { NavbarLink } from '../../shared/components/navbar/navbar.model'; import { NavbarService } from '../../shared/components/navbar/navbar.service'; import { Subscription } from 'rxjs'; import { BasePageComponent } from '../base-page/base-page.component'; +import { PeerInfo, PublicNode } from '../../../common'; @Component({ selector: 'app-peers', @@ -25,6 +26,10 @@ export class PeersComponent extends BasePageComponent implements AfterViewInit { public limitOutPeersResult: number = 0; public refreshingPeerList: boolean = false; + public refreshingPublicNodes: boolean = false; + + public getPeerListError: string = ''; + public getPublicNodesError: string = ''; public get daemonRunning(): boolean { return this.daemonData.running; @@ -34,6 +39,9 @@ export class PeersComponent extends BasePageComponent implements AfterViewInit { return this.daemonData.stopping; } + private peerList?: PeerInfo[]; + private publicNodes?: PublicNode[]; + constructor(private daemonService: DaemonService, private daemonData: DaemonDataService, navbarService: NavbarService, private ngZone: NgZone) { super(navbarService); this.setLinks([ @@ -48,16 +56,15 @@ export class PeersComponent extends BasePageComponent implements AfterViewInit { this.ngZone.run(() => { this.loadTables(); - const sub: Subscription = this.daemonData.syncEnd.subscribe(() => { - this.loadPublicNodesTable(); - }); + this.refreshPeerListTable().then().catch((error: any) => console.error(error)); + this.refreshPublicNodesTable().then().catch((error: any) => console.error(error)); const statusSub: Subscription = this.daemonService.onDaemonStatusChanged.subscribe((running: boolean) => { if (running) this.loadTables(); else this.destroyTables(); }); - this.subscriptions.push(sub, statusSub); + this.subscriptions.push(statusSub); }); } @@ -67,38 +74,47 @@ export class PeersComponent extends BasePageComponent implements AfterViewInit { } private loadPeerListTable(): void { - this.loadTable('peerListTable', this.daemonData.peerList); + const loading = this.peerList === undefined; + + this.loadTable('peerListTable', this.peerList ? this.peerList : [], loading); } private loadPublicNodesTable(): void { - this.loadTable('publicNodesTable', this.daemonData.publicNodes); + this.loadTable('publicNodesTable', this.publicNodes ? this.publicNodes : [], this.publicNodes === undefined); } public async refreshPeerListTable(): Promise { this.refreshingPeerList = true; try { - await new Promise((resolve, reject) => { - setTimeout(() => { - this.ngZone.run(() => { - try { - this.loadPeerListTable(); - resolve(); - } - catch(error: any) { - reject(new Error(`${error}`)); - } - }); - }, 1000); - }); + this.peerList = await this.daemonService.getPeerList(); } - catch(error) { + catch(error: any) { console.error(error); + this.getPeerListError = `${error}`; + this.peerList = undefined; } + this.loadPeerListTable(); this.refreshingPeerList = false; } + public async refreshPublicNodesTable(): Promise { + this.refreshingPublicNodes = true; + + try { + this.publicNodes = await this.daemonService.getPublicNodes(); + } + catch(error: any) { + console.error(error); + this.publicNodes = undefined; + this.getPublicNodesError = `${error}`; + } + + this.loadPublicNodesTable(); + this.refreshingPublicNodes = false; + } + public async inPeers(): Promise { this.limitingInPeers = true; diff --git a/src/app/shared/components/daemon-not-running/daemon-status.service.ts b/src/app/shared/components/daemon-not-running/daemon-status.service.ts index 078359b..4a77c4d 100644 --- a/src/app/shared/components/daemon-not-running/daemon-status.service.ts +++ b/src/app/shared/components/daemon-not-running/daemon-status.service.ts @@ -22,7 +22,7 @@ export class DaemonStatusService { public get daemonConfigured(): boolean { return this.settings ? this.settings.monerodPath != '' : true; - }; + } public get disablingSync(): boolean { return this.daemonService.disablingSync;