Skip to content

Commit

Permalink
allow settings reset in case of a configuration error
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jan 15, 2024
1 parent 0ccbea0 commit 0a10333
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
30 changes: 23 additions & 7 deletions core/src/egui/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ pub trait UiExtension {
fn confirm_medium(
&mut self,
align: Align,
ack: impl Into<WidgetText>,
ack: Option<impl Into<WidgetText>>,
nack: impl Into<WidgetText>,
) -> Option<Confirm>;
fn confirm_medium_apply_cancel(&mut self, align: Align) -> Option<Confirm>;
fn confirm_medium_cancel(&mut self, align: Align) -> Option<Confirm>;
}

impl UiExtension for Ui {
Expand All @@ -53,21 +54,26 @@ impl UiExtension for Ui {
fn confirm_medium(
&mut self,
align: Align,
ack: impl Into<WidgetText>,
ack: Option<impl Into<WidgetText>>,
nack: impl Into<WidgetText>,
) -> Option<Confirm> {
let mut resp: Option<Confirm> = None;
self.horizontal(|ui| {
let buttons = if ack.is_some() { 2. } else { 1. };

if matches!(align, Align::Max) {
ui.add_space(
ui.available_width()
- 16.
- (theme_style().medium_button_size.x + ui.spacing().item_spacing.x) * 2.,
- (theme_style().medium_button_size.x + ui.spacing().item_spacing.x)
* buttons,
);
}

if ui.medium_button(ack).clicked() {
resp.replace(Confirm::Ack);
if let Some(ack) = ack {
if ui.medium_button(ack).clicked() {
resp.replace(Confirm::Ack);
}
}

if ui.medium_button(nack).clicked() {
Expand All @@ -83,8 +89,18 @@ impl UiExtension for Ui {

self.confirm_medium(
align,
format!("{} {}", egui_phosphor::light::CHECK, "Apply"),
format!("{} {}", egui_phosphor::light::X, "Cancel"),
Some(format!("{} {}", egui_phosphor::light::CHECK, i18n("Apply"))),
format!("{} {}", egui_phosphor::light::X, i18n("Cancel")),
)
}

fn confirm_medium_cancel(&mut self, align: Align) -> Option<Confirm> {
let _theme = theme();

self.confirm_medium(
align,
Option::<&str>::None,
format!("{} {}", egui_phosphor::light::X, i18n("Cancel")),
)
}
}
Expand Down
10 changes: 9 additions & 1 deletion core/src/modules/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,17 @@ impl Settings {
.color(theme_color().error_color),
);
ui.add_space(4.);
ui.label(i18n("Unable to change node settings until the problem is resolved."));
ui.label(i18n("Unable to change node settings until the problem is resolved"));

ui.add_space(8.);

if let Some(response) = ui.confirm_medium_cancel(Align::Max) {
if matches!(response, Confirm::Nack) {
self.settings.node = core.settings.node.clone();
self.grpc_network_interface = NetworkInterfaceEditor::from(&self.settings.node.grpc_network_interface);
}
}

ui.separator();

} else if node_settings_error.is_none() {
Expand Down
10 changes: 5 additions & 5 deletions resources/i18n/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"fi": "Finnish",
"es": "Español",
"lt": "Lithuanian",
"sv": "Swedish",
"uk": "Ukrainian",
"sv": "Swedish",
"af": "Afrikaans",
"et": "Esti",
"en": "English",
Expand Down Expand Up @@ -64,11 +64,11 @@
"fil": {},
"pa": {},
"fa": {},
"sv": {},
"fi": {},
"es": {},
"lt": {},
"uk": {},
"sv": {},
"af": {},
"et": {},
"en": {
Expand Down Expand Up @@ -223,6 +223,7 @@
"You must be connected to a node...": "You must be connected to a node...",
"Mainnet": "Mainnet",
"Integrated Daemon": "Integrated Daemon",
"Unable to change node settings until the problem is resolved": "Unable to change node settings until the problem is resolved",
"Key Perf.": "Key Perf.",
"24h Change": "24h Change",
"Processed Dependencies": "Processed Dependencies",
Expand All @@ -235,18 +236,17 @@
"Confirm wallet password": "Confirm wallet password",
"The node is currently syncing with the Kaspa p2p network.": "The node is currently syncing with the Kaspa p2p network.",
"A wallet is stored in a file on your computer.": "A wallet is stored in a file on your computer.",
"Unable to change node settings until the problem is resolved.": "Unable to change node settings until the problem is resolved.",
"A random node will be selected on startup": "A random node will be selected on startup",
"Client RPC": "Client RPC",
"wRPC JSON Tx": "wRPC JSON Tx",
"Virtual DAA Score": "Virtual DAA Score",
"Wallet:": "Wallet:",
"A random node will be selected on startup": "A random node will be selected on startup",
"Double click on the graph to re-center...": "Double click on the graph to re-center...",
"Stor Read": "Stor Read",
"Database Blocks": "Database Blocks",
"Headers": "Headers",
"Use all available system memory": "Use all available system memory",
"Address:": "Address:",
"Headers": "Headers",
"Custom": "Custom",
"Mainnet (Main Kaspa network)": "Mainnet (Main Kaspa network)",
"Developer mode enables advanced and experimental features": "Developer mode enables advanced and experimental features",
Expand Down

0 comments on commit 0a10333

Please sign in to comment.