2023-06-27 02:11:07 +03:00
|
|
|
// Copyright 2023 The Grim Developers
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2023-11-08 01:00:56 +03:00
|
|
|
use egui::{Id, RichText};
|
2023-07-01 03:29:05 +03:00
|
|
|
use grin_core::global::ChainTypes;
|
2023-07-03 21:17:49 +03:00
|
|
|
|
2023-07-01 03:29:05 +03:00
|
|
|
use crate::AppConfig;
|
2023-07-13 03:54:27 +03:00
|
|
|
use crate::gui::Colors;
|
2023-11-08 01:00:56 +03:00
|
|
|
use crate::gui::icons::{CLOCK_CLOCKWISE, COMPUTER_TOWER, PLUG, POWER, SHIELD, SHIELD_SLASH};
|
2023-06-27 02:11:07 +03:00
|
|
|
use crate::gui::platform::PlatformCallbacks;
|
2023-08-03 04:11:25 +03:00
|
|
|
use crate::gui::views::{Modal, NetworkContent, View};
|
2023-07-04 00:39:13 +03:00
|
|
|
use crate::gui::views::network::settings::NetworkSettings;
|
2023-11-08 01:00:56 +03:00
|
|
|
use crate::gui::views::types::{ModalContainer, ModalPosition, TextEditOptions};
|
2023-06-27 02:11:07 +03:00
|
|
|
use crate::node::{Node, NodeConfig};
|
|
|
|
|
2023-08-03 04:11:25 +03:00
|
|
|
/// Integrated node general setup section content.
|
2023-07-05 16:06:14 +03:00
|
|
|
pub struct NodeSetup {
|
|
|
|
/// IP Addresses available at system.
|
|
|
|
available_ips: Vec<String>,
|
|
|
|
|
|
|
|
/// API port value.
|
2023-06-27 02:11:07 +03:00
|
|
|
api_port_edit: String,
|
2023-07-05 16:06:14 +03:00
|
|
|
/// Flag to check if API port is available.
|
2023-06-27 02:11:07 +03:00
|
|
|
api_port_available_edit: bool,
|
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
/// Flag to check if API port from saved config value is available.
|
2023-07-11 03:02:44 +03:00
|
|
|
is_api_port_available: bool,
|
2023-06-27 02:11:07 +03:00
|
|
|
|
2023-07-11 03:02:44 +03:00
|
|
|
/// Secret edit value for modal.
|
|
|
|
secret_edit: String,
|
2023-06-27 02:11:07 +03:00
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
/// Future Time Limit value.
|
2023-06-27 02:11:07 +03:00
|
|
|
ftl_edit: String,
|
2023-08-03 04:11:25 +03:00
|
|
|
|
|
|
|
/// [`Modal`] identifiers allowed at this ui container.
|
|
|
|
modal_ids: Vec<&'static str>
|
2023-06-27 02:11:07 +03:00
|
|
|
}
|
|
|
|
|
2023-08-03 04:11:25 +03:00
|
|
|
/// Identifier for API port value [`Modal`].
|
|
|
|
pub const API_PORT_MODAL: &'static str = "api_port";
|
|
|
|
/// Identifier for API secret value [`Modal`].
|
|
|
|
pub const API_SECRET_MODAL: &'static str = "api_secret";
|
|
|
|
/// Identifier for Foreign API secret value [`Modal`].
|
|
|
|
pub const FOREIGN_API_SECRET_MODAL: &'static str = "foreign_api_secret";
|
|
|
|
/// Identifier for FTL value [`Modal`].
|
|
|
|
pub const FTL_MODAL: &'static str = "ftl";
|
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
impl Default for NodeSetup {
|
2023-06-27 02:11:07 +03:00
|
|
|
fn default() -> Self {
|
2023-07-23 19:36:12 +03:00
|
|
|
let (api_ip, api_port) = NodeConfig::get_api_ip_port();
|
2023-06-29 23:52:30 +03:00
|
|
|
let is_api_port_available = NodeConfig::is_api_port_available(&api_ip, &api_port);
|
2023-06-27 02:11:07 +03:00
|
|
|
Self {
|
2023-07-05 16:06:14 +03:00
|
|
|
available_ips: NodeConfig::get_ip_addrs(),
|
2023-06-29 03:42:03 +03:00
|
|
|
api_port_edit: api_port,
|
2023-06-27 02:11:07 +03:00
|
|
|
api_port_available_edit: is_api_port_available,
|
2023-06-29 03:42:03 +03:00
|
|
|
is_api_port_available,
|
2023-07-11 03:02:44 +03:00
|
|
|
secret_edit: "".to_string(),
|
2023-07-05 16:06:14 +03:00
|
|
|
ftl_edit: NodeConfig::get_ftl(),
|
2023-08-03 04:11:25 +03:00
|
|
|
modal_ids: vec![
|
|
|
|
API_PORT_MODAL,
|
|
|
|
API_SECRET_MODAL,
|
|
|
|
FOREIGN_API_SECRET_MODAL,
|
|
|
|
FTL_MODAL
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ModalContainer for NodeSetup {
|
|
|
|
fn modal_ids(&self) -> &Vec<&'static str> {
|
|
|
|
&self.modal_ids
|
|
|
|
}
|
|
|
|
|
|
|
|
fn modal_ui(&mut self,
|
|
|
|
ui: &mut egui::Ui,
|
|
|
|
modal: &Modal,
|
|
|
|
cb: &dyn PlatformCallbacks) {
|
|
|
|
match modal.id {
|
|
|
|
API_PORT_MODAL => self.api_port_modal(ui, modal, cb),
|
|
|
|
API_SECRET_MODAL => self.secret_modal(ui, modal, cb),
|
|
|
|
FOREIGN_API_SECRET_MODAL => self.secret_modal(ui, modal, cb),
|
|
|
|
FTL_MODAL => self.ftl_modal(ui, modal, cb),
|
|
|
|
_ => {}
|
2023-06-27 02:11:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
impl NodeSetup {
|
2024-06-20 22:52:12 +03:00
|
|
|
pub fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
2023-08-03 04:11:25 +03:00
|
|
|
// Draw modal content for current ui container.
|
2024-06-20 22:52:12 +03:00
|
|
|
self.current_modal_ui(ui, cb);
|
2023-06-27 02:11:07 +03:00
|
|
|
|
2023-06-29 03:42:03 +03:00
|
|
|
View::sub_title(ui, format!("{} {}", COMPUTER_TOWER, t!("network_settings.server")));
|
2024-05-29 22:47:17 +03:00
|
|
|
View::horizontal_line(ui, Colors::stroke());
|
2023-08-11 04:23:06 +03:00
|
|
|
ui.add_space(6.0);
|
2023-07-01 03:29:05 +03:00
|
|
|
|
|
|
|
// Show chain type setup.
|
2023-08-09 02:22:16 +03:00
|
|
|
Self::chain_type_ui(ui);
|
2023-08-11 04:23:06 +03:00
|
|
|
ui.add_space(2.0);
|
2023-06-27 02:11:07 +03:00
|
|
|
|
|
|
|
// Show loading indicator or controls to stop/start/restart node.
|
|
|
|
if Node::is_stopping() || Node::is_restarting() || Node::is_starting() {
|
|
|
|
ui.vertical_centered(|ui| {
|
2023-07-03 21:17:49 +03:00
|
|
|
ui.add_space(8.0);
|
2023-06-27 02:11:07 +03:00
|
|
|
View::small_loading_spinner(ui);
|
2023-07-03 21:17:49 +03:00
|
|
|
ui.add_space(2.0);
|
2023-06-27 02:11:07 +03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if Node::is_running() {
|
|
|
|
ui.scope(|ui| {
|
|
|
|
// Setup spacing between buttons.
|
2023-06-29 03:42:03 +03:00
|
|
|
ui.spacing_mut().item_spacing = egui::Vec2::new(6.0, 0.0);
|
2023-06-27 02:11:07 +03:00
|
|
|
ui.add_space(6.0);
|
|
|
|
|
|
|
|
ui.columns(2, |columns| {
|
|
|
|
columns[0].vertical_centered_justified(|ui| {
|
2024-05-29 22:47:17 +03:00
|
|
|
View::action_button(ui, t!("network_settings.disable"), || {
|
2023-06-27 02:11:07 +03:00
|
|
|
Node::stop(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
columns[1].vertical_centered_justified(|ui| {
|
2024-05-29 22:47:17 +03:00
|
|
|
View::action_button(ui, t!("network_settings.restart"), || {
|
2023-06-27 02:11:07 +03:00
|
|
|
Node::restart();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
ui.add_space(6.0);
|
|
|
|
ui.vertical_centered(|ui| {
|
2023-06-29 03:42:03 +03:00
|
|
|
let enable_text = format!("{} {}", POWER, t!("network_settings.enable"));
|
2024-05-29 22:47:17 +03:00
|
|
|
View::action_button(ui, enable_text, || {
|
2023-06-27 02:11:07 +03:00
|
|
|
Node::start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-01 03:29:05 +03:00
|
|
|
// Autorun node setup.
|
2023-06-27 02:11:07 +03:00
|
|
|
ui.vertical_centered(|ui| {
|
2023-07-03 21:17:49 +03:00
|
|
|
ui.add_space(6.0);
|
2023-07-31 16:23:15 +03:00
|
|
|
NetworkContent::autorun_node_ui(ui);
|
2023-07-03 21:17:49 +03:00
|
|
|
if Node::is_running() {
|
|
|
|
ui.add_space(2.0);
|
|
|
|
ui.label(RichText::new(t!("network_settings.restart_node_required"))
|
|
|
|
.size(16.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::inactive_text())
|
2023-07-03 21:17:49 +03:00
|
|
|
);
|
|
|
|
ui.add_space(4.0);
|
|
|
|
}
|
2023-06-27 02:11:07 +03:00
|
|
|
});
|
2023-07-03 21:17:49 +03:00
|
|
|
ui.add_space(6.0);
|
2023-06-27 02:11:07 +03:00
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
if self.available_ips.is_empty() {
|
2023-07-01 03:29:05 +03:00
|
|
|
// Show message when IP addresses are not available on the system.
|
2023-07-04 00:39:13 +03:00
|
|
|
NetworkSettings::no_ip_address_ui(ui);
|
2023-06-27 02:11:07 +03:00
|
|
|
} else {
|
2024-05-29 22:47:17 +03:00
|
|
|
View::horizontal_line(ui, Colors::item_stroke());
|
2023-07-03 21:17:49 +03:00
|
|
|
ui.add_space(6.0);
|
2023-06-27 02:11:07 +03:00
|
|
|
|
|
|
|
ui.vertical_centered(|ui| {
|
2023-06-29 03:42:03 +03:00
|
|
|
ui.label(RichText::new(t!("network_settings.api_ip"))
|
2023-06-27 02:11:07 +03:00
|
|
|
.size(16.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::gray())
|
2023-06-27 02:11:07 +03:00
|
|
|
);
|
|
|
|
ui.add_space(6.0);
|
2023-07-03 21:17:49 +03:00
|
|
|
|
2023-06-29 03:42:03 +03:00
|
|
|
// Show API IP addresses to select.
|
2023-07-23 19:36:12 +03:00
|
|
|
let (api_ip, api_port) = NodeConfig::get_api_ip_port();
|
2023-07-05 16:06:14 +03:00
|
|
|
NetworkSettings::ip_addrs_ui(ui, &api_ip, &self.available_ips, |selected_ip| {
|
2023-06-29 23:52:30 +03:00
|
|
|
let api_available = NodeConfig::is_api_port_available(selected_ip, &api_port);
|
|
|
|
self.is_api_port_available = api_available;
|
2023-07-01 03:29:05 +03:00
|
|
|
NodeConfig::save_api_address(selected_ip, &api_port);
|
2023-06-29 03:42:03 +03:00
|
|
|
});
|
|
|
|
// Show API port setup.
|
|
|
|
self.api_port_setup_ui(ui, cb);
|
2023-07-01 03:29:05 +03:00
|
|
|
// Show API secret setup.
|
2023-08-03 04:11:25 +03:00
|
|
|
self.secret_ui(API_SECRET_MODAL, ui, cb);
|
2023-07-11 22:05:56 +03:00
|
|
|
ui.add_space(12.0);
|
2023-07-01 03:29:05 +03:00
|
|
|
// Show Foreign API secret setup.
|
2023-08-03 04:11:25 +03:00
|
|
|
self.secret_ui(FOREIGN_API_SECRET_MODAL, ui, cb);
|
2023-07-11 22:05:56 +03:00
|
|
|
ui.add_space(6.0);
|
2023-06-29 03:42:03 +03:00
|
|
|
});
|
2023-06-27 02:11:07 +03:00
|
|
|
}
|
2023-07-01 03:29:05 +03:00
|
|
|
|
|
|
|
ui.add_space(6.0);
|
2024-05-29 22:47:17 +03:00
|
|
|
View::horizontal_line(ui, Colors::item_stroke());
|
2023-07-01 03:29:05 +03:00
|
|
|
ui.add_space(6.0);
|
|
|
|
|
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
// Show FTL setup.
|
|
|
|
self.ftl_ui(ui, cb);
|
|
|
|
|
2023-07-01 21:04:52 +03:00
|
|
|
ui.add_space(6.0);
|
2024-05-29 22:47:17 +03:00
|
|
|
View::horizontal_line(ui, Colors::item_stroke());
|
2023-07-01 21:04:52 +03:00
|
|
|
ui.add_space(6.0);
|
|
|
|
|
|
|
|
// Validation setup.
|
|
|
|
self.validation_mode_ui(ui);
|
|
|
|
|
|
|
|
ui.add_space(6.0);
|
2024-05-29 22:47:17 +03:00
|
|
|
View::horizontal_line(ui, Colors::item_stroke());
|
2023-07-01 21:04:52 +03:00
|
|
|
ui.add_space(6.0);
|
|
|
|
|
|
|
|
// Archive mode setup.
|
|
|
|
self.archive_mode_ui(ui);
|
2023-07-01 03:29:05 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
/// Draw [`ChainTypes`] setup content.
|
2023-08-09 02:22:16 +03:00
|
|
|
pub fn chain_type_ui(ui: &mut egui::Ui) {
|
2023-08-10 19:54:12 +03:00
|
|
|
ui.vertical_centered(|ui| {
|
2024-05-29 22:47:17 +03:00
|
|
|
ui.label(RichText::new(t!("network.type")).size(16.0).color(Colors::gray()));
|
2023-08-10 19:54:12 +03:00
|
|
|
});
|
|
|
|
|
2023-07-01 03:29:05 +03:00
|
|
|
let saved_chain_type = AppConfig::chain_type();
|
|
|
|
let mut selected_chain_type = saved_chain_type;
|
|
|
|
|
2023-07-03 21:17:49 +03:00
|
|
|
ui.add_space(8.0);
|
2023-07-01 03:29:05 +03:00
|
|
|
ui.columns(2, |columns| {
|
|
|
|
columns[0].vertical_centered(|ui| {
|
|
|
|
let main_type = ChainTypes::Mainnet;
|
2024-04-22 22:01:09 +03:00
|
|
|
View::radio_value(ui, &mut selected_chain_type, main_type, t!("network.mainnet"));
|
2023-07-01 03:29:05 +03:00
|
|
|
});
|
|
|
|
columns[1].vertical_centered(|ui| {
|
|
|
|
let test_type = ChainTypes::Testnet;
|
2024-04-22 22:01:09 +03:00
|
|
|
View::radio_value(ui, &mut selected_chain_type, test_type, t!("network.testnet"));
|
2023-07-01 03:29:05 +03:00
|
|
|
})
|
|
|
|
});
|
2023-07-03 21:17:49 +03:00
|
|
|
ui.add_space(8.0);
|
2023-07-01 03:29:05 +03:00
|
|
|
|
2024-05-04 16:25:44 +03:00
|
|
|
if saved_chain_type != selected_chain_type && !Node::is_restarting() {
|
2023-07-01 03:29:05 +03:00
|
|
|
AppConfig::change_chain_type(&selected_chain_type);
|
2024-04-18 05:20:49 +03:00
|
|
|
if Node::is_running() {
|
|
|
|
Node::restart();
|
|
|
|
}
|
2023-07-01 03:29:05 +03:00
|
|
|
}
|
2023-06-27 02:11:07 +03:00
|
|
|
}
|
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
/// Draw API port setup content.
|
2023-08-03 04:11:25 +03:00
|
|
|
fn api_port_setup_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
2024-05-29 22:47:17 +03:00
|
|
|
ui.label(RichText::new(t!("network_settings.api_port")).size(16.0).color(Colors::gray()));
|
2023-07-05 16:06:14 +03:00
|
|
|
ui.add_space(6.0);
|
|
|
|
|
2023-07-23 19:36:12 +03:00
|
|
|
let (_, port) = NodeConfig::get_api_ip_port();
|
2024-05-29 22:47:17 +03:00
|
|
|
View::button(ui, format!("{} {}", PLUG, port.clone()), Colors::button(), || {
|
2023-06-29 03:42:03 +03:00
|
|
|
// Setup values for modal.
|
|
|
|
self.api_port_edit = port;
|
|
|
|
self.api_port_available_edit = self.is_api_port_available;
|
2023-06-27 02:11:07 +03:00
|
|
|
|
2023-06-29 03:42:03 +03:00
|
|
|
// Show API port modal.
|
2023-08-03 04:11:25 +03:00
|
|
|
Modal::new(API_PORT_MODAL)
|
2023-06-29 03:42:03 +03:00
|
|
|
.position(ModalPosition::CenterTop)
|
2023-07-23 11:48:28 +03:00
|
|
|
.title(t!("network_settings.change_value"))
|
|
|
|
.show();
|
2023-06-29 03:42:03 +03:00
|
|
|
cb.show_keyboard();
|
|
|
|
});
|
2023-06-29 23:52:30 +03:00
|
|
|
ui.add_space(6.0);
|
2023-06-29 03:42:03 +03:00
|
|
|
|
|
|
|
if !self.is_api_port_available {
|
2023-06-29 23:52:30 +03:00
|
|
|
// Show error when API server port is unavailable.
|
2023-06-29 03:42:03 +03:00
|
|
|
ui.label(RichText::new(t!("network_settings.port_unavailable"))
|
|
|
|
.size(16.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::red()));
|
2023-06-29 23:52:30 +03:00
|
|
|
ui.add_space(6.0);
|
2023-06-27 02:11:07 +03:00
|
|
|
}
|
2023-07-01 03:29:05 +03:00
|
|
|
ui.add_space(6.0);
|
2023-06-29 03:42:03 +03:00
|
|
|
}
|
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
/// Draw API port [`Modal`] content.
|
2023-08-03 04:11:25 +03:00
|
|
|
fn api_port_modal(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks) {
|
2023-06-29 03:42:03 +03:00
|
|
|
ui.add_space(6.0);
|
|
|
|
ui.vertical_centered(|ui| {
|
2024-05-29 22:47:17 +03:00
|
|
|
ui.label(RichText::new(t!("network_settings.api_port")).size(17.0).color(Colors::gray()));
|
2023-07-01 21:04:52 +03:00
|
|
|
ui.add_space(6.0);
|
2023-06-29 03:42:03 +03:00
|
|
|
|
|
|
|
// Draw API port text edit.
|
2024-05-21 13:31:46 +03:00
|
|
|
let mut api_port_edit_opts = TextEditOptions::new(Id::from(modal.id)).h_center();
|
|
|
|
View::text_edit(ui, cb, &mut self.api_port_edit, &mut api_port_edit_opts);
|
2023-06-29 03:42:03 +03:00
|
|
|
|
2023-07-01 21:04:52 +03:00
|
|
|
// Show error when specified port is unavailable or reminder to restart enabled node.
|
2023-06-29 03:42:03 +03:00
|
|
|
if !self.api_port_available_edit {
|
|
|
|
ui.add_space(12.0);
|
|
|
|
ui.label(RichText::new(t!("network_settings.port_unavailable"))
|
|
|
|
.size(16.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::red()));
|
2023-07-01 21:04:52 +03:00
|
|
|
} else {
|
2023-07-04 00:39:13 +03:00
|
|
|
NetworkSettings::node_restart_required_ui(ui);
|
2023-06-29 03:42:03 +03:00
|
|
|
}
|
|
|
|
ui.add_space(12.0);
|
2023-07-01 21:04:52 +03:00
|
|
|
});
|
2023-06-29 03:42:03 +03:00
|
|
|
|
2023-07-01 21:04:52 +03:00
|
|
|
// Show modal buttons.
|
|
|
|
ui.scope(|ui| {
|
|
|
|
// Setup spacing between buttons.
|
2024-06-04 14:05:45 +03:00
|
|
|
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
|
2023-07-01 21:04:52 +03:00
|
|
|
|
|
|
|
// Save button callback.
|
|
|
|
let on_save = || {
|
|
|
|
// Check if port is available.
|
2023-07-23 19:36:12 +03:00
|
|
|
let (api_ip, _) = NodeConfig::get_api_ip_port();
|
2023-07-01 21:04:52 +03:00
|
|
|
let available = NodeConfig::is_api_port_available(&api_ip, &self.api_port_edit);
|
|
|
|
self.api_port_available_edit = available;
|
2023-06-27 02:11:07 +03:00
|
|
|
|
2023-07-01 21:04:52 +03:00
|
|
|
if available {
|
|
|
|
// Save port at config if it's available.
|
|
|
|
NodeConfig::save_api_address(&api_ip, &self.api_port_edit);
|
2023-07-01 03:29:05 +03:00
|
|
|
|
2024-05-15 14:15:18 +03:00
|
|
|
if Node::is_running() {
|
|
|
|
Node::restart();
|
|
|
|
}
|
|
|
|
|
2023-07-01 21:04:52 +03:00
|
|
|
self.is_api_port_available = true;
|
|
|
|
cb.hide_keyboard();
|
|
|
|
modal.close();
|
|
|
|
}
|
|
|
|
};
|
2023-07-01 03:29:05 +03:00
|
|
|
|
2023-07-01 21:04:52 +03:00
|
|
|
ui.columns(2, |columns| {
|
|
|
|
columns[0].vertical_centered_justified(|ui| {
|
2024-05-29 22:47:17 +03:00
|
|
|
View::button(ui, t!("modal.cancel"), Colors::white_or_black(false), || {
|
2023-07-01 03:29:05 +03:00
|
|
|
cb.hide_keyboard();
|
|
|
|
modal.close();
|
|
|
|
});
|
|
|
|
});
|
2023-07-01 21:04:52 +03:00
|
|
|
columns[1].vertical_centered_justified(|ui| {
|
2024-05-29 22:47:17 +03:00
|
|
|
View::button(ui, t!("modal.save"), Colors::white_or_black(false), on_save);
|
2023-07-01 21:04:52 +03:00
|
|
|
});
|
2023-07-01 03:29:05 +03:00
|
|
|
});
|
2023-07-01 21:04:52 +03:00
|
|
|
ui.add_space(6.0);
|
2023-07-01 03:29:05 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
/// Draw API secret token setup content.
|
2023-08-03 04:11:25 +03:00
|
|
|
fn secret_ui(&mut self, modal_id: &'static str, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
2023-07-05 16:06:14 +03:00
|
|
|
let secret_title = match modal_id {
|
2023-08-03 04:11:25 +03:00
|
|
|
API_SECRET_MODAL => t!("network_settings.api_secret"),
|
2023-07-05 16:06:14 +03:00
|
|
|
_ => t!("network_settings.foreign_api_secret")
|
|
|
|
};
|
|
|
|
ui.label(RichText::new(secret_title)
|
|
|
|
.size(16.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::gray())
|
2023-07-05 16:06:14 +03:00
|
|
|
);
|
|
|
|
ui.add_space(6.0);
|
|
|
|
|
2023-07-01 03:29:05 +03:00
|
|
|
let secret_value = match modal_id {
|
2023-08-03 04:11:25 +03:00
|
|
|
API_SECRET_MODAL => NodeConfig::get_api_secret(),
|
2023-07-01 03:29:05 +03:00
|
|
|
_ => NodeConfig::get_foreign_api_secret()
|
|
|
|
};
|
|
|
|
|
|
|
|
let secret_text = if secret_value.is_some() {
|
2023-07-01 21:04:52 +03:00
|
|
|
format!("{} {}", SHIELD, t!("network_settings.enabled"))
|
2023-07-01 03:29:05 +03:00
|
|
|
} else {
|
2023-07-01 21:04:52 +03:00
|
|
|
format!("{} {}", SHIELD_SLASH, t!("network_settings.disabled"))
|
2023-07-01 03:29:05 +03:00
|
|
|
};
|
|
|
|
|
2024-05-29 22:47:17 +03:00
|
|
|
View::button(ui, secret_text, Colors::button(), || {
|
2023-07-01 03:29:05 +03:00
|
|
|
// Setup values for modal.
|
2023-07-11 03:02:44 +03:00
|
|
|
self.secret_edit = secret_value.unwrap_or("".to_string());
|
2023-07-01 03:29:05 +03:00
|
|
|
// Show secret edit modal.
|
2023-07-23 11:48:28 +03:00
|
|
|
Modal::new(modal_id)
|
2023-07-01 03:29:05 +03:00
|
|
|
.position(ModalPosition::CenterTop)
|
2023-07-23 11:48:28 +03:00
|
|
|
.title(t!("network_settings.change_value"))
|
|
|
|
.show();
|
2023-07-01 03:29:05 +03:00
|
|
|
cb.show_keyboard();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-20 23:53:55 +03:00
|
|
|
/// Draw API secret token [`Modal`] content.
|
2023-08-03 04:11:25 +03:00
|
|
|
fn secret_modal(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks) {
|
2023-07-01 03:29:05 +03:00
|
|
|
ui.add_space(6.0);
|
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
let description = match modal.id {
|
2023-08-03 04:11:25 +03:00
|
|
|
API_SECRET_MODAL => t!("network_settings.api_secret"),
|
2023-07-01 03:29:05 +03:00
|
|
|
_ => t!("network_settings.foreign_api_secret")
|
|
|
|
};
|
2024-05-29 22:47:17 +03:00
|
|
|
ui.label(RichText::new(description).size(17.0).color(Colors::gray()));
|
2023-07-15 22:37:34 +03:00
|
|
|
ui.add_space(8.0);
|
2023-11-08 01:00:56 +03:00
|
|
|
|
|
|
|
// Draw API secret token value text edit.
|
2024-05-21 13:31:46 +03:00
|
|
|
let mut secret_edit_opts = TextEditOptions::new(Id::from(modal.id)).copy().paste();
|
|
|
|
View::text_edit(ui, cb, &mut self.secret_edit, &mut secret_edit_opts);
|
2023-11-08 01:00:56 +03:00
|
|
|
ui.add_space(6.0);
|
2023-07-01 03:29:05 +03:00
|
|
|
|
2023-07-01 21:04:52 +03:00
|
|
|
// Show reminder to restart enabled node.
|
2023-07-15 21:13:37 +03:00
|
|
|
if Node::is_running() {
|
|
|
|
ui.label(RichText::new(t!("network_settings.restart_node_required"))
|
|
|
|
.size(16.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::green())
|
2023-07-15 21:13:37 +03:00
|
|
|
);
|
2023-11-08 01:00:56 +03:00
|
|
|
ui.add_space(6.0);
|
2023-07-15 21:13:37 +03:00
|
|
|
}
|
|
|
|
ui.add_space(4.0);
|
2023-07-01 21:04:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// Show modal buttons.
|
|
|
|
ui.scope(|ui| {
|
|
|
|
// Setup spacing between buttons.
|
2024-06-04 14:05:45 +03:00
|
|
|
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
|
2023-07-01 21:04:52 +03:00
|
|
|
|
|
|
|
// Save button callback.
|
|
|
|
let on_save = || {
|
2023-07-11 03:02:44 +03:00
|
|
|
let secret = self.secret_edit.clone();
|
2023-07-01 21:04:52 +03:00
|
|
|
match modal.id {
|
2023-08-03 04:11:25 +03:00
|
|
|
API_SECRET_MODAL => {
|
2023-07-11 03:02:44 +03:00
|
|
|
NodeConfig::save_api_secret(&secret);
|
2023-07-01 21:04:52 +03:00
|
|
|
}
|
|
|
|
_ => {
|
2023-07-11 03:02:44 +03:00
|
|
|
NodeConfig::save_foreign_api_secret(&secret);
|
2023-07-01 21:04:52 +03:00
|
|
|
}
|
2023-07-01 03:29:05 +03:00
|
|
|
};
|
2023-07-01 21:04:52 +03:00
|
|
|
cb.hide_keyboard();
|
|
|
|
modal.close();
|
|
|
|
};
|
2023-07-01 03:29:05 +03:00
|
|
|
|
2023-07-01 21:04:52 +03:00
|
|
|
ui.columns(2, |columns| {
|
|
|
|
columns[0].vertical_centered_justified(|ui| {
|
2024-05-29 22:47:17 +03:00
|
|
|
View::button(ui, t!("modal.cancel"), Colors::white_or_black(false), || {
|
2023-07-01 21:04:52 +03:00
|
|
|
cb.hide_keyboard();
|
|
|
|
modal.close();
|
2023-07-01 03:29:05 +03:00
|
|
|
});
|
|
|
|
});
|
2023-07-01 21:04:52 +03:00
|
|
|
columns[1].vertical_centered_justified(|ui| {
|
2024-05-29 22:47:17 +03:00
|
|
|
View::button(ui, t!("modal.save"), Colors::white_or_black(false), on_save);
|
2023-07-01 21:04:52 +03:00
|
|
|
});
|
2023-06-29 03:42:03 +03:00
|
|
|
});
|
2023-07-01 21:04:52 +03:00
|
|
|
ui.add_space(6.0);
|
2023-06-29 03:42:03 +03:00
|
|
|
});
|
|
|
|
}
|
2023-07-01 03:29:05 +03:00
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
/// Draw FTL setup content.
|
2023-08-03 04:11:25 +03:00
|
|
|
fn ftl_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
2023-07-05 16:06:14 +03:00
|
|
|
ui.label(RichText::new(t!("network_settings.ftl"))
|
|
|
|
.size(16.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::gray())
|
2023-07-05 16:06:14 +03:00
|
|
|
);
|
|
|
|
ui.add_space(6.0);
|
|
|
|
|
2023-07-01 03:29:05 +03:00
|
|
|
let ftl = NodeConfig::get_ftl();
|
2024-05-29 22:47:17 +03:00
|
|
|
View::button(ui, format!("{} {}", CLOCK_CLOCKWISE, ftl.clone()), Colors::button(), || {
|
2023-07-01 03:29:05 +03:00
|
|
|
// Setup values for modal.
|
|
|
|
self.ftl_edit = ftl;
|
2023-07-23 11:48:28 +03:00
|
|
|
// Show ftl value setup modal.
|
2023-08-03 04:11:25 +03:00
|
|
|
Modal::new(FTL_MODAL)
|
2023-07-01 03:29:05 +03:00
|
|
|
.position(ModalPosition::CenterTop)
|
2023-07-23 11:48:28 +03:00
|
|
|
.title(t!("network_settings.change_value"))
|
|
|
|
.show();
|
2023-07-01 03:29:05 +03:00
|
|
|
cb.show_keyboard();
|
|
|
|
});
|
|
|
|
ui.add_space(6.0);
|
|
|
|
ui.label(RichText::new(t!("network_settings.ftl_description"))
|
|
|
|
.size(16.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::inactive_text())
|
2023-07-01 03:29:05 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Draw FTL [`Modal`] content.
|
2023-08-03 04:11:25 +03:00
|
|
|
fn ftl_modal(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks) {
|
2023-07-01 03:29:05 +03:00
|
|
|
ui.add_space(6.0);
|
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
ui.label(RichText::new(t!("network_settings.ftl"))
|
2023-07-14 03:51:06 +03:00
|
|
|
.size(17.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::gray()));
|
2023-07-01 03:29:05 +03:00
|
|
|
ui.add_space(8.0);
|
|
|
|
|
2023-07-23 11:48:28 +03:00
|
|
|
// Draw ftl value text edit.
|
2024-05-21 13:31:46 +03:00
|
|
|
let mut ftl_edit_opts = TextEditOptions::new(Id::from(modal.id)).h_center();
|
|
|
|
View::text_edit(ui, cb, &mut self.ftl_edit, &mut ftl_edit_opts);
|
2023-07-01 03:29:05 +03:00
|
|
|
|
2023-07-01 21:04:52 +03:00
|
|
|
// Show error when specified value is not valid or reminder to restart enabled node.
|
2023-07-01 03:29:05 +03:00
|
|
|
if self.ftl_edit.parse::<u64>().is_err() {
|
|
|
|
ui.add_space(12.0);
|
|
|
|
ui.label(RichText::new(t!("network_settings.not_valid_value"))
|
2023-07-14 03:51:06 +03:00
|
|
|
.size(17.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::red()));
|
2023-07-01 21:04:52 +03:00
|
|
|
} else {
|
2023-07-04 00:39:13 +03:00
|
|
|
NetworkSettings::node_restart_required_ui(ui);
|
2023-07-01 03:29:05 +03:00
|
|
|
}
|
2023-07-01 21:04:52 +03:00
|
|
|
ui.add_space(12.0);
|
2023-07-01 03:29:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// Show modal buttons.
|
|
|
|
ui.scope(|ui| {
|
|
|
|
// Setup spacing between buttons.
|
|
|
|
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
|
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
// Save button callback.
|
2023-07-01 03:29:05 +03:00
|
|
|
let on_save = || {
|
|
|
|
if let Ok(ftl) = self.ftl_edit.parse::<u64>() {
|
|
|
|
NodeConfig::save_ftl(ftl);
|
|
|
|
cb.hide_keyboard();
|
|
|
|
modal.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ui.columns(2, |columns| {
|
|
|
|
columns[0].vertical_centered_justified(|ui| {
|
2024-05-29 22:47:17 +03:00
|
|
|
View::button(ui, t!("modal.cancel"), Colors::white_or_black(false), || {
|
2023-07-01 03:29:05 +03:00
|
|
|
// Close modal.
|
|
|
|
cb.hide_keyboard();
|
|
|
|
modal.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
columns[1].vertical_centered_justified(|ui| {
|
2024-05-29 22:47:17 +03:00
|
|
|
View::button(ui, t!("modal.save"), Colors::white_or_black(false), on_save);
|
2023-07-01 03:29:05 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
ui.add_space(6.0);
|
|
|
|
});
|
|
|
|
}
|
2023-07-01 21:04:52 +03:00
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
/// Draw chain validation mode setup content.
|
2023-08-03 04:11:25 +03:00
|
|
|
pub fn validation_mode_ui(&mut self, ui: &mut egui::Ui) {
|
2023-07-01 21:04:52 +03:00
|
|
|
let validate = NodeConfig::is_full_chain_validation();
|
|
|
|
View::checkbox(ui, validate, t!("network_settings.full_validation"), || {
|
|
|
|
NodeConfig::toggle_full_chain_validation();
|
|
|
|
});
|
2023-07-03 21:17:49 +03:00
|
|
|
ui.add_space(4.0);
|
2023-07-01 21:04:52 +03:00
|
|
|
ui.label(RichText::new(t!("network_settings.full_validation_description"))
|
|
|
|
.size(16.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::inactive_text())
|
2023-07-01 21:04:52 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-07-05 16:06:14 +03:00
|
|
|
/// Draw archive mode setup content.
|
2023-08-03 04:11:25 +03:00
|
|
|
fn archive_mode_ui(&mut self, ui: &mut egui::Ui) {
|
2023-07-01 21:04:52 +03:00
|
|
|
let archive_mode = NodeConfig::is_archive_mode();
|
|
|
|
View::checkbox(ui, archive_mode, t!("network_settings.archive_mode"), || {
|
|
|
|
NodeConfig::toggle_archive_mode();
|
|
|
|
});
|
2023-07-03 21:17:49 +03:00
|
|
|
ui.add_space(4.0);
|
2023-07-01 21:04:52 +03:00
|
|
|
ui.label(RichText::new(t!("network_settings.archive_mode_desc"))
|
|
|
|
.size(16.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::inactive_text())
|
2023-07-01 21:04:52 +03:00
|
|
|
);
|
|
|
|
}
|
2023-06-27 02:11:07 +03:00
|
|
|
}
|