diff --git a/src/app/core/services/daemon/daemon-data.service.ts b/src/app/core/services/daemon/daemon-data.service.ts index 3435d8e..675b35e 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 { DaemonService } from './daemon.service'; -import { BlockCount, BlockHeader, Chain, DaemonInfo, NetStats, SyncInfo } from '../../../../common'; +import { BlockCount, BlockHeader, Chain, DaemonInfo, MinerData, MiningStatus, NetStats, SyncInfo } from '../../../../common'; @Injectable({ providedIn: 'root' @@ -37,6 +37,12 @@ export class DaemonDataService { private _netStats?: NetStats; private _gettingNetStats: boolean = false; + private _miningStatus?: MiningStatus; + private _gettingMiningStatus: boolean = false; + + private _minerData?: MinerData; + private _gettingMinerData: boolean = false; + public readonly syncStart: EventEmitter = new EventEmitter(); public readonly syncEnd: EventEmitter = new EventEmitter(); public readonly syncError: EventEmitter = new EventEmitter(); @@ -137,6 +143,18 @@ export class DaemonDataService { return this._gettingNetStats; } + public get miningStatus(): MiningStatus | undefined { + return this._miningStatus; + } + + public get gettingMiningStatus(): boolean { + return this._gettingMiningStatus; + } + + public get gettingMinerData(): boolean { + return this._gettingMinerData; + } + public setRefreshTimeout(ms: number = 5000): void { this.refreshTimeoutMs = ms; } @@ -170,6 +188,46 @@ export class DaemonDataService { } + private async refreshMiningStatus(): Promise { + this._gettingMiningStatus = true; + + try { + this._miningStatus = await this.daemonService.miningStatus(); + } + catch(error) { + console.error(error); + } + + this._gettingMiningStatus = false; + } + + private async refreshMinerData(): Promise { + this._gettingMinerData = true; + + try { + this._minerData = await this.daemonService.getMinerData(); + } + catch (error) { + console.error(error); + } + + this._gettingMinerData = false; + } + + private async refreshAltChains(): Promise { + this._gettingAltChains = true; + + try { + this._altChains = await this.daemonService.getAlternateChains(); + } + catch (error) { + console.error(error); + } + + this._gettingAltChains = false; + + } + private async refresh(): Promise { if (this.refreshing || this.tooEarlyForRefresh) { return; @@ -210,14 +268,16 @@ export class DaemonDataService { if (firstRefresh) this._isBlockchainPruned = (await this.daemonService.pruneBlockchain(true)).pruned; this._gettingIsBlockchainPruned = false; - this._gettingAltChains = true; - this._altChains = await this.daemonService.getAlternateChains(); - this._gettingAltChains = false; + await this.refreshAltChains(); this._gettingNetStats = true; this._netStats = await this.daemonService.getNetStats(); this._gettingNetStats = false; + await this.refreshMiningStatus(); + + await this.refreshMinerData(); + this._lastRefresh = Date.now(); } catch(error) { console.error(error); diff --git a/src/app/pages/mining/mining.component.html b/src/app/pages/mining/mining.component.html index a5d8130..05e1069 100644 --- a/src/app/pages/mining/mining.component.html +++ b/src/app/pages/mining/mining.component.html @@ -11,7 +11,7 @@ -
+
@@ -31,7 +31,7 @@
-
+

Mining Status

@@ -78,6 +78,48 @@
+
+
+
+ +
+ + + Account address to mine to +
+ +
+ + +
+ States if the mining should run in background (true) or foreground (false) +
+ +
+ + +
+ States if battery state (on laptop) should be ignored (true) or not (false) +
+ +
+ + + Number of mining thread to run +
+ +
+
+
+ +
+ + + + + + +
diff --git a/src/app/pages/mining/mining.component.ts b/src/app/pages/mining/mining.component.ts index 7f85aae..6611719 100644 --- a/src/app/pages/mining/mining.component.ts +++ b/src/app/pages/mining/mining.component.ts @@ -64,6 +64,25 @@ export class MiningComponent implements AfterViewInit { //private txBacklog: MineableTxBacklog[] public cards: Card[]; public daemonRunning: boolean; + public get daemonStopping(): boolean { + return this.daemonService.stopping; + } + + public startMiningDoBackgroundMining: boolean = false; + public startMiningIgnoreBattery: boolean = false; + public startMiningMinerAddress: string = ''; + public startMiningThreadsCount: number = 0; + public startingMining: boolean = false; + public startMiningSuccess: boolean = false; + public startMiningError: string = ''; + + public stoppingMining: boolean = false; + public stopMiningError: string = ''; + public stopMiningSuccess: boolean = false; + + public get validStartMiningMinerAddress(): boolean { + return this.startMiningMinerAddress != ''; + } constructor(private router: Router, private daemonService: DaemonService, private navbarService: NavbarService, private ngZone: NgZone) { @@ -109,7 +128,7 @@ export class MiningComponent implements AfterViewInit { }); } - ngAfterViewInit(): void { + public ngAfterViewInit(): void { console.log('DetailComponent AFTER VIEW INIT'); this.navbarService.setLinks(this.navbarLinks); @@ -289,6 +308,39 @@ export class MiningComponent implements AfterViewInit { this.generatingBlocks = false; } + public async startMining(): Promise { + this.startingMining = true; + try { + await this.daemonService.startMining(this.startMiningDoBackgroundMining, this.startMiningIgnoreBattery, this.startMiningMinerAddress, this.startMiningThreadsCount) + this.startMiningError = ''; + this.startMiningSuccess = true; + } + catch(error) { + this.startMiningSuccess = false; + this.startMiningError = `${error}`; + } + + this.startingMining = false; + } + + public async stopMining(): Promise { + this.stoppingMining = true; + + try { + await this.daemonService.stopMining(); + + this.stopMiningSuccess = true; + this.stopMiningError = ''; + } + catch(error) { + console.error(error); + this.stopMiningSuccess = false; + this.stopMiningError = `${error};` + } + + this.stoppingMining = false; + } + } class Card {