From bbcea66905fd52e39b139b4d40c727370e8c00ff Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Sun, 13 Oct 2024 20:47:25 +0200 Subject: [PATCH] General fixes --- app/main.ts | 7 +++- app/preload.js | 3 ++ .../services/daemon/daemon-data.service.ts | 34 +++++++++++++----- src/app/pages/bans/bans.component.ts | 9 ++++- .../pages/blockchain/blockchain.component.ts | 27 +++----------- src/app/pages/logs/logs.service.ts | 4 +-- .../transactions/transactions.component.html | 21 +++++++++++ .../transactions/transactions.component.ts | 36 ++++++++----------- .../daemon-not-running.component.ts | 4 ++- .../components/navbar/navbar.component.ts | 6 ++++ src/common/TxBacklogEntry.ts | 24 ++++++------- src/polyfills.ts | 2 ++ 12 files changed, 108 insertions(+), 69 deletions(-) diff --git a/app/main.ts b/app/main.ts index bfd7f16..776a6ae 100644 --- a/app/main.ts +++ b/app/main.ts @@ -69,7 +69,7 @@ function createWindow(): BrowserWindow { icon: wdwIcon }); - win.webContents.openDevTools(); + //win.webContents.openDevTools(); //win.setIcon() if (serve) { @@ -365,6 +365,11 @@ try { isQuitting = true; }); + ipcMain.handle('quit', (event) => { + isQuitting = true; + app.quit(); + }); + ipcMain.handle('start-monerod', (event, configFilePath: string[]) => { startMoneroDaemon(configFilePath); }) diff --git a/app/preload.js b/app/preload.js index 1906bd4..5bbe657 100644 --- a/app/preload.js +++ b/app/preload.js @@ -44,5 +44,8 @@ contextBridge.exposeInMainWorld('electronAPI', { }, gotOsType: (callback) => { ipcRenderer.on('got-os-type', callback); + }, + quit: () => { + ipcRenderer.invoke('quit'); } }); diff --git a/src/app/core/services/daemon/daemon-data.service.ts b/src/app/core/services/daemon/daemon-data.service.ts index 99647ec..d18570b 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 } from '@angular/core'; +import { EventEmitter, Injectable, NgZone } from '@angular/core'; import { DaemonService } from './daemon.service'; -import { BlockCount, BlockHeader, Chain, Connection, CoreIsBusyError, DaemonInfo, MinerData, MiningStatus, NetStats, NetStatsHistory, PeerInfo, PublicNode, SyncInfo, TxPool } from '../../../../common'; +import { BlockCount, BlockHeader, Chain, Connection, CoreIsBusyError, DaemonInfo, MinerData, MiningStatus, NetStats, NetStatsHistory, PeerInfo, PublicNode, SyncInfo, TxBacklogEntry, TxPool } from '../../../../common'; @Injectable({ providedIn: 'root' @@ -57,6 +57,9 @@ export class DaemonDataService { private _peerList: PeerInfo[] = []; private _gettingPeerList: boolean = false; + private _txPoolBacklog: TxBacklogEntry[] = []; + private _gettingTxPoolBackLog: boolean = false; + public readonly syncStart: EventEmitter = new EventEmitter(); public readonly syncEnd: EventEmitter = new EventEmitter(); public readonly syncError: EventEmitter = new EventEmitter(); @@ -67,15 +70,19 @@ export class DaemonDataService { public readonly netStatsRefreshStart: EventEmitter = new EventEmitter(); public readonly netStatsRefreshEnd: EventEmitter = new EventEmitter(); - constructor(private daemonService: DaemonService) { + constructor(private daemonService: DaemonService, private ngZone: NgZone) { this.daemonService.onDaemonStatusChanged.subscribe((running: boolean) => { - if (running) { - this.startLoop(); - } - else { - this.stopLoop(); - } + this.ngZone.run(() => { + if (running) { + this._daemonRunning = true; + this.startLoop(); + } + else { + this.stopLoop(); + } + }); + }); } @@ -215,6 +222,14 @@ export class DaemonDataService { return this._gettingPeerList; } + public get txPoolBacklog(): TxBacklogEntry[] { + return this._txPoolBacklog; + } + + public get gettingTxPoolBacklog(): boolean { + return this._gettingTxPoolBackLog; + } + public setRefreshTimeout(ms: number = 5000): void { this.refreshTimeoutMs = ms; } @@ -313,6 +328,7 @@ export class DaemonDataService { this._firstRefresh = false; if (!this._daemonRunning) { + this.stopLoop(); this.syncEnd.emit(); return; } diff --git a/src/app/pages/bans/bans.component.ts b/src/app/pages/bans/bans.component.ts index f88a7df..86bc721 100644 --- a/src/app/pages/bans/bans.component.ts +++ b/src/app/pages/bans/bans.component.ts @@ -89,7 +89,14 @@ export class BansComponent implements AfterViewInit { let _bans: Ban[] = []; try { - _bans = await this.daemonService.getBans(); + const running = await this.daemonService.isRunning(); + + if (running) { + _bans = await this.daemonService.getBans(); + } + else { + _bans = []; + } } catch (error) { console.error(error); diff --git a/src/app/pages/blockchain/blockchain.component.ts b/src/app/pages/blockchain/blockchain.component.ts index 43ba72c..bf2ce46 100644 --- a/src/app/pages/blockchain/blockchain.component.ts +++ b/src/app/pages/blockchain/blockchain.component.ts @@ -21,7 +21,10 @@ export class BlockchainComponent implements AfterViewInit { return this.daemonData.stopping; } - public lastBlockHeader?: BlockHeader; + public get lastBlockHeader(): BlockHeader | undefined { + return this.daemonData.lastBlockHeader; + } + public getLastBlockError: string = ''; public block?: Block; public getBlockByHash: boolean = false; @@ -64,28 +67,8 @@ export class BlockchainComponent implements AfterViewInit { ]; } - ngAfterViewInit(): void { + public ngAfterViewInit(): void { this.navbarService.setLinks(this.navbarLinks); - this.load().then().catch((error: any) => { - console.error(error); - }); - } - - public async load(): Promise { - await this.getLastBlockHeader(); - } - - private async getLastBlockHeader(): Promise { - this.gettingLastBlock = true; - try { - this.lastBlockHeader = await this.daemonService.getLastBlockHeader(true); - this.getLastBlockError = ''; - } - catch(error: any) { - console.error(error); - this.getLastBlockError = `${error}`; - } - this.gettingLastBlock = false; } public async getBlock(): Promise { diff --git a/src/app/pages/logs/logs.service.ts b/src/app/pages/logs/logs.service.ts index 9634bc7..b2ced30 100644 --- a/src/app/pages/logs/logs.service.ts +++ b/src/app/pages/logs/logs.service.ts @@ -25,8 +25,8 @@ export class LogsService { } public cleanLog(message: string): string { - //return message.replace(/\u001b\[[0-9;]*m/g, '').replace(/[\r\n]+/g, '\n').trim(); - return message.replace(/[\r\n]+/g, '\n').trim(); + return message.replace(/\u001b\[[0-9;]*m/g, '').replace(/[\r\n]+/g, '\n').trim(); + //return message.replace(/[\r\n]+/g, '\n').trim(); } public log(message: string): void { diff --git a/src/app/pages/transactions/transactions.component.html b/src/app/pages/transactions/transactions.component.html index e1e8630..35f9ab3 100644 --- a/src/app/pages/transactions/transactions.component.html +++ b/src/app/pages/transactions/transactions.component.html @@ -201,6 +201,27 @@ +
+

All transactions pool backlog

+
+ + + + + + + + + +
Blob SizeFeeTime In Pool
+
+
diff --git a/src/app/pages/transactions/transactions.component.ts b/src/app/pages/transactions/transactions.component.ts index bd83598..f31ada8 100644 --- a/src/app/pages/transactions/transactions.component.ts +++ b/src/app/pages/transactions/transactions.component.ts @@ -17,7 +17,11 @@ export class TransactionsComponent implements AfterViewInit, OnDestroy { public readonly navbarLinks: NavbarLink[]; public canRelay: boolean; - public txPoolBacklog: TxBacklogEntry[]; + + public get txPoolBacklog(): TxBacklogEntry[] { + return this.daemonData.txPoolBacklog; + } + public height: number; public count: number; @@ -80,14 +84,13 @@ export class TransactionsComponent implements AfterViewInit, OnDestroy { new NavbarLink('pills-relay-tx-tab', '#pills-relay-tx', 'pills-relay-tx', false, 'Relay Tx'), new NavbarLink('pills-send-raw-tx-tab', '#pills-send-raw-tx', 'pills-send-raw-tx', false, 'Send Raw Tx'), new NavbarLink('pills-get-fee-estimate-tab', '#pills-get-fee-estimate', 'pills-get-fee-estimate', false, 'Get Fee Estimate'), - new NavbarLink('pills-tx-backlog-tab', '#pills-tx-backlog', 'pills-tx-backlog', false, 'Tx Backlog'), + new NavbarLink('pills-tx-pool-backlog-tab', '#pills-tx-pool-backlog', 'pills-tx-pool-backlog', false, 'Tx Pool Backlog'), new NavbarLink('pills-coinbase-tx-sum-tab', '#pills-coinbase-tx-sum', 'pills-coinbase-tx-sum', false, 'Coinbase Tx Sum'), new NavbarLink('pills-flush-tx-pool-tab', '#pills-flush-tx-pool', 'pills-flush-tx-pool', false, 'Flush Tx Pool'), new NavbarLink('pills-flush-cahe-tab', '#pills-flush-cache', 'pills-flush-cache', false, 'Flush Cache') ]; this.height = 0; this.count = 0; - this.txPoolBacklog = []; this.canRelay = false; } @@ -95,18 +98,11 @@ export class TransactionsComponent implements AfterViewInit, OnDestroy { public ngAfterViewInit(): void { this.ngZone.run(() => { this.navbarService.setLinks(this.navbarLinks); - + this.initTables(); this.subscriptions.push(this.daemonData.syncEnd.subscribe(() => { this.refreshTables(); })); - - this.load().then(() => { - this.navbarService.enableLinks(); - }).catch((error) => { - console.error(error); - this.navbarService.disableLinks(); - }); }); } @@ -130,6 +126,7 @@ export class TransactionsComponent implements AfterViewInit, OnDestroy { private initTables(): void { this.initTable('spentKeyImagesTable'); this.initTable('transactionsTable'); + this.initTable('txPoolBacklogTable'); } private loadTransactionsTable(): void { @@ -144,19 +141,16 @@ export class TransactionsComponent implements AfterViewInit, OnDestroy { $table.bootstrapTable('load', this.spentKeyImages); } + private loadTxPoolBacklogTable(): void { + const $table = $('#txPoolBacklogTable'); + + $table.bootstrapTable('load', this.txPoolBacklog) + } + private refreshTables(): void { this.loadSpentKeyImagesTable(); this.loadTransactionsTable(); - } - - private async load(): Promise { - try { - this.txPoolBacklog = await this.daemonService.getTxPoolBacklog(); - console.log(this.txPoolBacklog) - } - catch (error) { - console.error(error); - } + this.loadTxPoolBacklogTable(); } public validTxIds(): boolean { diff --git a/src/app/shared/components/daemon-not-running/daemon-not-running.component.ts b/src/app/shared/components/daemon-not-running/daemon-not-running.component.ts index a74bdf3..8ea8ee0 100644 --- a/src/app/shared/components/daemon-not-running/daemon-not-running.component.ts +++ b/src/app/shared/components/daemon-not-running/daemon-not-running.component.ts @@ -47,7 +47,9 @@ export class DaemonNotRunningComponent { }).catch((error: any) => { console.error(error); this.daemonConfigured = false; - }) + }); + + this.daemonService.isRunning().then().catch((error: any) => console.error(error)); } public async startDaemon(): Promise { diff --git a/src/app/shared/components/navbar/navbar.component.ts b/src/app/shared/components/navbar/navbar.component.ts index df350a7..685b468 100644 --- a/src/app/shared/components/navbar/navbar.component.ts +++ b/src/app/shared/components/navbar/navbar.component.ts @@ -72,6 +72,12 @@ export class NavbarComponent { } public async quit(): Promise { + const running: boolean = await this.daemonService.isRunning(); + if (running) { + await this.stopDaemon(); + } + + window.electronAPI.quit(); } } diff --git a/src/common/TxBacklogEntry.ts b/src/common/TxBacklogEntry.ts index d6e967b..b577972 100644 --- a/src/common/TxBacklogEntry.ts +++ b/src/common/TxBacklogEntry.ts @@ -1,16 +1,16 @@ export class TxBacklogEntry { - public readonly blobSize: number; - public readonly fee: number; - public readonly timeInPool: number; + public readonly blobSize: number; + public readonly fee: number; + public readonly timeInPool: number; - constructor(blobSize: number, fee: number, timeInPool: number) { - this.blobSize = blobSize; - this.fee = fee; - this.timeInPool = timeInPool; - } + constructor(blobSize: number, fee: number, timeInPool: number) { + this.blobSize = blobSize; + this.fee = fee; + this.timeInPool = timeInPool; + } - public static fromBinary(binary: string): TxBacklogEntry[] { - console.debug(binary); - throw new Error("TxBacklogEntry.fromBinary(): not implemented"); - } + public static fromBinary(binary: string): TxBacklogEntry[] { + console.debug(binary); + throw new Error("TxBacklogEntry.fromBinary(): not implemented"); + } } \ No newline at end of file diff --git a/src/polyfills.ts b/src/polyfills.ts index a607f43..8708fe4 100644 --- a/src/polyfills.ts +++ b/src/polyfills.ts @@ -58,8 +58,10 @@ import 'bootstrap-table'; declare global { interface Window { electronAPI: { + startMonerod: (args: string[]) => void; getOsType: () => void; gotOsType: (callback: (event: any, osType: { platform: string, arch: string }) => void) => void; + quit: () => void; }; } } \ No newline at end of file