Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder83singh committed Sep 12, 2024
1 parent ff44953 commit c7f68ac
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 40 deletions.
7 changes: 3 additions & 4 deletions core/src/egui/selection_panels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,14 @@ impl<Value: PartialEq> SelectionPanels<Value> {
responce
};

let response = ui
.indent_with_size("selection-panels", indent, Box::new(add_contents))
.response;
ui.indent_with_size("selection-panels", indent, Box::new(add_contents))
.response
// response |= ui
// .vertical_centered(|ui| (self.build_footer)(ui, current_value))
// .response;
// ui.label(" ");
// ui.label(format!(" vertical: {vertical}"));
// ui.label(format!("panels_width {}", panels_width));
response
// response
}
}
15 changes: 7 additions & 8 deletions core/src/modules/account_manager/estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<'context> Estimator<'context> {
(false, GeneratorSummary::new(network_id), GeneratorSummary::new(network_id))
}
EstimatorStatus::None => {
ui.label(format!("{} {} {}", i18n("Please enter"), kaspa_suffix(&network_type), i18n("amount to send")));
ui.label(format!("{} {} {}", i18n("Please enter"), kaspa_suffix(network_type), i18n("amount to send")));
(false, GeneratorSummary::new(network_id), GeneratorSummary::new(network_id))
}
};
Expand Down Expand Up @@ -202,20 +202,19 @@ impl<'context> Estimator<'context> {
// }
);

for mode in buckets.into_iter().filter_map(|v|v) {
for mode in buckets.into_iter().flatten() {
let bucket = mode.bucket();
let aggregate_mass = actual_estimate.aggregate_mass;
let number_of_generated_stages = actual_estimate.number_of_generated_stages;
let feerate = bucket.feerate;
let seconds = bucket.seconds.max(1.0) * number_of_generated_stages as f64;
let network_type = network_type;
let total_kas = feerate * aggregate_mass as f64 * 1e-8;
let total_sompi = (feerate * aggregate_mass as f64) as u64;
let total_usd = usd_rate.map(|rate| total_kas * rate);
// println!("total_kas: {:?}, total_usd: {:?} usd_rate: {:?}", total_kas, total_usd, usd_rate);
fee_selection = fee_selection.add_with_footer(mode, i18n(mode.to_string().as_str()), format_duration_estimate(seconds), move |ui| {
// ui.label(format!("{} µKAS", feerate * aggregate_mass as f64 * 0.01));
ui.label(RichText::new(format!("{}",sompi_to_kaspa_string_with_suffix(total_sompi, &network_type))).strong());
ui.label(RichText::new(sompi_to_kaspa_string_with_suffix(total_sompi, &network_type)).strong());
if let Some(usd) = total_usd {
let usd = format_currency(usd, 6);
ui.label(RichText::new(format!("~{} USD", usd)).strong());
Expand Down Expand Up @@ -366,12 +365,12 @@ fn format_duration_estimate(seconds: f64) -> String {
let seconds = seconds as u64;

if seconds == 1 {
format!("< {} second", seconds as u64)
format!("< {seconds} second")
} else if seconds < 60 {
format!("< {} seconds", seconds as u64)
format!("< {seconds} seconds")
} else if minutes == 1 {
format!("< {} minute", minutes)
format!("< {minutes} minute")
} else {
format!("< {} minutes", minutes as u64)
format!("< {minutes} minutes")
}
}
30 changes: 16 additions & 14 deletions core/src/modules/account_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ enum AddressStatus {
Invalid(String),
}

#[derive(Debug, Clone, Copy)]
#[derive(Default, Debug, Clone, Copy)]
pub enum FeeMode{
#[default]
None,
Low(FeerateBucket),
// #[default]
Expand All @@ -132,24 +133,25 @@ impl FeeMode {
}
}

impl Default for FeeMode {
fn default() -> Self {
// FeeMode::Economic(FeerateBucket::default())
FeeMode::None
}
}
// impl Default for FeeMode {
// fn default() -> Self {
// // FeeMode::Economic(FeerateBucket::default())
// FeeMode::None
// }
// }

impl Eq for FeeMode {}

impl PartialEq for FeeMode {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(FeeMode::None, FeeMode::None) => true,
(FeeMode::Low(_), FeeMode::Low(_)) => true,
(FeeMode::Economic(_), FeeMode::Economic(_)) => true,
(FeeMode::Priority(_), FeeMode::Priority(_)) => true,
_ => false,
}
// match (self, other) {
// (FeeMode::None, FeeMode::None) => true,
// (FeeMode::Low(_), FeeMode::Low(_)) => true,
// (FeeMode::Economic(_), FeeMode::Economic(_)) => true,
// (FeeMode::Priority(_), FeeMode::Priority(_)) => true,
// _ => false,
// }
matches!((self, other), (FeeMode::None, FeeMode::None) | (FeeMode::Low(_), FeeMode::Low(_)) | (FeeMode::Economic(_), FeeMode::Economic(_)) | (FeeMode::Priority(_), FeeMode::Priority(_)))
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/modules/account_manager/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl<'context> Processor<'context> {
pub fn render(&mut self, core : &mut Core, ui: &mut Ui, rc : &RenderContext) {

let RenderContext { account, network_type, .. } = rc;
let network_type = network_type.clone();
let network_type = *network_type;

ui.add_space(8.);
match self.context.transaction_kind.as_ref().unwrap() {
Expand Down Expand Up @@ -148,7 +148,7 @@ impl<'context> Processor<'context> {

spawn_with_result(&send_result, async move {

let fee_rate = calculate_fee_rate(network_type.clone(), account_id, send_amount_sompi, priority_fee_sompi).await;
let fee_rate = calculate_fee_rate(network_type, account_id, send_amount_sompi, priority_fee_sompi).await;

let request = AccountsSendRequest {
account_id,
Expand All @@ -174,7 +174,7 @@ impl<'context> Processor<'context> {
let transfer_amount_sompi = self.context.send_amount_sompi;

spawn_with_result(&send_result, async move {
let fee_rate = calculate_fee_rate(network_type.clone(), source_account_id, transfer_amount_sompi, priority_fee_sompi).await;
let fee_rate = calculate_fee_rate(network_type, source_account_id, transfer_amount_sompi, priority_fee_sompi).await;

let request = AccountsTransferRequest {
source_account_id,
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ kaspa_ng_macros::register_modules!(
#[cfg(not(target_arch = "wasm32"))]
kaspa_ng_macros::register_modules!(register_native_modules, [changelog, logs, node,]);

// #[cfg(not(feature = "lean"))]
#[cfg(not(feature = "lean"))]
kaspa_ng_macros::register_modules!(register_advanced_modules, [block_dag, metrics,]);

pub enum ModuleStyle {
Expand Down
21 changes: 11 additions & 10 deletions core/src/utils/average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ const MAX_AVERAGE_SAMPLES: usize = 6;
const AVERAGE_ALPHA_HIGH: f64 = 0.8;
const AVERAGE_ALPHA_LOW: f64 = 0.5;

#[derive(Default)]
pub struct FeerateEstimate {
pub low: FeerateBucketAverage,
pub economic: FeerateBucketAverage,
pub priority: FeerateBucketAverage,
}

impl Default for FeerateEstimate {
fn default() -> Self {
Self {
low: FeerateBucketAverage::default(),
economic: FeerateBucketAverage::default(),
priority: FeerateBucketAverage::default(),
}
}
}
// impl Default for FeerateEstimate {
// fn default() -> Self {
// Self {
// low: FeerateBucketAverage::default(),
// economic: FeerateBucketAverage::default(),
// priority: FeerateBucketAverage::default(),
// }
// }
// }

impl FeerateEstimate {
pub fn new(estimate: &RpcFeeEstimate) -> Self {
Expand Down Expand Up @@ -127,7 +128,7 @@ impl<const SAMPLES: usize> FeerateBucketAverageN<SAMPLES> {
}

fn insert(&mut self, value: FeerateBucket) {
if self.samples.len() == 0 {
if self.samples.is_empty() {
self.samples.push_back(value);
} else {
let delta = self.average;
Expand Down

0 comments on commit c7f68ac

Please sign in to comment.