feat: add UI for manual donation level feature

This commit is contained in:
mostafaei2002 2024-06-09 20:28:57 +03:30
parent 12c8d9622d
commit a232058772
4 changed files with 74 additions and 9 deletions

View file

@ -6,7 +6,7 @@ use log::debug;
use readable::num::Float;
use readable::up::Uptime;
use crate::disk::state::XvbMode;
use crate::disk::state::{XvbMode, ManualDonationLevel};
use crate::helper::xmrig::PubXmrigApi;
use crate::helper::xvb::priv_stats::RuntimeMode;
use crate::helper::xvb::PubXvbApi;
@ -134,7 +134,11 @@ impl crate::disk::state::Xvb {
}
}
});
ui.add_space(space_h);
// --------------------------- XVB Advanced -----------------------------------------
if !self.simple {
@ -149,6 +153,7 @@ impl crate::disk::state::Xvb {
ui.selectable_value(&mut self.mode, XvbMode::Hero, "Hero Mode");
ui.selectable_value(&mut self.mode, XvbMode::ManuallyDonate, "Manually Donate");
ui.selectable_value(&mut self.mode, XvbMode::ManuallyKeep, "Manually Keep");
ui.selectable_value(&mut self.mode, XvbMode::ManualDonationLevel, "Manual Donation Level");
});
if self.mode == XvbMode::ManuallyDonate || self.mode == XvbMode::ManuallyKeep {
@ -167,6 +172,17 @@ impl crate::disk::state::Xvb {
ui.add(
egui::Slider::new(&mut self.amount, 0.0..=(hashrate_xmrig as f64)).text("H/s")
).on_hover_text(XVB_MANUAL_HASHRATE_HELP);
}
if self.mode == XvbMode::ManualDonationLevel {
ui.radio_value(&mut self.manual_donation_level, ManualDonationLevel::VIP, "VIP");
ui.radio_value(&mut self.manual_donation_level, ManualDonationLevel::Donor, "Donor");
ui.radio_value(&mut self.manual_donation_level, ManualDonationLevel::DonorVIP, "DonorVIP");
ui.radio_value(&mut self.manual_donation_level, ManualDonationLevel::DonorWhale, "DonorWhale");
ui.radio_value(&mut self.manual_donation_level, ManualDonationLevel::DonorMega, "DonorMega");
lock!(api).stats_priv.runtime_manual_donation_level = self.manual_donation_level.clone().into();
}
});
@ -177,8 +193,6 @@ impl crate::disk::state::Xvb {
lock!(api).stats_priv.runtime_mode = self.mode.clone().into();
lock!(api).stats_priv.runtime_manual_amount = self.amount;
}
});
// need to warn the user if no address is set in p2pool tab
if !Regexes::addr_ok(address) {

View file

@ -249,6 +249,17 @@ pub enum XvbMode {
ManuallyDonate,
ManuallyKeep,
Hero,
ManualDonationLevel
}
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub enum ManualDonationLevel {
VIP,
Donor,
DonorVIP,
DonorWhale,
DonorMega
}
#[derive(Clone, PartialEq, Debug, Deserialize, Serialize, Default)]
@ -257,7 +268,8 @@ pub struct Xvb {
pub token: String,
pub simple_hero_mode: bool,
pub mode: XvbMode,
pub amount: f64
pub amount: f64,
pub manual_donation_level: ManualDonationLevel
}
#[derive(Clone, Debug, Deserialize, Serialize)]
@ -391,4 +403,10 @@ impl Default for XvbMode {
fn default() -> Self {
Self::Auto
}
}
impl Default for ManualDonationLevel {
fn default() -> Self {
Self::VIP
}
}

View file

@ -93,6 +93,9 @@ pub(crate) fn calcul_donated_time(
info!("RuntimeMode::ManuallyDonate - lhr:{lhr} keep_hr:{keep_hr}");
XVB_TIME_ALGO - (XVB_TIME_ALGO * (keep_hr as u32) / (lhr as u32))
},
RuntimeMode::ManualDonationLevel => {
todo!()
}
};

View file

@ -10,9 +10,7 @@ use serde::Deserialize;
use tokio::time::sleep;
use crate::{
helper::{xvb::output_console, Process, ProcessState},
macros::lock,
XVB_URL,
disk::state::ManualDonationLevel, helper::{xvb::output_console, Process, ProcessState}, macros::lock, XVB_URL
};
use crate::disk::state::XvbMode;
@ -25,6 +23,17 @@ pub enum RuntimeMode {
ManuallyDonate,
ManuallyKeep,
Hero,
ManualDonationLevel
}
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
pub enum RuntimeDonationLevel {
VIP,
Donor,
DonorVIP,
DonorWhale,
DonorMega
}
#[derive(Debug, Clone, Default, Deserialize)]
@ -48,7 +57,9 @@ 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: f64
pub runtime_manual_amount: f64,
#[serde(skip)]
pub runtime_manual_donation_level: RuntimeDonationLevel
}
impl XvbPrivStats {
@ -126,6 +137,19 @@ impl From<XvbMode> for RuntimeMode {
XvbMode::ManuallyDonate => Self::ManuallyDonate,
XvbMode::ManuallyKeep => Self::ManuallyKeep,
XvbMode::Hero => Self::Hero,
XvbMode::ManualDonationLevel => Self::ManualDonationLevel
}
}
}
impl From<ManualDonationLevel> for RuntimeDonationLevel {
fn from(level: ManualDonationLevel) -> Self {
match level {
ManualDonationLevel::VIP => RuntimeDonationLevel::VIP,
ManualDonationLevel::Donor => RuntimeDonationLevel::Donor,
ManualDonationLevel::DonorVIP => RuntimeDonationLevel::DonorVIP,
ManualDonationLevel::DonorWhale => RuntimeDonationLevel::DonorWhale,
ManualDonationLevel::DonorMega => RuntimeDonationLevel::DonorMega
}
}
}
@ -134,4 +158,10 @@ impl Default for RuntimeMode {
fn default() -> Self {
Self::Auto
}
}
impl Default for RuntimeDonationLevel {
fn default() -> Self {
Self::VIP
}
}