From caf3c62227587d128343f3c2e405b587b0f8aed4 Mon Sep 17 00:00:00 2001 From: mostafaei2002 Date: Tue, 11 Jun 2024 21:23:02 +0330 Subject: [PATCH] feat: add megahash option to slider --- src/app/mod.rs | 2 +- src/app/panels/middle/xvb.rs | 46 ++++++++++++++++++++---------------- src/disk/state.rs | 6 +++-- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 39b5914..e241338 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -527,7 +527,7 @@ impl App { // Set saved Hero mode to runtime. debug!("Setting runtime_mode & runtime_manual_amount"); app.xvb_api.lock().unwrap().stats_priv.runtime_mode = app.state.xvb.mode.clone().into(); - app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = app.state.xvb.amount; + app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = app.state.xvb.manual_amount_raw; // Check if [P2pool.node] exists info!("App Init | Checking if saved remote node still exists..."); app.state.p2pool.node = RemoteNode::check_exists(&app.state.p2pool.node); diff --git a/src/app/panels/middle/xvb.rs b/src/app/panels/middle/xvb.rs index 9fec213..ea16216 100644 --- a/src/app/panels/middle/xvb.rs +++ b/src/app/panels/middle/xvb.rs @@ -168,12 +168,12 @@ impl crate::disk::state::Xvb { ui.add_space(space_h); let mut is_slider_enabled = true; - let mut hashrate_xmrig = { + let hashrate_xmrig = { if lock!(gui_api_xmrig).hashrate_raw_15m > 0.0 { lock!(gui_api_xmrig).hashrate_raw_15m } else if lock!(gui_api_xmrig).hashrate_raw_1m > 0.0 { lock!(gui_api_xmrig).hashrate_raw_1m - } else if lock!(gui_api_xmrig).hashrate_raw { + } else if lock!(gui_api_xmrig).hashrate_raw > 0.0 { lock!(gui_api_xmrig).hashrate_raw } else { is_slider_enabled = false; @@ -181,10 +181,7 @@ impl crate::disk::state::Xvb { } }; - if self.manual_donation_metric == ManualDonationMetric::Kilo { - hashrate_xmrig /= 1000.0; - } - + let slider_help_text = if self.mode == XvbMode::ManualXvb { XVB_MANUAL_SLIDER_MANUAL_XVB_HELP } else { @@ -196,21 +193,22 @@ impl crate::disk::state::Xvb { ui.spacing_mut().slider_width = width * 0.5; ui.add_sized( [width, text_edit], - egui::Slider::new(&mut self.amount, 0.0..=(hashrate_xmrig as f64)) + egui::Slider::new(&mut self.manual_slider_amount, 0.0..=(hashrate_xmrig as f64)) ).on_hover_text(slider_help_text); - if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Hash, "H/s")).clicked() && - self.manual_donation_metric != ManualDonationMetric::Hash - { - self.amount *= 1000.0; + if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Hash, "H/s")).clicked() { self.manual_donation_metric = ManualDonationMetric::Hash; + self.manual_slider_amount = self.manual_amount_raw; } - if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Kilo, "kH/s")).clicked() && - self.manual_donation_metric != ManualDonationMetric::Kilo - { - self.amount /= 1000.0; + if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Kilo, "kH/s")).clicked() { self.manual_donation_metric = ManualDonationMetric::Kilo; + self.manual_slider_amount = self.manual_amount_raw / 1000.0; }; + if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Mega, "MH/s")).clicked() { + self.manual_donation_metric = ManualDonationMetric::Mega; + self.manual_slider_amount = self.manual_amount_raw / 1_000_000.0; + }; + }); }); @@ -233,14 +231,22 @@ impl crate::disk::state::Xvb { }); }); }); + + match self.manual_donation_metric { + ManualDonationMetric::Hash => { + self.manual_amount_raw = self.manual_slider_amount; + }, + ManualDonationMetric::Kilo => { + self.manual_amount_raw = self.manual_slider_amount * 1000.0; + }, + ManualDonationMetric::Mega => { + self.manual_amount_raw = self.manual_slider_amount * 1_000_000.0; + } + } // Set runtime_mode & runtime_manual_amount lock!(api).stats_priv.runtime_mode = self.mode.clone().into(); - if self.manual_donation_metric == ManualDonationMetric::Hash { - lock!(api).stats_priv.runtime_manual_amount = self.amount; - } else { - lock!(api).stats_priv.runtime_manual_amount = self.amount * 1000.0; - } + lock!(api).stats_priv.runtime_manual_amount = self.manual_amount_raw; } ui.add_space(space_h); diff --git a/src/disk/state.rs b/src/disk/state.rs index 9d9ef28..29f411d 100644 --- a/src/disk/state.rs +++ b/src/disk/state.rs @@ -249,7 +249,8 @@ pub struct Xvb { pub token: String, pub simple_hero_mode: bool, pub mode: XvbMode, - pub amount: f64, + pub manual_amount_raw: f64, + pub manual_slider_amount: f64, pub manual_donation_level: ManualDonationLevel, pub manual_donation_metric: ManualDonationMetric, } @@ -258,9 +259,9 @@ pub struct Xvb { pub enum XvbMode { #[default] Auto, + Hero, ManualXvb, ManualP2pool, - Hero, ManualDonationLevel, } @@ -278,6 +279,7 @@ pub enum ManualDonationMetric { #[default] Hash, Kilo, + Mega } #[derive(Clone, Debug, Deserialize, Serialize)]