Skip to content

Commit

Permalink
storage management
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jan 16, 2024
1 parent 0a10333 commit a9af914
Show file tree
Hide file tree
Showing 22 changed files with 480 additions and 142 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ cfg-if = "1.0.0"
chrome-sys = "0.1.0"
# chrome-sys = {path = "../chrome-sys"}
chrono = "0.4.31"
convert_case = "0.6.0"
clap = { version = "4.4.7", features = ["derive", "string", "cargo"] }
convert_case = "0.6.0"
ctrlc = { version = "3.2", features = ["termination"] }
derivative = "2.2.0"
downcast = "0.11.0"
Expand All @@ -147,6 +147,7 @@ js-sys = "0.3.64"
log = "0.4.20"
nix = "0.27.1"
num_cpus = "1.15.0"
open = "5.0.1"
pad = "0.1.6"
passwords = "3.1.16"
qrcode = "0.12.0"
Expand All @@ -163,6 +164,7 @@ sysinfo = "0.29.10"
thiserror = "1.0.50"
tokio = { version = "1", features = ["sync", "rt-multi-thread", "process"] }
toml = "0.8.8"
walkdir = "2.4.0"
wasm-bindgen = "0.2.87"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3.64", features = ['Window'] }
Expand Down
2 changes: 2 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ slug.workspace = true
smallvec.workspace = true
thiserror.workspace = true
toml.workspace = true
walkdir.workspace = true
wasm-bindgen.workspace = true
xxhash-rust.workspace = true
zeroize.workspace = true
Expand Down Expand Up @@ -104,6 +105,7 @@ kaspa-rpc-service.workspace = true
kaspa-wrpc-server.workspace = true
kaspad.workspace = true
num_cpus.workspace = true
open.workspace = true
rlimit.workspace = true
sysinfo.workspace = true
tokio.workspace = true
Expand Down
22 changes: 19 additions & 3 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct Core {
callback_map: CallbackMap,
pub network_pressure: NetworkPressure,
notifications: Notifications,
pub storage: Storage,
}

impl Core {
Expand Down Expand Up @@ -192,6 +193,7 @@ impl Core {
callback_map: CallbackMap::default(),
network_pressure: NetworkPressure::default(),
notifications: Notifications::default(),
storage: Storage::default(),
};

modules.values().for_each(|module| {
Expand All @@ -202,9 +204,18 @@ impl Core {

this.wallet_update_list();

#[cfg(target_arch = "wasm32")]
{
this.register_visibility_handler();
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
this.register_visibility_handler();
} else {
let storage = this.storage.clone();
spawn(async move {
loop {
storage.update(None);
task::sleep(Duration::from_secs(60)).await;
}
});
}
}

this
Expand Down Expand Up @@ -616,6 +627,11 @@ impl Core {
_frame: &mut eframe::Frame,
) -> Result<()> {
match event {
Events::UpdateStorage(_options) => {
#[cfg(not(target_arch = "wasm32"))]
self.storage
.update(Some(_options.with_network(self.settings.node.network)));
}
Events::VisibilityChange(state) => match state {
VisibilityState::Visible => {
self.module.clone().show(self);
Expand Down
5 changes: 5 additions & 0 deletions core/src/egui/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub trait UiExtension {
) -> Option<Confirm>;
fn confirm_medium_apply_cancel(&mut self, align: Align) -> Option<Confirm>;
fn confirm_medium_cancel(&mut self, align: Align) -> Option<Confirm>;
fn sized_separator(&mut self, size: Vec2) -> Response;
}

impl UiExtension for Ui {
Expand Down Expand Up @@ -103,6 +104,10 @@ impl UiExtension for Ui {
format!("{} {}", egui_phosphor::light::X, i18n("Cancel")),
)
}

fn sized_separator(&mut self, size: Vec2) -> Response {
self.add_sized(size, Separator::default())
}
}

pub struct LayoutJobBuilderSettings {
Expand Down
2 changes: 2 additions & 0 deletions core/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::imports::*;
use crate::market::*;
use crate::storage::StorageUpdateOptions;
use crate::utils::Release;
use kaspa_metrics_core::MetricsSnapshot;
use kaspa_wallet_core::{events as kaspa, storage::PrvKeyDataInfo};
Expand All @@ -8,6 +9,7 @@ pub type ApplicationEventsChannel = crate::runtime::channel::Channel<Events>;

#[derive(Clone)]
pub enum Events {
UpdateStorage(StorageUpdateOptions),
VisibilityChange(VisibilityState),
VersionUpdate(Release),
ThemeChange,
Expand Down
3 changes: 2 additions & 1 deletion core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub use workflow_core::abortable::Abortable;
pub use workflow_core::channel::{oneshot, Channel, Receiver, Sender};
pub use workflow_core::enums::Describe;
pub use workflow_core::extensions::is_not_empty::*;
pub use workflow_core::task::interval;
pub use workflow_core::task;
pub use workflow_core::time::{unixtime_as_millis_f64, Instant};
pub use workflow_dom::utils::*;
pub use workflow_http as http;
Expand Down Expand Up @@ -85,5 +85,6 @@ pub use crate::settings::{
};
pub use crate::state::State;
pub use crate::status::Status;
pub use crate::storage::{Storage, StorageUpdateOptions};
pub use crate::utils::spawn;
pub use crate::utils::*;
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub mod servers;
pub mod settings;
pub mod state;
pub mod status;
pub mod storage;
pub mod sync;
pub mod utils;

Expand Down
17 changes: 11 additions & 6 deletions core/src/modules/account_manager/estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'context> Estimator<'context> {
Focus::Amount,
|ui, text| {
ui.add_space(8.);
ui.label(RichText::new(format!("Enter {} amount to send", kaspa_suffix(network_type))).size(12.).raised());
ui.label(RichText::new(format!("{} {} {}", i18n("Enter"), kaspa_suffix(network_type), i18n("amount to send"))).size(12.).raised());
ui.add_sized(Overview::editor_size(ui), TextEdit::singleline(text)
.vertical_align(Align::Center))
},
Expand All @@ -57,10 +57,15 @@ impl<'context> Estimator<'context> {

// TODO - improve the logic
if core.network_pressure.is_high() {
ui.label(format!("The network is currently experiencing high load (~{}% of its capacity). \
It is recommended that you add a priority fee of at least {:0.3} {} \
to ensure faster transaction acceptance.",
core.network_pressure.capacity(), 0.001, kaspa_suffix(network_type)));
ui.label(format!("{}: {}% {} {} {:0.3} {} {}",
i18n("The network is currently experiencing high load"),
core.network_pressure.capacity(),
i18n("of its capacity."),
i18n("It is recommended that you add a priority fee of at least"),
0.001,
kaspa_suffix(network_type),
i18n("to ensure faster transaction acceptance."),
));
}

ui.add_space(8.);
Expand Down Expand Up @@ -117,7 +122,7 @@ impl<'context> Estimator<'context> {
false
}
EstimatorStatus::None => {
ui.label(i18n("Please enter KAS amount to send"));
ui.label(format!("{} {} {}", i18n("Please enter"), kaspa_suffix(network_type), i18n("amount to send")));
false
}
};
Expand Down
3 changes: 3 additions & 0 deletions core/src/modules/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ impl Overview {
if let Some(system) = runtime().system() {
system.render(ui);
}

#[cfg(not(target_arch = "wasm32"))]
core.storage.render(ui);

CollapsingHeader::new(i18n("License Information"))
.default_open(false)
Expand Down
Loading

0 comments on commit a9af914

Please sign in to comment.