diff --git a/src/app/mod.rs b/src/app/mod.rs index 7fa118f..7e93bf7 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -528,15 +528,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 = match app.state.xvb.amount.parse() { - Ok(n) => n, - Err(e) => { - error!("App Init | Failed to parse manual amount: {}", e); - app.xvb_api.lock().unwrap().stats_priv.runtime_mode = RuntimeMode::Auto; - 0 - } - }; - + app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = app.state.xvb.amount; // 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/mod.rs b/src/app/panels/middle/mod.rs index 42f8c2a..4690429 100644 --- a/src/app/panels/middle/mod.rs +++ b/src/app/panels/middle/mod.rs @@ -162,7 +162,7 @@ path_xmr: {:#?}\n } Tab::Xvb => { debug!("App | Entering [XvB] Tab"); - crate::disk::state::Xvb::show(&mut self.state.xvb, self.size, &self.state.p2pool.address, ctx, ui, &self.xvb_api, lock!(self.xvb).state == ProcessState::Alive); + crate::disk::state::Xvb::show(&mut self.state.xvb, self.size, &self.state.p2pool.address, ctx, ui, &self.xvb_api, &self.xmrig_api, lock!(self.xvb).state == ProcessState::Alive); } } }); diff --git a/src/app/panels/middle/xvb.rs b/src/app/panels/middle/xvb.rs index 51222a9..18c26f8 100644 --- a/src/app/panels/middle/xvb.rs +++ b/src/app/panels/middle/xvb.rs @@ -8,6 +8,7 @@ use readable::num::Float; use readable::up::Uptime; use crate::disk::state::XvbMode; +use crate::helper::xmrig::PubXmrigApi; use crate::helper::xvb::priv_stats::RuntimeMode; use crate::helper::xvb::PubXvbApi; use crate::regex::num_lines; @@ -33,6 +34,7 @@ impl crate::disk::state::Xvb { _ctx: &egui::Context, ui: &mut egui::Ui, api: &Arc>, + gui_api_xmrig: &Arc>, private_stats: bool, ) { let website_height = size.y / 10.0; @@ -149,26 +151,21 @@ impl crate::disk::state::Xvb { ui.selectable_value(&mut self.mode, XvbMode::ManuallyKeep, "Manually Keep"); }); if self.mode == XvbMode::ManuallyDonate || self.mode == XvbMode::ManuallyKeep { - let (text, color) = if self.amount.is_empty() { - ( - format!(""), - LIGHT_GRAY, - ) - } else if self.amount.parse::().is_ok() { - (format!("✔"), GREEN) - } else { - ( - format!("Invalid hashrate ❌"), - RED, - ) - }; ui.add_space(space_h); - ui.colored_label(color, text); + 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 { + lock!(gui_api_xmrig).hashrate_raw + } + }; + ui.add( - TextEdit::singleline(&mut self.amount) - .vertical_align(egui::Align::Center) + egui::Slider::new(&mut self.amount, 0.0..=(hashrate_xmrig as f64)).text("H/s") ).on_hover_text(XVB_MANUAL_HASHRATE_HELP); } @@ -178,15 +175,7 @@ impl crate::disk::state::Xvb { // Set runtime_mode & runtime_manual_amount lock!(api).stats_priv.runtime_mode = self.mode.clone().into(); - lock!(api).stats_priv.runtime_manual_amount = match self.amount.parse() { - Ok(n) => n, - Err(e) => { - error!("Error parsing int {}", e); - lock!(api).stats_priv.runtime_mode = RuntimeMode::Auto; - 0 - } - }; - + lock!(api).stats_priv.runtime_manual_amount = self.amount; } diff --git a/src/disk/state.rs b/src/disk/state.rs index 70d484a..91029c4 100644 --- a/src/disk/state.rs +++ b/src/disk/state.rs @@ -251,13 +251,13 @@ pub enum XvbMode { Hero, } -#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default)] +#[derive(Clone, PartialEq, Debug, Deserialize, Serialize, Default)] pub struct Xvb { pub simple: bool, pub token: String, pub simple_hero_mode: bool, pub mode: XvbMode, - pub amount: String + pub amount: f64 } #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/src/helper/xvb/algorithm.rs b/src/helper/xvb/algorithm.rs index 40fc6b6..b3cc308 100644 --- a/src/helper/xvb/algorithm.rs +++ b/src/helper/xvb/algorithm.rs @@ -83,32 +83,16 @@ pub(crate) fn calcul_donated_time( default_spared_time }, RuntimeMode::ManuallyDonate => { - let mut donate_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; + let donate_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; info!("RuntimeMode::ManuallyDonate - lhr:{lhr} donate_hr:{donate_hr}"); - if donate_hr > (lhr as u64) { - donate_hr = lhr as u64; - } - - if lhr < 1.0 { - default_spared_time - } else { - XVB_TIME_ALGO * (donate_hr as u32) / (lhr as u32) - } + XVB_TIME_ALGO * (donate_hr as u32) / (lhr as u32) }, RuntimeMode::ManuallyKeep => { - let mut keep_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; + let keep_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; info!("RuntimeMode::ManuallyDonate - lhr:{lhr} keep_hr:{keep_hr}"); - if keep_hr > (lhr as u64) { - keep_hr = lhr as u64; - } - - if lhr < 1.0 { - default_spared_time - } else { - XVB_TIME_ALGO - (XVB_TIME_ALGO * (keep_hr as u32) / (lhr as u32)) - } + XVB_TIME_ALGO - (XVB_TIME_ALGO * (keep_hr as u32) / (lhr as u32)) } }; @@ -299,6 +283,7 @@ pub(crate) async fn algorithm( gui_api_xvb, "At least one share is in current PPLNS window.", ); + let hashrate_xmrig = { if lock!(gui_api_xmrig).hashrate_raw_15m > 0.0 { lock!(gui_api_xmrig).hashrate_raw_15m @@ -308,6 +293,7 @@ pub(crate) async fn algorithm( lock!(gui_api_xmrig).hashrate_raw } }; + *lock!(time_donated) = calcul_donated_time(hashrate_xmrig, gui_api_p2pool, gui_api_xvb, state_p2pool); let time_donated = *lock!(time_donated); diff --git a/src/helper/xvb/priv_stats.rs b/src/helper/xvb/priv_stats.rs index 8950de5..0f6277a 100644 --- a/src/helper/xvb/priv_stats.rs +++ b/src/helper/xvb/priv_stats.rs @@ -48,7 +48,7 @@ pub struct XvbPrivStats { // so the hero mode can change between two decision of algorithm without restarting XvB. pub runtime_mode: RuntimeMode, #[serde(skip)] - pub runtime_manual_amount: u64 + pub runtime_manual_amount: f64 } impl XvbPrivStats {