From 9c6043ea2ec65719b47788ce497a13f2cc41642e Mon Sep 17 00:00:00 2001
From: hinto-janaiyo <hinto.janaiyo@protonmail.com>
Date: Sun, 18 Dec 2022 20:17:32 -0500
Subject: [PATCH] helper: reset [Pub*Api] if restarting process

---
 Cargo.lock    | 24 ++++++++++++------------
 src/gupax.rs  | 24 ++++++++++--------------
 src/helper.rs | 12 ++++++++++--
 src/status.rs |  8 ++++----
 4 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 818714a..5650957 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -134,9 +134,9 @@ dependencies = [
 
 [[package]]
 name = "anyhow"
-version = "1.0.67"
+version = "1.0.68"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7724808837b77f4b4de9d283820f9d98bcf496d5692934b857a2399d31ff22e6"
+checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
 
 [[package]]
 name = "arboard"
@@ -3009,9 +3009,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
 
 [[package]]
 name = "proc-macro2"
-version = "1.0.48"
+version = "1.0.49"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e9d89e5dba24725ae5678020bf8f1357a9aa7ff10736b551adbcd3f8d17d766f"
+checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
 dependencies = [
  "unicode-ident",
 ]
@@ -3024,9 +3024,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
 
 [[package]]
 name = "quote"
-version = "1.0.22"
+version = "1.0.23"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "556d0f47a940e895261e77dc200d5eadfc6ef644c179c6f5edfc105e3a2292c8"
+checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
 dependencies = [
  "proc-macro2",
 ]
@@ -3405,9 +3405,9 @@ dependencies = [
 
 [[package]]
 name = "semver"
-version = "1.0.15"
+version = "1.0.16"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3bfa246f936730408c0abee392cc1a50b118ece708c7f630516defd64480c7d8"
+checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a"
 
 [[package]]
 name = "serde"
@@ -3440,9 +3440,9 @@ dependencies = [
 
 [[package]]
 name = "serde_json"
-version = "1.0.90"
+version = "1.0.91"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8778cc0b528968fe72abec38b5db5a20a70d148116cd9325d2bc5f5180ca3faf"
+checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
 dependencies = [
  "itoa",
  "ryu",
@@ -3800,9 +3800,9 @@ dependencies = [
 
 [[package]]
 name = "syn"
-version = "1.0.106"
+version = "1.0.107"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "09ee3a69cd2c7e06684677e5629b3878b253af05e4714964204279c6bc02cf0b"
+checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
 dependencies = [
  "proc-macro2",
  "quote",
diff --git a/src/gupax.rs b/src/gupax.rs
index 68202eb..6a4128e 100644
--- a/src/gupax.rs
+++ b/src/gupax.rs
@@ -152,14 +152,12 @@ impl Gupax {
 		ui.horizontal(|ui| {
 			if self.p2pool_path.is_empty() {
 				ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ➖").color(LIGHT_GRAY))).on_hover_text(P2POOL_PATH_EMPTY);
+			} else if !Self::path_is_file(&self.p2pool_path) {
+				ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ❌").color(RED))).on_hover_text(P2POOL_PATH_NOT_FILE);
+			} else if !crate::update::check_p2pool_path(&self.p2pool_path) {
+				ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ❌").color(RED))).on_hover_text(P2POOL_PATH_NOT_VALID);
 			} else {
-				if !Self::path_is_file(&self.p2pool_path) {
-					ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ❌").color(RED))).on_hover_text(P2POOL_PATH_NOT_FILE);
-				} else if !crate::update::check_p2pool_path(&self.p2pool_path) {
-					ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ❌").color(RED))).on_hover_text(P2POOL_PATH_NOT_VALID);
-				} else {
-					ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ✔").color(GREEN))).on_hover_text(P2POOL_PATH_OK);
-				}
+				ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ✔").color(GREEN))).on_hover_text(P2POOL_PATH_OK);
 			}
 			ui.spacing_mut().text_edit_width = ui.available_width() - SPACE;
 			ui.set_enabled(!file_window.lock().unwrap().thread);
@@ -171,14 +169,12 @@ impl Gupax {
 		ui.horizontal(|ui| {
 			if self.xmrig_path.is_empty() {
 				ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ➖").color(LIGHT_GRAY))).on_hover_text(XMRIG_PATH_EMPTY);
+			} else if !Self::path_is_file(&self.xmrig_path) {
+				ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ❌").color(RED))).on_hover_text(XMRIG_PATH_NOT_FILE);
+			} else if !crate::update::check_xmrig_path(&self.xmrig_path) {
+				ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ❌").color(RED))).on_hover_text(XMRIG_PATH_NOT_VALID);
 			} else {
-				if !Self::path_is_file(&self.xmrig_path) {
-					ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ❌").color(RED))).on_hover_text(XMRIG_PATH_NOT_FILE);
-				} else if !crate::update::check_xmrig_path(&self.xmrig_path) {
-					ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ❌").color(RED))).on_hover_text(XMRIG_PATH_NOT_VALID);
-				} else {
-					ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ✔").color(GREEN))).on_hover_text(XMRIG_PATH_OK);
-				}
+				ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ✔").color(GREEN))).on_hover_text(XMRIG_PATH_OK);
 			}
 			ui.spacing_mut().text_edit_width = ui.available_width() - SPACE;
 			ui.set_enabled(!file_window.lock().unwrap().thread);
diff --git a/src/helper.rs b/src/helper.rs
index 9485247..42c1906 100644
--- a/src/helper.rs
+++ b/src/helper.rs
@@ -475,6 +475,10 @@ impl Helper {
 		let regex = P2poolRegex::new();
 		let start = process.lock().unwrap().start;
 
+		// Reset stats before loop
+		*pub_api.lock().unwrap() = PubP2poolApi::new();
+		*gui_api.lock().unwrap() = PubP2poolApi::new();
+
 		// 4. Loop as watchdog
 		info!("P2Pool | Entering watchdog mode... woof!");
 		loop {
@@ -842,6 +846,10 @@ impl Helper {
 		let client: hyper::Client<hyper::client::HttpConnector> = hyper::Client::builder().build(hyper::client::HttpConnector::new());
 		let start = process.lock().unwrap().start;
 
+		// Reset stats before loop
+		*pub_api.lock().unwrap() = PubXmrigApi::new();
+		*gui_api.lock().unwrap() = PubXmrigApi::new();
+
 		// 5. Loop as watchdog
 		info!("XMRig | Entering watchdog mode... woof!");
 		loop {
@@ -1454,12 +1462,12 @@ impl PubP2poolApi {
 		let xmr_day = xmr_hour * 24.0;
 		let xmr_month = xmr_day * 30.0;
 
-		if payouts != 0 {
+		if payouts_new != 0 {
 			debug!("P2Pool Watchdog | New [Payout] found in output ... {}", payouts_new);
 			debug!("P2Pool Watchdog | Total [Payout] should be ... {}", payouts);
 			debug!("P2Pool Watchdog | Correct [Payout per] should be ... [{}/hour, {}/day, {}/month]", payouts_hour, payouts_day, payouts_month);
 		}
-		if xmr != 0.0 {
+		if xmr_new != 0.0 {
 			debug!("P2Pool Watchdog | New [XMR mined] found in output ... {}", xmr_new);
 			debug!("P2Pool Watchdog | Total [XMR mined] should be ... {}", xmr);
 			debug!("P2Pool Watchdog | Correct [XMR mined per] should be ... [{}/hour, {}/day, {}/month]", xmr_hour, xmr_day, xmr_month);
diff --git a/src/status.rs b/src/status.rs
index 261282b..9c39e3b 100644
--- a/src/status.rs
+++ b/src/status.rs
@@ -72,10 +72,10 @@ pub fn show(sys: &Arc<Mutex<Sys>>, p2pool_api: &Arc<Mutex<PubP2poolApi>>, xmrig_
 		ui.add_sized([width, height], Label::new(format!("{}", api.shares_found)));
 		ui.add_sized([width, height], Label::new(RichText::new("Payouts").underline().color(BONE))).on_hover_text(STATUS_P2POOL_PAYOUTS);
 		ui.add_sized([width, height], Label::new(format!("Total: {}", api.payouts)));
-		ui.add_sized([width, height], Label::new(format!("[{:.3}/hour] [{:.3}/day] [{:.3}/month]", api.payouts_hour, api.payouts_day, api.payouts_month)));
+		ui.add_sized([width, height], Label::new(format!("[{:.3}/hour]\n[{:.3}/day]\n[{:.3}/month]", api.payouts_hour, api.payouts_day, api.payouts_month)));
 		ui.add_sized([width, height], Label::new(RichText::new("XMR Mined").underline().color(BONE))).on_hover_text(STATUS_P2POOL_XMR);
-		ui.add_sized([width, height], Label::new(format!("Total: {} XMR", api.xmr)));
-		ui.add_sized([width, height], Label::new(format!("[{:.3}/hour] [{:.3}/day] [{:.3}/month]", api.xmr_hour, api.xmr_day, api.xmr_month)));
+		ui.add_sized([width, height], Label::new(format!("Total: {:.13} XMR", api.xmr)));
+		ui.add_sized([width, height], Label::new(format!("[{:.3}/hour]\n[{:.3}/day]\n[{:.3}/month]", api.xmr_hour, api.xmr_day, api.xmr_month)));
 		ui.add_sized([width, height], Label::new(RichText::new("Hashrate [15m/1h/24h]").underline().color(BONE))).on_hover_text(STATUS_P2POOL_HASHRATE);
 		ui.add_sized([width, height], Label::new(format!("[{} H/s] [{} H/s] [{} H/s]", api.hashrate_15m, api.hashrate_1h, api.hashrate_24h)));
 		ui.add_sized([width, height], Label::new(RichText::new("Miners Connected").underline().color(BONE))).on_hover_text(STATUS_P2POOL_CONNECTIONS);
@@ -100,7 +100,7 @@ pub fn show(sys: &Arc<Mutex<Sys>>, p2pool_api: &Arc<Mutex<PubP2poolApi>>, xmrig_
 		ui.add_sized([width, height], Label::new(RichText::new("Difficulty").underline().color(BONE))).on_hover_text(STATUS_XMRIG_DIFFICULTY);
 		ui.add_sized([width, height], Label::new(format!("{}", api.diff)));
 		ui.add_sized([width, height], Label::new(RichText::new("Shares").underline().color(BONE))).on_hover_text(STATUS_XMRIG_SHARES);
-		ui.add_sized([width, height], Label::new(format!("[Accepted: {}] [Rejected: {}]", api.accepted, api.rejected)));
+		ui.add_sized([width, height], Label::new(format!("[Accepted: {}]\n[Rejected: {}]", api.accepted, api.rejected)));
 		ui.add_sized([width, height], Label::new(RichText::new("Pool").underline().color(BONE))).on_hover_text(STATUS_XMRIG_POOL);
 		ui.add_sized([width, height], Label::new(api.pool.to_string()));
 		drop(api);