Skip to content

Commit

Permalink
wip - settings, cleanup, balance padding
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Dec 14, 2023
1 parent f0baf5a commit e11fa7b
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 54 deletions.
4 changes: 4 additions & 0 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ impl Core {
}
}

pub fn balance_padding(&self) -> bool {
self.settings.user_interface.balance_padding
}

pub fn has_stack(&self) -> bool {
!self.stack.is_empty()
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<'core> Menu<'core> {
// // ui.ctx().set_visuals(Visuals::light());
// }

if self.core.settings.developer.enable_screen_capture() {
if self.core.settings.developer.screen_capture_enabled() {
ui.add_space(8.);
ui.vertical_centered(|ui| {
use egui_phosphor::light::CAMERA;
Expand Down
4 changes: 2 additions & 2 deletions core/src/modules/account_manager/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ impl<'context> BalancePane<'context> {

if !core.state().is_synced() {
ui.label(
s2kws_layout_job(balance.mature, network_type, theme_color().balance_syncing_color,FontId::proportional(28.))
s2kws_layout_job(core.balance_padding(), balance.mature, network_type, theme_color().balance_syncing_color,FontId::proportional(28.))
);
ui.label(RichText::new(i18n("The balance may be out of date during node sync")).size(12.).color(theme_color().balance_syncing_color));
return;
} else {
ui.label(
s2kws_layout_job(balance.mature, network_type, theme_color().balance_color,FontId::proportional(28.))
s2kws_layout_job(core.balance_padding(), balance.mature, network_type, theme_color().balance_color,FontId::proportional(28.))
);
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/modules/account_manager/menus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl AccountMenu {
account_list.retain(|selectable_account|{
if selectable_account.descriptor().prv_key_data_id() == Some(&prv_key_data_info.id) {

if ui.account_selector_button(selectable_account, network_type, account.id() == selectable_account.id()).clicked() {
if ui.account_selector_button(selectable_account, network_type, account.id() == selectable_account.id(), core.balance_padding()).clicked() {
account_manager.request_estimate();
account_manager.state = AccountManagerState::Overview {
account: selectable_account.clone(),
Expand All @@ -143,7 +143,7 @@ impl AccountMenu {
ui.separator();

account_list.iter().for_each(|selectable_account|{
if ui.account_selector_button(selectable_account, network_type, account.id() == selectable_account.id()).clicked() {
if ui.account_selector_button(selectable_account, network_type, account.id() == selectable_account.id(), core.balance_padding()).clicked() {
account_manager.request_estimate();
account_manager.state = AccountManagerState::Overview {
account: selectable_account.clone(),
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/account_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl AccountManager {
}

account_collection.iter().for_each(|account_select| {
if ui.account_selector_button(account_select, &network_type, false).clicked() {
if ui.account_selector_button(account_select, &network_type, false, core.balance_padding()).clicked() {
this.select(Some(account_select.clone()), core.device().clone());
if core.device().single_pane() {
this.section = AccountManagerSection::Overview;
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/account_manager/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'context> Transfer<'context> {
return;
}

if ui.account_selector_button(account, network_type, false).clicked() {
if ui.account_selector_button(account, network_type, false, core.balance_padding()).clicked() {
self.context.transfer_to_account = Some(account.clone());
}
});
Expand Down
8 changes: 5 additions & 3 deletions core/src/modules/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl ModuleT for Scanner {
continue;
}

if ui.account_selector_button(selectable_account, &network_type, false).clicked() {
if ui.account_selector_button(selectable_account, &network_type, false, core.balance_padding()).clicked() {
this.state = State::Settings {
account: selectable_account.clone(),
};
Expand Down Expand Up @@ -332,7 +332,7 @@ impl ModuleT for Scanner {
ui.add_space(16.);
ui.label(RichText::new("BALANCE").size(12.).raised());
ui.label(
s2kws_layout_job(*balance, &network_type, theme_color().balance_color,FontId::proportional(28.))
s2kws_layout_job(core.balance_padding(), *balance, &network_type, theme_color().balance_color,FontId::proportional(28.))
);
}
_ => {}
Expand All @@ -355,6 +355,8 @@ impl ModuleT for Scanner {

State::Finish => {

let balance_padding = core.balance_padding();

Panel::new(self)
.with_caption("Scanner")
.with_close_enabled(false, |_|{
Expand All @@ -370,7 +372,7 @@ impl ModuleT for Scanner {
ui.add_space(16.);
ui.label(RichText::new("BALANCE").size(12.).raised());
ui.label(
s2kws_layout_job(*balance, &network_type, theme_color().balance_color,FontId::proportional(28.))
s2kws_layout_job(balance_padding, *balance, &network_type, theme_color().balance_color,FontId::proportional(28.))
);
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/modules/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Settings {
ui.horizontal_wrapped(|ui|{
KaspadNodeKind::iter().for_each(|node_kind| {
#[cfg(not(target_arch = "wasm32"))] {
if !core.settings.developer.enable_experimental_features() && matches!(*node_kind,KaspadNodeKind::IntegratedInProc|KaspadNodeKind::ExternalAsDaemon) {
if !core.settings.developer.experimental_features_enabled() && matches!(*node_kind,KaspadNodeKind::IntegratedInProc|KaspadNodeKind::ExternalAsDaemon) {
return;
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ impl Settings {
}

#[cfg(not(target_arch = "wasm32"))]
if core.settings.developer.enable_custom_daemon_args() && core.settings.node.node_kind.is_config_capable() {
if core.settings.developer.custom_daemon_args_enabled() && core.settings.node.node_kind.is_config_capable() {
use kaspad_lib::args::Args;
use clap::error::ErrorKind as ClapErrorKind;
use crate::runtime::services::kaspa::Config;
Expand Down
8 changes: 4 additions & 4 deletions core/src/modules/wallet_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ impl ModuleT for WalletCreate {
if score < 80.0 {
ui.label("");
ui.label(RichText::new(i18n("Secret is too weak")).color(error_color()));
if !core.settings.developer.disable_password_restrictions() {
if !core.settings.developer.password_restrictions_disabled() {
submit = false;
ui.label(RichText::new(i18n("Please create a stronger password")).color(error_color()));
}
Expand All @@ -550,7 +550,7 @@ impl ModuleT for WalletCreate {
}
})
.with_footer(|this,ui| {
let is_weak = !core.settings.developer.disable_password_restrictions() && this.context.wallet_secret_score.unwrap_or_default() < 80.0;
let is_weak = !core.settings.developer.password_restrictions_disabled() && this.context.wallet_secret_score.unwrap_or_default() < 80.0;
let enabled = this.context.wallet_secret == this.context.wallet_secret_confirm && this.context.wallet_secret.is_not_empty();
if ui.large_button_enabled(enabled && !is_weak, "Continue").clicked() {
this.state = State::PaymentSecret;
Expand Down Expand Up @@ -654,7 +654,7 @@ impl ModuleT for WalletCreate {
if score < 80.0 {
ui.label("");
ui.label(RichText::new(i18n("Passphrase is too weak")).color(egui::Color32::from_rgb(255, 120, 120)));
if !core.settings.developer.disable_password_restrictions() {
if !core.settings.developer.password_restrictions_disabled() {
submit = false;
ui.label(RichText::new(i18n("Please create a stronger passphrase")).color(egui::Color32::from_rgb(255, 120, 120)));
}
Expand All @@ -679,7 +679,7 @@ impl ModuleT for WalletCreate {
})
.with_footer(|this,ui| {
if this.context.enable_payment_secret {
let is_weak = !core.settings.developer.disable_password_restrictions() && this.context.payment_secret_score.unwrap_or_default() < 80.0;
let is_weak = !core.settings.developer.password_restrictions_disabled() && this.context.payment_secret_score.unwrap_or_default() < 80.0;
let enabled = this.context.wallet_secret == this.context.wallet_secret_confirm && this.context.wallet_secret.is_not_empty();
if ui.large_button_enabled(enabled && !is_weak, "Continue").clicked() {
this.state = State::CreateWalletConfirm;
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/wallet_secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl ModuleT for WalletSecret {
if let Some(score) = this.context.new_wallet_secret_score {
ui.label("");
render_secret_score_text(ui, "Secret score:", score);
if score < 80.0 && !core.settings.developer.disable_password_restrictions() {
if score < 80.0 && !core.settings.developer.password_restrictions_disabled() {
allow = false;
ui.label(RichText::new(i18n("Please enter a stronger secret")).color(error_color()));
}
Expand Down
10 changes: 9 additions & 1 deletion core/src/primitives/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pub trait AccountSelectorButtonExtension {
account: &Account,
network_type: &NetworkType,
selected: bool,
balance_padding: bool,
) -> Response;
}

Expand All @@ -222,6 +223,7 @@ impl AccountSelectorButtonExtension for Ui {
account: &Account,
network_type: &NetworkType,
selected: bool,
balance_padding: bool,
) -> Response {
let account_name = account.name_or_id();

Expand All @@ -241,7 +243,13 @@ impl AccountSelectorButtonExtension for Ui {
CompositeButton::image_and_text(
icon,
RichText::new(account_name).size(14.),
s2kws_layout_job(balance.mature, network_type, color, FontId::monospace(16.)),
s2kws_layout_job(
balance_padding,
balance.mature,
network_type,
color,
FontId::monospace(16.),
),
),
)
} else {
Expand Down
47 changes: 12 additions & 35 deletions core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ pub struct NodeSettings {
pub rpc_kind: RpcKind,
pub wrpc_url: String,
pub wrpc_encoding: WrpcEncoding,
// pub enable_wrpc_borsh : true,
// pub wrpc_network_interface_borsh: NetworkInterfaceConfig,
pub enable_wrpc_json: bool,
pub wrpc_json_network_interface: NetworkInterfaceConfig,
pub enable_grpc: bool,
Expand All @@ -200,22 +198,16 @@ impl Default for NodeSettings {
cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
let wrpc_url = "127.0.0.1";
// let wrpc_url = "ws://127.0.0.1:17210".to_string();
} else {
use workflow_dom::utils::*;
use workflow_core::runtime;
let wrpc_url = if runtime::is_chrome_extension() {
"ws://127.0.0.1".to_string()
} else {
let location = location().unwrap();
//let protocol = location.protocol().expect("unable to get protocol");
let hostname = location.hostname().expect("KaspadNodeKind: Unable to get hostname");
//log_warning!("protocol: {}", protocol);
//log_warning!("hostname: {}", hostname);
hostname.to_string()
};

//,Network::Testnet10.default_borsh_rpc_port()); // window().location().hostname().expect("KaspadNodeKind: Unable to get hostname");
}
}

Expand All @@ -235,9 +227,6 @@ impl Default for NodeSettings {
kaspad_daemon_binary: String::default(),
kaspad_daemon_args: String::default(),
kaspad_daemon_args_enable: false,
// {
// url: "".to_string(),
// },
}
}
}
Expand Down Expand Up @@ -324,7 +313,6 @@ impl Default for MetricsSettings {
graph_range_from: 0,
graph_range_to: 15 * 60,
disabled: AHashSet::default(),
// rows : 5,
}
}
}
Expand All @@ -336,6 +324,7 @@ pub struct UserInterfaceSettings {
pub theme_style: String,
pub scale: f32,
pub metrics: MetricsSettings,
pub balance_padding: bool,
}

impl Default for UserInterfaceSettings {
Expand All @@ -345,21 +334,11 @@ impl Default for UserInterfaceSettings {
theme_style: "Rounded".to_string(),
scale: 1.0,
metrics: MetricsSettings::default(),
balance_padding: true,
}
}
}

// pub type PluginSettings = HashMap<String, serde_json::Value>;

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct PluginSettings {
pub enabled: bool, //HashMap<String, bool>,
pub settings: serde_json::Value, //HashMap<String, serde_json::Value>,
}

pub type PluginSettingsMap = HashMap<String, PluginSettings>;

#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct DeveloperSettings {
Expand All @@ -368,6 +347,7 @@ pub struct DeveloperSettings {
pub disable_password_restrictions: bool,
pub enable_experimental_features: bool,
pub enable_custom_daemon_args: bool,
pub market_monitor_on_testnet: bool,
}

impl Default for DeveloperSettings {
Expand All @@ -378,24 +358,25 @@ impl Default for DeveloperSettings {
disable_password_restrictions: false,
enable_experimental_features: false,
enable_custom_daemon_args: true,
market_monitor_on_testnet: false,
}
}
}

impl DeveloperSettings {
pub fn enable_screen_capture(&self) -> bool {
pub fn screen_capture_enabled(&self) -> bool {
self.enable && self.enable_screen_capture
}

pub fn disable_password_restrictions(&self) -> bool {
pub fn password_restrictions_disabled(&self) -> bool {
self.enable && self.disable_password_restrictions
}

pub fn enable_experimental_features(&self) -> bool {
pub fn experimental_features_enabled(&self) -> bool {
self.enable && self.enable_experimental_features
}

pub fn enable_custom_daemon_args(&self) -> bool {
pub fn custom_daemon_args_enabled(&self) -> bool {
self.enable && self.enable_custom_daemon_args
}
}
Expand All @@ -406,14 +387,12 @@ pub struct Settings {
pub initialized: bool,
pub splash_screen: bool,
pub version: String,
// pub developer_mode: bool,
pub developer: DeveloperSettings,
pub node: NodeSettings,
pub user_interface: UserInterfaceSettings,
pub language_code: String,
pub enable_plugins: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub plugins: Option<PluginSettingsMap>,
pub update_monitor: bool,
pub market_monitor: bool,
}

impl Default for Settings {
Expand All @@ -426,13 +405,12 @@ impl Default for Settings {

splash_screen: true,
version: "0.0.0".to_string(),
// developer_mode: false,
developer: DeveloperSettings::default(),
node: NodeSettings::default(),
user_interface: UserInterfaceSettings::default(),
language_code: "en".to_string(),
enable_plugins: true,
plugins: Some(PluginSettingsMap::default()),
update_monitor: true,
market_monitor: true,
}
}
}
Expand Down Expand Up @@ -463,7 +441,6 @@ impl Settings {

let storage = storage()?;
if storage.exists().await.unwrap_or(false) {
// println!("Settings::load: file exists: {}", storage.filename());
match read_json::<Self>(storage.filename()).await {
Ok(settings) => Ok(settings),
Err(err) => {
Expand Down
13 changes: 12 additions & 1 deletion core/src/utils/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn format_address(address: &Address, range: Option<usize>) -> String {

/// SOMPI (u64) to KASPA (string) with suffix layout job generator
pub fn s2kws_layout_job(
enable: bool,
sompi: u64,
network_type: &NetworkType,
color: Color32,
Expand All @@ -49,7 +50,17 @@ pub fn s2kws_layout_job(
let style = Style::default();

let mut layout_job = LayoutJob::default();
if sompi == 0 {
if !enable {
let kas = sompi_to_kaspa_string_with_suffix(sompi, network_type);
let text = RichText::new(kas).color(color).font(font.clone());
text.append_to(
&mut layout_job,
&style,
FontSelection::Default,
Align::Center,
);
layout_job
} else if sompi == 0 {
let transparent = color.gamma_multiply(0.25);
let left = RichText::new("0.0").color(color).font(font.clone());
let right = RichText::new("0000000 ")
Expand Down

0 comments on commit e11fa7b

Please sign in to comment.