Skip to content

Commit

Permalink
handling for enable/disable of market and update monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Dec 20, 2023
1 parent ef30620 commit 5f11cbc
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 292 deletions.
28 changes: 15 additions & 13 deletions core/src/modules/account_manager/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@ impl<'context> BalancePane<'context> {
);
}

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();
symbols.into_iter().for_each(|symbol| {
if let Some(data) = price_list.get(symbol) {
let symbol = symbol.to_uppercase();
let MarketData { price, change : _, .. } = data;
let text = format!("{:.8} {}", sompi_to_kaspa(balance.mature) * (*price), symbol.as_str());
ui.label(RichText::new(text).font(FontId::proportional(16.)));
}
});
if core.settings.market_monitor {
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();
symbols.into_iter().for_each(|symbol| {
if let Some(data) = price_list.get(symbol) {
let symbol = symbol.to_uppercase();
let MarketData { price, change : _, .. } = data;
let text = format!("{:.8} {}", sompi_to_kaspa(balance.mature) * (*price), symbol.as_str());
ui.label(RichText::new(text).font(FontId::proportional(16.)));
}
});
}
}
}

if balance.pending != 0 {
ui.label(format!(
"Pending: {}",
Expand Down
92 changes: 47 additions & 45 deletions core/src/modules/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,54 +106,56 @@ impl Overview {
.auto_shrink([false; 2])
.show(ui, |ui| {

CollapsingHeader::new(i18n("Market"))
.default_open(true)
.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() {
if let Some(price_list) = market.price.as_ref() {
let mut symbols = price_list.keys().collect::<Vec<_>>();
symbols.sort();
symbols.into_iter().for_each(|symbol| {
if let Some(data) = price_list.get(symbol) {
let symbol = symbol.to_uppercase();
CollapsingHeader::new(symbol.as_str())
.default_open(true)
.show(ui, |ui| {
Grid::new("market_price_info_grid")
.num_columns(2)
.spacing([16.0,4.0])
.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();

ui.label(i18n("Change"));
if change > 0. {
ui.colored_label(theme_color().market_up_color, RichText::new(format!("+{:.2}% ",change)));
} else {
ui.colored_label(theme_color().market_down_color, RichText::new(format!("{:.2}% ",change)));
};
ui.end_row();

ui.label(i18n("Volume"));
ui.colored_label(theme_color().market_default_color, RichText::new(format!("{} {}",volume.trunc().separated_string(),symbol.to_uppercase())));
ui.end_row();

ui.label(i18n("Market Cap"));
ui.colored_label(theme_color().market_default_color, RichText::new(format!("{} {}",market_cap.trunc().separated_string(),symbol.to_uppercase())));
ui.end_row();
});

});
}
})
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();
symbols.into_iter().for_each(|symbol| {
if let Some(data) = price_list.get(symbol) {
let symbol = symbol.to_uppercase();
CollapsingHeader::new(symbol.as_str())
.default_open(true)
.show(ui, |ui| {
Grid::new("market_price_info_grid")
.num_columns(2)
.spacing([16.0,4.0])
.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();

ui.label(i18n("Change"));
if change > 0. {
ui.colored_label(theme_color().market_up_color, RichText::new(format!("+{:.2}% ",change)));
} else {
ui.colored_label(theme_color().market_down_color, RichText::new(format!("{:.2}% ",change)));
};
ui.end_row();

ui.label(i18n("Volume"));
ui.colored_label(theme_color().market_default_color, RichText::new(format!("{} {}",volume.trunc().separated_string(),symbol.to_uppercase())));
ui.end_row();

ui.label(i18n("Market Cap"));
ui.colored_label(theme_color().market_default_color, RichText::new(format!("{} {}",market_cap.trunc().separated_string(),symbol.to_uppercase())));
ui.end_row();
});

});
}
})
}
}
}

});
});
}

CollapsingHeader::new(i18n("Resources"))
.default_open(true)
Expand Down
19 changes: 11 additions & 8 deletions core/src/modules/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Settings {
use crate::runtime::services::kaspa::Config;

ui.add_space(4.);
ui.checkbox(&mut self.settings.node.kaspad_daemon_args_enable, i18n("Enable custom daemon arguments"));
ui.checkbox(&mut self.settings.node.kaspad_daemon_args_enable, i18n("Activate custom daemon arguments"));
ui.add_space(4.);

if self.settings.node.kaspad_daemon_args_enable {
Expand Down Expand Up @@ -344,19 +344,22 @@ impl Settings {
CollapsingHeader::new("Market Monitor")
.default_open(true)
.show(ui, |ui| {
let mut v = false;
if ui.checkbox(&mut v, i18n("Enable Market Monitor")).changed() {
if ui.checkbox(&mut self.settings.market_monitor, i18n("Enable Market Monitor")).changed() {
core.settings.market_monitor = self.settings.market_monitor;
self.runtime.market_monitor_service().enable(core.settings.market_monitor);
core.store_settings();
}
});

#[cfg(not(target_arch = "wasm32"))]
CollapsingHeader::new("Check for Updates")
.default_open(true)
.show(ui, |ui| {
let mut v = false;
if ui.checkbox(&mut v, i18n("Check for Software Updates via GitHub")).changed() {
if ui.checkbox(&mut self.settings.update_monitor, i18n("Check for Software Updates via GitHub")).changed() {
core.settings.update_monitor = self.settings.update_monitor;
self.runtime.update_monitor_service().enable(core.settings.update_monitor);
core.store_settings();
}

});
});

Expand All @@ -382,7 +385,7 @@ impl Settings {
#[cfg(not(target_arch = "wasm32"))]
ui.checkbox(
&mut self.settings.developer.enable_custom_daemon_args,
i18n("Allow custom daemon arguments")
i18n("Enable custom daemon arguments")
).on_hover_text_at_pointer(
i18n("Allow custom arguments for the Rusty Kaspa daemon")
);
Expand All @@ -397,7 +400,7 @@ impl Settings {
#[cfg(not(target_arch = "wasm32"))]
ui.checkbox(
&mut self.settings.developer.enable_screen_capture,
i18n("Screen capture")
i18n("Enable screen capture")
).on_hover_text_at_pointer(
i18n("Allows you to take screenshots from within the application")
);
Expand Down
31 changes: 25 additions & 6 deletions core/src/runtime/services/market_monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ pub type CurrencyDescriptorList = Vec<CurrencyDescriptor>;
// pub struct MarketData {}

pub enum MarketMonitorEvents {
Enable,
Disable,
Exit,
}

pub struct MarketMonitorService {
pub application_events: ApplicationEventsChannel,
pub plugin_events: Channel<MarketMonitorEvents>,
pub service_events: Channel<MarketMonitorEvents>,
pub task_ctl: Channel<()>,
pub is_enabled: AtomicBool,
pub currencies: Mutex<Option<Vec<String>>>,
Expand All @@ -85,17 +87,17 @@ pub struct MarketMonitorService {
}

impl MarketMonitorService {
pub fn new(application_events: ApplicationEventsChannel, _settings: &Settings) -> Self {
pub fn new(application_events: ApplicationEventsChannel, settings: &Settings) -> Self {
let currencies = ["usd", "btc"]
.into_iter()
.map(String::from)
.collect::<Vec<_>>();

Self {
application_events,
plugin_events: Channel::unbounded(),
service_events: Channel::unbounded(),
task_ctl: Channel::oneshot(),
is_enabled: AtomicBool::new(false),
is_enabled: AtomicBool::new(settings.market_monitor),
provider: Mutex::new(MarketDataProvider::default()),
// ------
// currencies: Mutex::new(Some(vec!["usd".to_string()])),
Expand All @@ -115,6 +117,14 @@ impl MarketMonitorService {
self.provider.lock().unwrap().clone()
}

pub fn enable(&self, enable : bool) {
if enable {
self.service_events.try_send(MarketMonitorEvents::Enable).unwrap();
} else {
self.service_events.try_send(MarketMonitorEvents::Disable).unwrap();
}
}

#[allow(dead_code)]
async fn update_available_currencies(&self) -> Result<()> {
let available_currencies = self.provider().fetch_available_currencies().await?;
Expand Down Expand Up @@ -195,9 +205,18 @@ impl Service for MarketMonitorService {
this.update_market_price_list().await?;
},

msg = this.as_ref().plugin_events.receiver.recv().fuse() => {
msg = this.as_ref().service_events.receiver.recv().fuse() => {
if let Ok(event) = msg {
match event {
MarketMonitorEvents::Enable => {
if !this.is_enabled.load(Ordering::SeqCst) {
this.is_enabled.store(true, Ordering::SeqCst);
this.update_market_price_list().await?;
}
}
MarketMonitorEvents::Disable => {
this.is_enabled.store(false, Ordering::SeqCst);
}
MarketMonitorEvents::Exit => {
break;
}
Expand All @@ -215,7 +234,7 @@ impl Service for MarketMonitorService {
}

fn terminate(self: Arc<Self>) {
self.plugin_events
self.service_events
.sender
.try_send(MarketMonitorEvents::Exit)
.unwrap();
Expand Down
Loading

0 comments on commit 5f11cbc

Please sign in to comment.