Skip to content

Commit

Permalink
wip - cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Dec 23, 2023
1 parent 78ddcdc commit 0d7f23f
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 118 deletions.
66 changes: 42 additions & 24 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct Core {

pub device: Device,
pub market: Option<Market>,
pub servers : Arc<Vec<Server>>,
pub servers: Arc<Vec<Server>>,
pub debug: bool,
}

Expand Down Expand Up @@ -180,7 +180,7 @@ impl Core {

device: Device::default(),
market: None,
servers : parse_default_servers().clone(),
servers: parse_default_servers().clone(),
debug: false,
};

Expand Down Expand Up @@ -744,22 +744,24 @@ impl Core {
}
CoreWallet::AccountDeactivation { ids: _ } => {}
CoreWallet::AccountActivation { ids: _ } => {}
CoreWallet::AccountCreate { account_descriptor } => {
let account = Account::from(account_descriptor);
self.account_collection
.as_mut()
.expect("account collection")
.push_unchecked(account.clone());
let device = self.device().clone();
self.get_mut::<modules::AccountManager>()
.select(Some(account.clone()), device);
self.select::<modules::AccountManager>();

let wallet = self.wallet().clone();
spawn(async move {
wallet.accounts_activate(Some(vec![account.id()])).await?;
Ok(())
});
CoreWallet::AccountCreate {
account_descriptor: _,
} => {
// let account = Account::from(account_descriptor);
// self.account_collection
// .as_mut()
// .expect("account collection")
// .push_unchecked(account.clone());
// let device = self.device().clone();
// self.get_mut::<modules::AccountManager>()
// .select(Some(account.clone()), device);
// // self.select::<modules::AccountManager>();

// let wallet = self.wallet().clone();
// spawn(async move {
// wallet.accounts_activate(Some(vec![account.id()])).await?;
// Ok(())
// });
}
CoreWallet::AccountUpdate { account_descriptor } => {
let account_id = account_descriptor.account_id();
Expand Down Expand Up @@ -968,6 +970,27 @@ impl Core {
Ok(())
}

pub fn handle_account_creation(&mut self, account_descriptor: AccountDescriptor) -> Account {
let account = Account::from(account_descriptor);
self.account_collection
.as_mut()
.expect("account collection")
.push_unchecked(account.clone());
let device = self.device().clone();
self.get_mut::<modules::AccountManager>()
.select(Some(account.clone()), device);
// self.select::<modules::AccountManager>();

let account_id = account.id();
let wallet = self.wallet().clone();
spawn(async move {
wallet.accounts_activate(Some(vec![account_id])).await?;
Ok(())
});

account
}

fn handle_keyboard_events(
&mut self,
key: Key,
Expand Down Expand Up @@ -1028,13 +1051,8 @@ impl Core {
let runtime = self.runtime.clone();
spawn(async move {
let server_list = load_servers().await?;
runtime
.send(Events::ServerList {
server_list,
})
.await?;
runtime.send(Events::ServerList { server_list }).await?;
Ok(())
});
}

}
15 changes: 13 additions & 2 deletions core/src/egui/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,24 @@ impl<'render> MnemonicPresenter<'render> {
initiate a private key recovery."
}

pub fn render(&mut self, ui: &mut Ui) {
pub fn warning(&self) -> &'static str {
"This wallet will never ask you for this mnemonic phrase unless you manually \
initiate a private key recovery."
}

pub fn render(&mut self, ui: &mut Ui, caption: Option<impl Into<String>>) {
ui.vertical_centered(|ui| {
ui.label(
RichText::new("Never share your mnemonic with anyone!")
.color(theme_color().alert_color),
);
ui.separator();
// ui.separator();
ui.label(" ");

if let Some(caption) = caption {
ui.label(caption.into());
}

ui.label(" ");
});

Expand Down
4 changes: 2 additions & 2 deletions core/src/egui/theme/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl ThemeColor {
qr_background: Color32::from_rgba(0, 0, 0, 0),
qr_foreground: Color32::WHITE,
selection_background_color: Color32::from_rgb(40, 153, 132),
selection_text_color: Color32::from_rgb(220,220,220),
selection_text_color: Color32::from_rgb(220, 220, 220),
progress_color: Color32::from_rgb(71, 105, 97),

transaction_incoming: Color32::from_rgb(162, 245, 187),
Expand Down Expand Up @@ -168,7 +168,7 @@ impl ThemeColor {
qr_background: Color32::from_rgba(255, 255, 255, 0),
qr_foreground: Color32::BLACK,
selection_background_color: Color32::from_rgb(165, 201, 197),
selection_text_color: Color32::from_rgb(20,20,20),
selection_text_color: Color32::from_rgb(20, 20, 20),
progress_color: Color32::from_rgb(165, 201, 197),

transaction_incoming: Color32::from_rgb(15, 77, 35),
Expand Down
2 changes: 1 addition & 1 deletion core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum Events {
},
Error(Box<String>),
ServerList {
server_list : Arc<Vec<Server>>,
server_list: Arc<Vec<Server>>,
},
WalletList {
wallet_list: Arc<Vec<WalletDescriptor>>,
Expand Down
2 changes: 1 addition & 1 deletion core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub use crate::primitives::{
};
pub use crate::result::Result;
pub use crate::runtime::{runtime, spawn, spawn_with_result, Payload, Runtime, Service};
pub use crate::servers::{Server,load_servers};
pub use crate::servers::{load_servers, Server};
pub use crate::settings::{
KaspadNodeKind, NetworkInterfaceConfig, NetworkInterfaceKind, NodeSettings, RpcConfig,
Settings, UserInterfaceSettings,
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub mod notifications;
pub mod primitives;
pub mod result;
pub mod runtime;
pub mod servers;
pub mod settings;
pub mod state;
pub mod status;
pub mod servers;
pub mod sync;
pub mod utils;
23 changes: 22 additions & 1 deletion core/src/modules/account_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,36 @@ impl ModuleT for AccountCreate {

if let Some(result) = account_create_result.take() {
match result {
Ok(_descriptor) => {
Ok(account_descriptor) => {
println!("Account created successfully");
// let account = Account::from(descriptor);
// core.account_collection.as_mut().expect("account collection").push_unchecked(account.clone());
// core.get_mut::<modules::AccountManager>().select(Some(account));
// core.select::<modules::AccountManager>();



// let account = Account::from(account_descriptor);
// core.account_collection
// .as_mut()
// .expect("account collection")
// .push_unchecked(account.clone());
// let device = core.device().clone();
// core.get_mut::<modules::AccountManager>()
// .select(Some(account.clone()), device);
// // self.select::<modules::AccountManager>();

// let wallet = core.wallet().clone();
// spawn(async move {
// wallet.accounts_activate(Some(vec![account.id()])).await?;
// Ok(())
// });

core.handle_account_creation(account_descriptor);

// - RESET STATE
self.state = State::Start;

}
Err(err) => {
println!("Account creation error: {}", err);
Expand Down
4 changes: 4 additions & 0 deletions core/src/modules/account_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ impl AccountManager {
Panel::new(self)
.with_body(|_this, ui| {
ui.label("Please create an account");
ui.label("");
if ui.large_button("Create Account").clicked() {
core.select::<modules::AccountCreate>();
}
}).render(ui);
} else if account_collection.len() == 1 {
self.select(Some(account_collection.first().unwrap().clone()), core.device().clone());
Expand Down
24 changes: 12 additions & 12 deletions core/src/modules/donations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Donations {
Entry::Occupied(entry) => entry.into_mut(),
Entry::Vacant(entry) => {
let uri = format!("bytes://{}-{}.svg", Self::ADDRESS, theme_color().name);
let qr = render_qrcode(&Self::ADDRESS, 128, 128);
let qr = render_qrcode(Self::ADDRESS, 128, 128);
entry.insert((uri, qr.as_bytes().to_vec().into()))
},
};
Expand Down Expand Up @@ -76,17 +76,17 @@ impl ModuleT for Donations {

ui.label(" ");

if ui
.add(Label::new(format!("{} {CLIPBOARD_TEXT}", format_address_string(Self::ADDRESS, Some(12)))).sense(Sense::click()))
.on_hover_ui_at_pointer(|ui|{
ui.vertical(|ui|{
ui.label("Click to copy the donation address to clipboard".to_string());
});
})
.clicked() {
ui.output_mut(|o| o.copied_text = Self::ADDRESS.to_owned());
runtime().notify(UserNotification::info(format!("{CLIPBOARD_TEXT} {}", i18n("Copied to clipboard"))).short())
}
let response = ui.add(Label::new(format!("{} {CLIPBOARD_TEXT}", format_address_string(Self::ADDRESS, Some(12)))).sense(Sense::click()))
.on_hover_ui_at_pointer(|ui|{
ui.vertical(|ui|{
ui.label("Click to copy the donation address to clipboard".to_string());
});
});

if response.clicked() {
ui.output_mut(|o| o.copied_text = Self::ADDRESS.to_owned());
runtime().notify(UserNotification::info(format!("{CLIPBOARD_TEXT} {}", i18n("Copied to clipboard"))).short())
}

ui.label(" ");

Expand Down
16 changes: 6 additions & 10 deletions core/src/modules/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,12 @@ impl ModuleT for Metrics {
});
});

if graph_range_from != core.settings.user_interface.metrics.graph_range_from {
if graph_range_from.abs_diff(graph_range_to) < 15 {
graph_range_to = graph_range_from + 15;
}
if graph_range_from != core.settings.user_interface.metrics.graph_range_from && graph_range_from.abs_diff(graph_range_to) < 15{
graph_range_to = graph_range_from + 15;
}

if graph_range_to != core.settings.user_interface.metrics.graph_range_to {
if graph_range_to.abs_diff(graph_range_from) < 15 {
graph_range_from = graph_range_to - 15;
}
if graph_range_to != core.settings.user_interface.metrics.graph_range_to && graph_range_to.abs_diff(graph_range_from) < 15 {
graph_range_from = graph_range_to - 15;
}

if graph_range_from.abs_diff(graph_range_to) < 15 {
Expand Down Expand Up @@ -285,8 +281,8 @@ impl Metrics {
let graph_data = {
let metrics_data = self.runtime.metrics_service().metrics_data();
let data = metrics_data.get(&metric).unwrap();
let mut start = range.start.clamp(METRICS_SAMPLES_START, 0).abs() as usize;
let mut end = range.end.clamp(METRICS_SAMPLES_START, 0).abs() as usize;
let mut start = range.start.clamp(METRICS_SAMPLES_START, 0).unsigned_abs();
let mut end = range.end.clamp(METRICS_SAMPLES_START, 0).unsigned_abs();
if start > data.len() {
start = data.len();
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl ModuleT for Testing {
ui.vertical_centered(|ui|{
ui.label("Hello World");
});
MnemonicPresenter::new(phrase, &mut self.mnemonic_presenter_context).render(ui);
MnemonicPresenter::new(phrase, &mut self.mnemonic_presenter_context).render(ui, Some("Testing"));
ui.vertical_centered(|ui|{
ui.label("Goodbye World");
});
Expand Down
Loading

0 comments on commit 0d7f23f

Please sign in to comment.