Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Dec 20, 2023
1 parent 5f11cbc commit cc26156
Show file tree
Hide file tree
Showing 30 changed files with 55 additions and 317 deletions.
10 changes: 4 additions & 6 deletions core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ cfg_if! {

.about(format!("kaspa-ng v{VERSION}-{GIT_DESCRIBE} (rusty-kaspa v{})", kaspa_wallet_core::version()))
.arg(arg!(--disable "Disable node services when starting"))
.arg(arg!(--daemon "Run as Rusty Kaspa p2p daemon (kaspad)"))
.arg(arg!(--daemon "Run as Rusty Kaspa p2p daemon"))
.arg(arg!(--cli "Run as Rusty Kaspa Cli Wallet"))
.arg(
Arg::new("reset-settings")
.long("reset-settings")
Expand All @@ -99,14 +100,11 @@ cfg_if! {
.about("reset i18n data file")
)
)
.subcommand(
Command::new("cli")
.about("Run kaspa-ng as rusty-kaspa cli wallet")
)
;

let matches = cmd.get_matches();
if matches.subcommand_matches("cli").is_some() {

if matches.get_one::<bool>("cli").cloned().unwrap_or(false) {
Args::Cli
} else if let Some(matches) = matches.subcommand_matches("i18n") {
if let Some(_matches) = matches.subcommand_matches("import") {
Expand Down
1 change: 0 additions & 1 deletion core/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ where

impl<Id, T> Collection<Id, T>
where
// Id: IdT,
Id: Copy + Eq + Hash + Debug + ToHex,
T: Clone + IdT<Id = Id> + Debug,
{
Expand Down
10 changes: 4 additions & 6 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ pub struct Core {
application_events_channel: ApplicationEventsChannel,
deactivation: Option<Module>,
module: Module,
pub stack: VecDeque<Module>,
modules: HashMap<TypeId, Module>,
pub stack: VecDeque<Module>,
pub settings: Settings,
pub toasts: Toasts,
screenshot: Option<Arc<ColorImage>>,
pub mobile_style: egui::Style,
pub default_style: egui::Style,

state: State,
hint: Option<Hint>,
discard_hint: bool,
exception: Option<Exception>,
screenshot: Option<Arc<ColorImage>>,

pub metrics: Option<Box<MetricsSnapshot>>,
pub wallet_descriptor: Option<WalletDescriptor>,
Expand Down Expand Up @@ -160,21 +160,19 @@ impl Core {
stack: VecDeque::new(),
settings: settings.clone(),
toasts: Toasts::default(),
screenshot: None,
// status_bar_message: None,
default_style,
mobile_style,

wallet_descriptor: None,
wallet_list: Vec::new(),
prv_key_data_map: None,
account_collection: None,
// selected_account: None,
metrics: None,
state: Default::default(),
hint: None,
discard_hint: false,
exception: None,
screenshot: None,

release: None,

Expand Down Expand Up @@ -595,7 +593,7 @@ impl Core {
self.market.as_mut().unwrap().ohlc.replace(ohlc);
}
}
},
}
Events::ThemeChange => {
if let Some(account_collection) = self.account_collection.as_ref() {
account_collection
Expand Down
13 changes: 3 additions & 10 deletions core/src/egui/composite_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ impl CompositeIcon {
valign,
);

let truncate = true; //self.truncate;
let wrap = !truncate && ui.wrap_text(); //None.unwrap_or_else(|| ui.wrap_text());
let truncate = true;
let wrap = !truncate && ui.wrap_text();
let available_width = ui.available_width();

if wrap
Expand Down Expand Up @@ -309,14 +309,8 @@ impl CompositeIcon {
text_job.job.wrap.max_width = f32::INFINITY;
};

// if ui.is_grid() {
// // TODO(emilk): remove special Grid hacks like these
// text_job.job.halign = Align::LEFT;
// text_job.job.justify = false;
// } else {
text_job.job.halign = Align::Center; //ui.layout().horizontal_placement();
text_job.job.halign = Align::Center;
text_job.job.justify = ui.layout().horizontal_justify();
//};

let text_galley = ui.fonts(|f| text_job.into_galley(f));

Expand Down Expand Up @@ -398,7 +392,6 @@ impl Widget for CompositeIcon {
};

let button_padding = self._padding(ui);
//pos.x -= button_padding.x;
ui.painter().add(epaint::TextShape {
pos,
galley: icon_text.galley,
Expand Down
31 changes: 0 additions & 31 deletions core/src/egui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,32 @@ type PopupHandler<'panel> = Box<dyn FnOnce(&mut Ui, &mut bool) + 'panel>;

pub struct PopupPanel<'panel> {
id: Id,
// title: String,
min_width: Option<f32>,
max_height: Option<f32>,
widget: PopupWidget<'panel>,
content: PopupHandler<'panel>,
// widget: Option<PopupWidget<'panel>>,
// content: Option<PopupHandler<'panel>>,
// with_caption: bool,
caption: Option<String>,
with_close_button: bool,
// with_pulldown_marker: bool,
close_on_interaction: bool,
}

impl<'panel> PopupPanel<'panel> {
pub fn new(
ui: &mut Ui,
id: impl Into<String>,
// title: impl Into<String>,
widget: impl FnOnce(&mut Ui) -> Response + 'panel,
content: impl FnOnce(&mut Ui, &mut bool) + 'panel,
) -> Self {
let id = ui.make_persistent_id(id.into());

Self {
id,
// title: title.into(),
min_width: None,
max_height: None,
// widget: Some(Box::new(widget)),
// content: Some(Box::new(content)),
widget: Box::new(widget),
content: Box::new(content),
// with_caption: false,
caption: None,
with_close_button: false,
// with_pulldown_marker: false,
close_on_interaction: false,
}
}
Expand All @@ -56,10 +45,6 @@ impl<'panel> PopupPanel<'panel> {
self
}

// pub fn with_caption(mut self, caption: bool) -> Self {
// self.with_caption = caption;
// self
// }
pub fn with_caption(mut self, caption: impl Into<String>) -> Self {
self.caption = Some(caption.into());
self
Expand All @@ -70,30 +55,14 @@ impl<'panel> PopupPanel<'panel> {
self
}

// pub fn with_pulldown_marker(mut self, pulldown_marker: bool) -> Self {
// self.with_pulldown_marker = pulldown_marker;
// self
// }

pub fn with_close_on_interaction(mut self, close_on_interaction: bool) -> Self {
self.close_on_interaction = close_on_interaction;
self
}

pub fn build(self, ui: &mut Ui) {
// let title = self.title.clone();
// let content = self.content.take().unwrap();
// // let response = ui.add(Label::new(format!("{} ⏷", title)).sense(Sense::click()));
// let text = if self.with_pulldown_marker {
// format!("{} ⏷", title)
// } else {
// title.clone()
// };

// let response = ui.add(Label::new(text).sense(Sense::click()));
let response = (self.widget)(ui);
if response.clicked() {
// if response.clicked() {
ui.memory_mut(|mem| mem.toggle_popup(self.id));
}

Expand Down
9 changes: 2 additions & 7 deletions core/src/egui/theme/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub struct ThemeColor {

pub qr_background: Color32,
pub qr_foreground: Color32,
// pub toast_background : Color32,
pub selection_color: Color32,
pub progress_color: Color32,

Expand Down Expand Up @@ -84,12 +83,11 @@ impl ThemeColor {
alert_color: Color32::from_rgb(255, 136, 136),
warning_color: egui::Color32::from_rgb(255, 255, 136),
icon_syncing_color: egui::Color32::from_rgb(255, 255, 136),
// connected_color: egui::Color32::from_rgb(144, 238, 144),
icon_connected_color: egui::Color32::from_rgb(85, 233, 136),
icon_color_default: Color32::from_rgb(240, 240, 240),
ack_color: Color32::from_rgb(100, 200, 100),
nack_color: Color32::from_rgb(200, 100, 100),
market_default_color: Color32::from_rgb(240,240,240),
market_default_color: Color32::from_rgb(240, 240, 240),
market_up_color: Color32::from_rgb(136, 255, 136),
market_down_color: Color32::from_rgb(255, 136, 136),

Expand All @@ -98,7 +96,6 @@ impl ThemeColor {

qr_background: Color32::from_rgba(0, 0, 0, 0),
qr_foreground: Color32::WHITE,
// selection_color: Color32::from_rgb(58, 221, 190),
selection_color: Color32::from_rgb(40, 153, 132),
progress_color: Color32::from_rgb(71, 105, 97),

Expand Down Expand Up @@ -156,15 +153,13 @@ impl ThemeColor {
icon_color_default: Color32::from_rgb(32, 32, 32),
ack_color: Color32::from_rgb(100, 200, 100),
nack_color: Color32::from_rgb(200, 100, 100),
market_default_color: Color32::from_rgb(20,20,20),
market_default_color: Color32::from_rgb(20, 20, 20),
market_up_color: Color32::from_rgb(41, 77, 41),
market_down_color: Color32::from_rgb(77, 41, 41),

raised_text_color: Color32::from_rgb(0, 0, 0),
raised_text_shadow: Color32::from_rgb(255, 255, 255),

// qr_background: Color32::from_rgba(0, 0, 0, 255),
// qr_foreground: Color32::WHITE,
qr_background: Color32::from_rgba(255, 255, 255, 0),
qr_foreground: Color32::BLACK,
selection_color: Color32::from_rgb(165, 201, 197),
Expand Down
8 changes: 0 additions & 8 deletions core/src/egui/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ impl AsRef<Theme> for Theme {
}
}

// impl AsMut<Theme> for Theme {
// fn as_mut(&mut self) -> &mut Self {
// self
// }
// }

static mut THEME: Option<Theme> = None;
#[inline(always)]
pub fn theme() -> &'static Theme {
Expand Down Expand Up @@ -143,8 +137,6 @@ pub fn apply_theme_style_by_name(ctx: &Context, theme_style_name: impl Into<Stri
}

pub fn apply_theme(ctx: &Context, theme: Theme) {
// generate_theme_icons(theme.color.icon_color_default.to_hex().as_str());

unsafe {
THEME = Some(theme.clone());
}
Expand Down
6 changes: 0 additions & 6 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,3 @@ impl<T> From<ChannelError<T>> for Error {
Error::ChannelError(err.to_string())
}
}

// impl<T> From<downcast::DowncastError<T>> for Error {
// fn from(e: downcast::DowncastError<T>) -> Self {
// Error::DowncastError(e.to_string())
// }
// }
2 changes: 1 addition & 1 deletion core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ pub use crate::device::{Device, Orientation};
pub use crate::egui::*;
pub use crate::error::Error;
pub use crate::events::{ApplicationEventsChannel, Events};
pub use crate::market::MarketData;
pub use crate::menu::Menu;
pub use crate::modules;
pub use crate::modules::{Module, ModuleCaps, ModuleStyle, ModuleT};
pub use crate::market::MarketData;
pub use crate::network::Network;
pub use crate::notifications::{UserNotification, UserNotifyKind};
pub use crate::primitives::{
Expand Down
12 changes: 6 additions & 6 deletions core/src/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ pub struct MarketData {
pub market_cap: f64,
pub volume: f64,
pub change: f64,
pub precision : usize,
pub precision: usize,
}

impl MarketData {
pub fn new(symbol : &str) -> Self {
pub fn new(symbol: &str) -> Self {
let precision = precision_from_symbol(symbol);
Self {
price : 0.0,
market_cap : 0.0,
volume : 0.0,
change : 0.0,
price: 0.0,
market_cap: 0.0,
volume: 0.0,
change: 0.0,
precision,
}
}
Expand Down
10 changes: 0 additions & 10 deletions core/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ impl<'core> Menu<'core> {
}

if self.core.device().single_pane() {
// ui.menu_button(format!("{} Kaspa NG", LIST), |ui| {
ui.menu_button("Kaspa NG", |ui| {
self.render_menu(ui);
});
Expand Down Expand Up @@ -131,15 +130,6 @@ impl<'core> Menu<'core> {
});
});

// if ui.button("Change").clicked() {
// if theme().name == "Light" {
// apply_theme(ui, Theme::dark());
// } else {
// apply_theme(ui, Theme::light());
// }
// // ui.ctx().set_visuals(Visuals::light());
// }

if self.core.settings.developer.screen_capture_enabled() {
ui.add_space(8.);
ui.vertical_centered(|ui| {
Expand Down
15 changes: 7 additions & 8 deletions core/src/modules/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ impl Overview {
.show(ui, |ui| {

if core.settings.market_monitor {
CollapsingHeader::new(i18n("Market"))
.default_open(true)
.show(ui, |ui| {
if let Some(market) = core.market.as_ref() {

CollapsingHeader::new(i18n("Market"))
.default_open(true)
.show(ui, |ui| {

if let Some(market) = core.market.as_ref() {
if let Some(price_list) = market.price.as_ref() {
let mut symbols = price_list.keys().collect::<Vec<_>>();
symbols.sort();
Expand All @@ -127,7 +128,6 @@ impl Overview {
.show(ui, |ui| {
let MarketData { price, volume, change, market_cap , precision } = *data;
ui.label(i18n("Price"));
// ui.colored_label(theme_color().market_default_color, RichText::new(format_price_with_symbol(price, precision, symbol.as_str())).font(FontId::monospace(14.))); //
ui.colored_label(theme_color().market_default_color, RichText::new(format_price_with_symbol(price, precision, symbol.as_str()))); //
ui.end_row();

Expand All @@ -152,9 +152,8 @@ impl Overview {
}
})
}
}

});
});
}
}

CollapsingHeader::new(i18n("Resources"))
Expand Down
Loading

0 comments on commit cc26156

Please sign in to comment.