Skip to content

Commit

Permalink
Merge branch 'gamma-dev' of github.com:aspectron/kaspa-ng into gamma-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Sep 12, 2024
2 parents 4aeee0a + 04312e4 commit 9964e18
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
33 changes: 27 additions & 6 deletions core/src/egui/selection_panels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub struct SelectionPanel<V> {
pub value: V,
pub build_heading: Option<UiBuilderFn>,
pub build_footer: Option<UiBuilderFn>,
pub icons: Option<(RichText, RichText)>,
}

impl<Value: PartialEq> SelectionPanel<Value> {
Expand All @@ -92,6 +93,10 @@ impl<Value: PartialEq> SelectionPanel<Value> {
value,
build_heading: None,
build_footer: None,
icons: Some((
RichText::new(egui_phosphor::bold::CHECK).heading(),
RichText::new(egui_phosphor::bold::DOT_OUTLINE).heading(),
)),
}
}
pub fn heading(mut self, build_heading: impl FnOnce(&mut Ui) + 'static) -> Self {
Expand All @@ -102,6 +107,10 @@ impl<Value: PartialEq> SelectionPanel<Value> {
self.build_footer = Some(Box::new(build_footer));
self
}
pub fn icons(mut self, icons: Option<(impl Into<RichText>, impl Into<RichText>)>) -> Self {
self.icons = icons.map(|(a, b)| (a.into(), b.into()));
self
}

pub fn render(
self,
Expand Down Expand Up @@ -131,12 +140,10 @@ impl<Value: PartialEq> SelectionPanel<Value> {
if let Some(build) = self.build_heading {
(build)(ui);
}
let icon = if selected {
egui_phosphor::bold::CHECK
} else {
egui_phosphor::bold::DOT_OUTLINE
};
ui.label(RichText::new(icon).heading());
if let Some((selected_icon, normal_icon)) = self.icons {
let icon = if selected { selected_icon } else { normal_icon };
ui.label(icon);
}
if let Some(build) = self.build_footer {
//ui.visuals_mut().override_text_color = Some(Color32::WHITE);
(build)(ui);
Expand Down Expand Up @@ -223,6 +230,20 @@ impl<Value: PartialEq> SelectionPanels<Value> {
.push(SelectionPanel::new(value, title, sub).footer(build_footer));
self
}
pub fn add_icon_less(
mut self,
value: Value,
title: impl Into<WidgetText>,
sub: impl Into<WidgetText>,
build_footer: impl FnOnce(&mut Ui) + 'static,
) -> Self {
self.panels.push(
SelectionPanel::new(value, title, sub)
.footer(build_footer)
.icons(None::<(RichText, RichText)>),
);
self
}
pub fn panel_min_height(mut self, min_height: f32) -> Self {
self.panel_min_height = min_height;
self
Expand Down
12 changes: 10 additions & 2 deletions core/src/modules/account_manager/estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<'context> Estimator<'context> {
let mut fee_selection = SelectionPanels::new(
120.0,
150.0);

let fee_mode = self.context.fee_mode;
for mode in buckets.into_iter().flatten() {
let bucket = mode.bucket();
let feerate = (bucket.feerate - 1.0).max(0.0);
Expand All @@ -142,7 +142,15 @@ impl<'context> Estimator<'context> {
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);
fee_selection = fee_selection.add_with_footer(mode, i18n(mode.to_string().as_str()), format_duration_estimate(seconds), move |ui| {
fee_selection = fee_selection.add_icon_less(mode, i18n(mode.to_string().as_str()), format_duration_estimate(seconds), move |ui| {
// icon
let icon = if mode == fee_mode {
RichText::new(egui_phosphor::bold::CHECK).strong()
} else {
RichText::new(egui_phosphor::bold::DOT_OUTLINE).strong()
};
ui.label(icon);

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);
Expand Down

0 comments on commit 9964e18

Please sign in to comment.