diff --git a/src/app/core/services/daemon/daemon.service.ts b/src/app/core/services/daemon/daemon.service.ts index 90aab60..575db26 100644 --- a/src/app/core/services/daemon/daemon.service.ts +++ b/src/app/core/services/daemon/daemon.service.ts @@ -42,6 +42,7 @@ import { ElectronService } from '../electron/electron.service'; providedIn: 'root' }) export class DaemonService { + private daemonRunning?: boolean; private readonly configFilePath: string = './config'; private url: string = "http://127.0.0.1:28081"; //private url: string = "http://node2.monerodevs.org:28089"; @@ -81,17 +82,23 @@ export class DaemonService { }, 500) } - public async isRunning(): Promise { + public async isRunning(force: boolean = false): Promise { try { + if (!force && this.daemonRunning != undefined) { + return this.daemonRunning; + } + const response = await this.callJsonRpc(new EmptyRpcRequest()); console.log(response); - return true; + this.daemonRunning = true; } catch(error) { console.error(error); - return false; + this.daemonRunning = false; } + return this.daemonRunning; + } public async getBlockCount(): Promise { diff --git a/src/app/detail/detail.component.ts b/src/app/detail/detail.component.ts index 66881ac..2ce99e2 100644 --- a/src/app/detail/detail.component.ts +++ b/src/app/detail/detail.component.ts @@ -64,8 +64,8 @@ export class DetailComponent implements OnInit, AfterViewInit { this.isLoading = true; this.navbarLinks = [ - new NavbarLink('pills-home-tab', '#pills-home', 'pills-home', true, 'Overview'), - new NavbarLink('pills-profile-tab', '#pills-profile', 'pills-profile', false, 'Peers') + new NavbarLink('pills-home-tab', '#pills-home', 'pills-home', true, 'Overview', true), + new NavbarLink('pills-profile-tab', '#pills-profile', 'pills-profile', false, 'Peers', true) ]; this.cards = []; @@ -142,9 +142,13 @@ export class DetailComponent implements OnInit, AfterViewInit { this.daemonRunning = await this.daemonService.isRunning(); if (!this.daemonRunning) { + this.navbarService.disableNavbarLinks(); + this.isLoading = false; return; } + this.navbarService.enableNavbarLinks(); + const $table = $('#table'); this.syncInfo = await this.daemonService.syncInfo(); diff --git a/src/app/mining/mining.component.ts b/src/app/mining/mining.component.ts index f6a040c..8ae4ec5 100644 --- a/src/app/mining/mining.component.ts +++ b/src/app/mining/mining.component.ts @@ -81,6 +81,13 @@ export class MiningComponent implements AfterViewInit { private async load(): Promise { try { + const running = await this.daemonService.isRunning(); + + if (!running) { + this.coreBusy = false; + throw new Error("Daemon not running"); + } + this.minerData = await this.daemonService.getMinerData(); this.majorVersion = this.minerData.majorVersion; this.height = this.minerData.height; @@ -94,8 +101,11 @@ export class MiningComponent implements AfterViewInit { const $table = $('#chainsTable'); $table.bootstrapTable('load', this.getChains()); + this.coreBusy = false; + this.navbarService.enableNavbarLinks(); } catch(error) { + this.navbarService.disableNavbarLinks(); if (error instanceof CoreIsBusyError) { this.coreBusy = true; } @@ -106,7 +116,6 @@ export class MiningComponent implements AfterViewInit { private createCards(): Card[] { if (this.coreBusy) { return [ - new Card('Error', 'Core is busy') ] } return [ diff --git a/src/app/navbar/navbar.component.html b/src/app/navbar/navbar.component.html index c3f3eb8..ea26a18 100644 --- a/src/app/navbar/navbar.component.html +++ b/src/app/navbar/navbar.component.html @@ -7,7 +7,7 @@