mirror of
https://github.com/jwinterm/grim.git
synced 2026-12-06 04:33:57 +01:00
node + config + ui: fork stratum server to handle state on node start/stop, complete stratum configuration, complete node server config, settings ui refactoring, update i18n lib
This commit is contained in:
+1
-1
@@ -38,7 +38,7 @@ impl App {
|
||||
egui::CentralPanel::default()
|
||||
.frame(egui::Frame {
|
||||
fill: Colors::FILL,
|
||||
.. Default::default()
|
||||
..Default::default()
|
||||
})
|
||||
.show(ctx, |ui| {
|
||||
self.root.ui(ui, frame, cb);
|
||||
|
||||
@@ -59,7 +59,7 @@ impl PlatformCallbacks for Android {
|
||||
}
|
||||
|
||||
fn get_string_from_buffer(&self) -> String {
|
||||
use jni::objects::{JObject, JValue, JString};
|
||||
use jni::objects::{JObject, JString};
|
||||
|
||||
let vm = unsafe { jni::JavaVM::from_raw(self.android_app.vm_as_ptr() as _) }.unwrap();
|
||||
let mut env = vm.attach_current_thread().unwrap();
|
||||
|
||||
@@ -17,12 +17,12 @@ use egui::RichText;
|
||||
use crate::gui::{App, Colors, Navigator};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::screens::{Account, Accounts, Screen, ScreenId};
|
||||
use crate::gui::views::{ModalContainer, Network, View};
|
||||
use crate::gui::views::{ModalContainer, NetworkContainer, View};
|
||||
use crate::node::Node;
|
||||
|
||||
pub struct Root {
|
||||
screens: Vec<Box<dyn Screen>>,
|
||||
network: Network,
|
||||
network_panel: NetworkContainer,
|
||||
show_exit_progress: bool,
|
||||
allowed_modal_ids: Vec<&'static str>
|
||||
}
|
||||
@@ -36,7 +36,7 @@ impl Default for Root {
|
||||
Box::new(Accounts::default()),
|
||||
Box::new(Account::default())
|
||||
],
|
||||
network: Network::default(),
|
||||
network_panel: NetworkContainer::default(),
|
||||
show_exit_progress: false,
|
||||
allowed_modal_ids: vec![
|
||||
Navigator::EXIT_MODAL
|
||||
@@ -65,7 +65,7 @@ impl Root {
|
||||
.exact_width(panel_width)
|
||||
.frame(egui::Frame::default())
|
||||
.show_animated_inside(ui, is_panel_open, |ui| {
|
||||
self.network.ui(ui, frame, cb);
|
||||
self.network_panel.ui(ui, frame, cb);
|
||||
});
|
||||
|
||||
egui::CentralPanel::default()
|
||||
|
||||
@@ -22,11 +22,4 @@ mod modal;
|
||||
pub use modal::*;
|
||||
|
||||
mod network;
|
||||
pub use network::*;
|
||||
|
||||
mod network_node;
|
||||
mod network_settings;
|
||||
mod network_metrics;
|
||||
mod network_mining;
|
||||
mod settings_stratum;
|
||||
mod settings_node;
|
||||
pub use network::*;
|
||||
@@ -126,7 +126,7 @@ impl Modal {
|
||||
|
||||
// Show main content Window at given position.
|
||||
let (content_align, content_offset) = self.modal_position();
|
||||
let layer_id = egui::Window::new("modal_window")
|
||||
let layer_id = egui::Window::new(format!("modal_window_{}", self.id))
|
||||
.title_bar(false)
|
||||
.resizable(false)
|
||||
.collapsible(false)
|
||||
@@ -152,12 +152,12 @@ impl Modal {
|
||||
/// Get [`egui::Window`] position based on [`ModalPosition`].
|
||||
fn modal_position(&self) -> (Align2, Vec2) {
|
||||
let align = match self.position {
|
||||
ModalPosition::CenterTop => { Align2::CENTER_TOP }
|
||||
ModalPosition::Center => { Align2::CENTER_CENTER }
|
||||
ModalPosition::CenterTop => Align2::CENTER_TOP,
|
||||
ModalPosition::Center => Align2::CENTER_CENTER
|
||||
};
|
||||
let offset = match self.position {
|
||||
ModalPosition::CenterTop => { Vec2::new(0.0, 20.0) }
|
||||
ModalPosition::Center => { Vec2::new(0.0, 0.0) }
|
||||
ModalPosition::CenterTop => Vec2::new(0.0, 20.0),
|
||||
ModalPosition::Center => Vec2::new(0.0, 0.0)
|
||||
};
|
||||
(align, offset)
|
||||
}
|
||||
|
||||
+7
-258
@@ -12,262 +12,11 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::time::Duration;
|
||||
mod container;
|
||||
mod metrics;
|
||||
mod mining;
|
||||
mod node_settings;
|
||||
mod node;
|
||||
mod settings;
|
||||
|
||||
use egui::{Color32, lerp, Rgba, RichText};
|
||||
use egui::style::Margin;
|
||||
use egui_extras::{Size, StripBuilder};
|
||||
use grin_chain::SyncStatus;
|
||||
use crate::AppConfig;
|
||||
|
||||
use crate::gui::{Colors, Navigator};
|
||||
use crate::gui::icons::{CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, ModalContainer, View};
|
||||
use crate::gui::views::network_metrics::NetworkMetrics;
|
||||
use crate::gui::views::network_mining::NetworkMining;
|
||||
use crate::gui::views::network_node::NetworkNode;
|
||||
use crate::gui::views::network_settings::NetworkSettings;
|
||||
use crate::gui::views::settings_node::NodeSetup;
|
||||
use crate::gui::views::settings_stratum::StratumServerSetup;
|
||||
use crate::node::Node;
|
||||
|
||||
pub trait NetworkTab {
|
||||
fn get_type(&self) -> NetworkTabType;
|
||||
fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks);
|
||||
fn on_modal_ui(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks);
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum NetworkTabType {
|
||||
Node,
|
||||
Metrics,
|
||||
Mining,
|
||||
Settings
|
||||
}
|
||||
|
||||
impl NetworkTabType {
|
||||
pub fn name(&self) -> String {
|
||||
match *self {
|
||||
NetworkTabType::Node => { t!("network.node") }
|
||||
NetworkTabType::Metrics => { t!("network.metrics") }
|
||||
NetworkTabType::Mining => { t!("network.mining") }
|
||||
NetworkTabType::Settings => { t!("network.settings") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Network {
|
||||
current_tab: Box<dyn NetworkTab>,
|
||||
modal_ids: Vec<&'static str>,
|
||||
}
|
||||
|
||||
impl Default for Network {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
current_tab: Box::new(NetworkNode::default()),
|
||||
modal_ids: vec![
|
||||
NetworkSettings::NODE_RESTART_REQUIRED_MODAL,
|
||||
StratumServerSetup::STRATUM_PORT_MODAL,
|
||||
NodeSetup::API_PORT_MODAL,
|
||||
NodeSetup::API_SECRET_MODAL,
|
||||
NodeSetup::FOREIGN_API_SECRET_MODAL,
|
||||
NodeSetup::FTL_MODAL
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ModalContainer for Network {
|
||||
fn modal_ids(&self) -> &Vec<&'static str> {
|
||||
self.modal_ids.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Network {
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
// Show modal content if it's opened.
|
||||
let modal_id = Navigator::is_modal_open();
|
||||
if modal_id.is_some() && self.can_show_modal(modal_id.unwrap()) {
|
||||
Navigator::modal_ui(ui, |ui, modal| {
|
||||
self.current_tab.as_mut().on_modal_ui(ui, modal, cb);
|
||||
});
|
||||
}
|
||||
|
||||
egui::TopBottomPanel::top("network_title")
|
||||
.resizable(false)
|
||||
.frame(egui::Frame {
|
||||
fill: Colors::YELLOW,
|
||||
inner_margin: Margin::same(0.0),
|
||||
outer_margin: Margin::same(0.0),
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
self.title_ui(ui, frame);
|
||||
});
|
||||
|
||||
egui::TopBottomPanel::bottom("network_tabs")
|
||||
.frame(egui::Frame {
|
||||
outer_margin: Margin::same(5.0),
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
self.tabs_ui(ui);
|
||||
});
|
||||
|
||||
egui::CentralPanel::default()
|
||||
.frame(egui::Frame {
|
||||
stroke: View::DEFAULT_STROKE,
|
||||
inner_margin: Margin::same(4.0),
|
||||
fill: Colors::WHITE,
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
self.current_tab.ui(ui, cb);
|
||||
});
|
||||
}
|
||||
|
||||
/// Draw tab buttons in the bottom of the screen.
|
||||
fn tabs_ui(&mut self, ui: &mut egui::Ui) {
|
||||
ui.scope(|ui| {
|
||||
// Setup spacing between tabs.
|
||||
ui.style_mut().spacing.item_spacing = egui::vec2(5.0, 0.0);
|
||||
// Setup vertical padding inside tab button.
|
||||
ui.style_mut().spacing.button_padding = egui::vec2(0.0, 3.0);
|
||||
|
||||
ui.columns(4, |columns| {
|
||||
columns[0].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, DATABASE, self.is_current_tab(NetworkTabType::Node), || {
|
||||
self.current_tab = Box::new(NetworkNode::default());
|
||||
});
|
||||
});
|
||||
columns[1].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, GAUGE, self.is_current_tab(NetworkTabType::Metrics), || {
|
||||
self.current_tab = Box::new(NetworkMetrics::default());
|
||||
});
|
||||
});
|
||||
columns[2].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, FACTORY, self.is_current_tab(NetworkTabType::Mining), || {
|
||||
self.current_tab = Box::new(NetworkMining::default());
|
||||
});
|
||||
});
|
||||
columns[3].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, FADERS, self.is_current_tab(NetworkTabType::Settings), || {
|
||||
self.current_tab = Box::new(NetworkSettings::default());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Check if current tab equals providing [`NetworkTabType`].
|
||||
fn is_current_tab(&self, tab_type: NetworkTabType) -> bool {
|
||||
self.current_tab.get_type() == tab_type
|
||||
}
|
||||
|
||||
/// Draw title content.
|
||||
fn title_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
StripBuilder::new(ui)
|
||||
.size(Size::exact(52.0))
|
||||
.vertical(|mut strip| {
|
||||
strip.strip(|builder| {
|
||||
builder
|
||||
.size(Size::exact(52.0))
|
||||
.size(Size::remainder())
|
||||
.size(Size::exact(52.0))
|
||||
.horizontal(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::title_button(ui, DOTS_THREE_OUTLINE_VERTICAL, || {
|
||||
//TODO: Actions for node
|
||||
});
|
||||
});
|
||||
});
|
||||
strip.strip(|builder| {
|
||||
self.title_text_ui(builder);
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
if !View::is_dual_panel_mode(frame) {
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::title_button(ui, CARDHOLDER, || {
|
||||
Navigator::toggle_side_panel();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Draw title text.
|
||||
fn title_text_ui(&self, builder: StripBuilder) {
|
||||
builder
|
||||
.size(Size::remainder())
|
||||
.size(Size::exact(32.0))
|
||||
.vertical(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
ui.add_space(2.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new(self.current_tab.get_type().name().to_uppercase())
|
||||
.size(18.0)
|
||||
.color(Colors::TITLE));
|
||||
});
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
ui.centered_and_justified(|ui| {
|
||||
let sync_status = Node::get_sync_status();
|
||||
|
||||
// Setup text color animation based on sync status
|
||||
let idle = match sync_status {
|
||||
None => !Node::is_starting(),
|
||||
Some(ss) => ss == SyncStatus::NoSync
|
||||
};
|
||||
let (dark, bright) = (0.3, 1.0);
|
||||
let color_factor = if !idle {
|
||||
lerp(dark..=bright, ui.input().time.cos().abs()) as f32
|
||||
} else {
|
||||
bright as f32
|
||||
};
|
||||
|
||||
// Draw sync text
|
||||
let status_color_rgba = Rgba::from(Colors::TEXT) * color_factor;
|
||||
let status_color = Color32::from(status_color_rgba);
|
||||
View::ellipsize_text(ui, Node::get_sync_status_text(), 15.0, status_color);
|
||||
|
||||
// Repaint based on sync status
|
||||
if idle {
|
||||
ui.ctx().request_repaint_after(Duration::from_millis(600));
|
||||
} else {
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Content to draw when node is disabled.
|
||||
pub fn disabled_node_ui(ui: &mut egui::Ui) {
|
||||
View::center_content(ui, 162.0, |ui| {
|
||||
let text = t!("network.disabled_server", "dots" => DOTS_THREE_OUTLINE_VERTICAL);
|
||||
ui.label(RichText::new(text)
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
ui.add_space(10.0);
|
||||
View::button(ui, t!("network.enable_node"), Colors::GOLD, || {
|
||||
Node::start();
|
||||
});
|
||||
ui.add_space(2.0);
|
||||
Self::autorun_node_ui(ui);
|
||||
});
|
||||
}
|
||||
|
||||
/// Draw checkbox with setting to run node on app launch.
|
||||
pub fn autorun_node_ui(ui: &mut egui::Ui) {
|
||||
let autostart = AppConfig::autostart_node();
|
||||
View::checkbox(ui, autostart, t!("network.autorun"), || {
|
||||
AppConfig::toggle_node_autostart();
|
||||
});
|
||||
}
|
||||
}
|
||||
pub use container::*;
|
||||
@@ -0,0 +1,275 @@
|
||||
// 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.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use egui::{Color32, lerp, Rgba, RichText};
|
||||
use egui::style::Margin;
|
||||
use egui_extras::{Size, StripBuilder};
|
||||
use grin_chain::SyncStatus;
|
||||
|
||||
use crate::AppConfig;
|
||||
use crate::gui::{Colors, Navigator};
|
||||
use crate::gui::icons::{CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, ModalContainer, View};
|
||||
use crate::gui::views::network::metrics::NetworkMetrics;
|
||||
use crate::gui::views::network::mining::NetworkMining;
|
||||
use crate::gui::views::network::node::NetworkNode;
|
||||
use crate::gui::views::network::node_settings::NetworkNodeSettings;
|
||||
use crate::gui::views::network::settings::server::ServerSetup;
|
||||
use crate::gui::views::network::settings::stratum::StratumServerSetup;
|
||||
use crate::node::Node;
|
||||
|
||||
pub trait NetworkTab {
|
||||
fn get_type(&self) -> NetworkTabType;
|
||||
fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks);
|
||||
fn on_modal_ui(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks);
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum NetworkTabType {
|
||||
Node,
|
||||
Metrics,
|
||||
Mining,
|
||||
Settings
|
||||
}
|
||||
|
||||
impl NetworkTabType {
|
||||
pub fn name(&self) -> String {
|
||||
match *self {
|
||||
NetworkTabType::Node => { t!("network.node") }
|
||||
NetworkTabType::Metrics => { t!("network.metrics") }
|
||||
NetworkTabType::Mining => { t!("network.mining") }
|
||||
NetworkTabType::Settings => { t!("network.settings") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NetworkContainer {
|
||||
current_tab: Box<dyn NetworkTab>,
|
||||
modal_ids: Vec<&'static str>,
|
||||
}
|
||||
|
||||
impl Default for NetworkContainer {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
current_tab: Box::new(NetworkNode::default()),
|
||||
modal_ids: vec![
|
||||
NetworkNodeSettings::NODE_RESTART_REQUIRED_MODAL,
|
||||
StratumServerSetup::STRATUM_PORT_MODAL,
|
||||
StratumServerSetup::STRATUM_ATTEMPT_TIME_MODAL,
|
||||
StratumServerSetup::STRATUM_MIN_SHARE_MODAL,
|
||||
ServerSetup::API_PORT_MODAL,
|
||||
ServerSetup::API_SECRET_MODAL,
|
||||
ServerSetup::FOREIGN_API_SECRET_MODAL,
|
||||
ServerSetup::FTL_MODAL
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ModalContainer for NetworkContainer {
|
||||
fn modal_ids(&self) -> &Vec<&'static str> {
|
||||
self.modal_ids.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkContainer {
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
// Show modal content if it's opened.
|
||||
let modal_id = Navigator::is_modal_open();
|
||||
if modal_id.is_some() && self.can_show_modal(modal_id.unwrap()) {
|
||||
Navigator::modal_ui(ui, |ui, modal| {
|
||||
self.current_tab.as_mut().on_modal_ui(ui, modal, cb);
|
||||
});
|
||||
}
|
||||
|
||||
egui::TopBottomPanel::top("network_title")
|
||||
.resizable(false)
|
||||
.frame(egui::Frame {
|
||||
fill: Colors::YELLOW,
|
||||
inner_margin: Margin::same(0.0),
|
||||
outer_margin: Margin::same(0.0),
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
self.title_ui(ui, frame);
|
||||
});
|
||||
|
||||
egui::TopBottomPanel::bottom("network_tabs")
|
||||
.frame(egui::Frame {
|
||||
outer_margin: Margin::same(5.0),
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
self.tabs_ui(ui);
|
||||
});
|
||||
|
||||
egui::CentralPanel::default()
|
||||
.frame(egui::Frame {
|
||||
stroke: View::DEFAULT_STROKE,
|
||||
inner_margin: Margin::same(4.0),
|
||||
fill: Colors::WHITE,
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
self.current_tab.ui(ui, cb);
|
||||
});
|
||||
}
|
||||
|
||||
/// Draw tab buttons in the bottom of the screen.
|
||||
fn tabs_ui(&mut self, ui: &mut egui::Ui) {
|
||||
ui.scope(|ui| {
|
||||
// Setup spacing between tabs.
|
||||
ui.style_mut().spacing.item_spacing = egui::vec2(5.0, 0.0);
|
||||
// Setup vertical padding inside tab button.
|
||||
ui.style_mut().spacing.button_padding = egui::vec2(0.0, 3.0);
|
||||
|
||||
ui.columns(4, |columns| {
|
||||
columns[0].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, DATABASE, self.is_current_tab(NetworkTabType::Node), || {
|
||||
self.current_tab = Box::new(NetworkNode::default());
|
||||
});
|
||||
});
|
||||
columns[1].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, GAUGE, self.is_current_tab(NetworkTabType::Metrics), || {
|
||||
self.current_tab = Box::new(NetworkMetrics::default());
|
||||
});
|
||||
});
|
||||
columns[2].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, FACTORY, self.is_current_tab(NetworkTabType::Mining), || {
|
||||
self.current_tab = Box::new(NetworkMining::default());
|
||||
});
|
||||
});
|
||||
columns[3].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, FADERS, self.is_current_tab(NetworkTabType::Settings), || {
|
||||
self.current_tab = Box::new(NetworkNodeSettings::default());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Check if current tab equals providing [`NetworkTabType`].
|
||||
fn is_current_tab(&self, tab_type: NetworkTabType) -> bool {
|
||||
self.current_tab.get_type() == tab_type
|
||||
}
|
||||
|
||||
/// Draw title content.
|
||||
fn title_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
StripBuilder::new(ui)
|
||||
.size(Size::exact(52.0))
|
||||
.vertical(|mut strip| {
|
||||
strip.strip(|builder| {
|
||||
builder
|
||||
.size(Size::exact(52.0))
|
||||
.size(Size::remainder())
|
||||
.size(Size::exact(52.0))
|
||||
.horizontal(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::title_button(ui, DOTS_THREE_OUTLINE_VERTICAL, || {
|
||||
//TODO: Actions for node
|
||||
});
|
||||
});
|
||||
});
|
||||
strip.strip(|builder| {
|
||||
self.title_text_ui(builder);
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
if !View::is_dual_panel_mode(frame) {
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::title_button(ui, CARDHOLDER, || {
|
||||
Navigator::toggle_side_panel();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Draw title text.
|
||||
fn title_text_ui(&self, builder: StripBuilder) {
|
||||
builder
|
||||
.size(Size::remainder())
|
||||
.size(Size::exact(32.0))
|
||||
.vertical(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
ui.add_space(2.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new(self.current_tab.get_type().name().to_uppercase())
|
||||
.size(18.0)
|
||||
.color(Colors::TITLE));
|
||||
});
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
ui.centered_and_justified(|ui| {
|
||||
let sync_status = Node::get_sync_status();
|
||||
|
||||
// Setup text color animation based on sync status
|
||||
let idle = match sync_status {
|
||||
None => !Node::is_starting(),
|
||||
Some(ss) => ss == SyncStatus::NoSync
|
||||
};
|
||||
let (dark, bright) = (0.3, 1.0);
|
||||
let color_factor = if !idle {
|
||||
lerp(dark..=bright, ui.input().time.cos().abs()) as f32
|
||||
} else {
|
||||
bright as f32
|
||||
};
|
||||
|
||||
// Draw sync text
|
||||
let status_color_rgba = Rgba::from(Colors::TEXT) * color_factor;
|
||||
let status_color = Color32::from(status_color_rgba);
|
||||
View::ellipsize_text(ui, Node::get_sync_status_text(), 15.0, status_color);
|
||||
|
||||
// Repaint based on sync status
|
||||
if idle {
|
||||
ui.ctx().request_repaint_after(Duration::from_millis(600));
|
||||
} else {
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Content to draw when node is disabled.
|
||||
pub fn disabled_node_ui(ui: &mut egui::Ui) {
|
||||
View::center_content(ui, 162.0, |ui| {
|
||||
let text = t!("network.disabled_server", "dots" => DOTS_THREE_OUTLINE_VERTICAL);
|
||||
ui.label(RichText::new(text)
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
ui.add_space(10.0);
|
||||
View::button(ui, t!("network.enable_node"), Colors::GOLD, || {
|
||||
Node::start();
|
||||
});
|
||||
ui.add_space(2.0);
|
||||
Self::autorun_node_ui(ui);
|
||||
});
|
||||
}
|
||||
|
||||
/// Draw checkbox with setting to run node on app launch.
|
||||
pub fn autorun_node_ui(ui: &mut egui::Ui) {
|
||||
let autostart = AppConfig::autostart_node();
|
||||
View::checkbox(ui, autostart, t!("network.autorun"), || {
|
||||
AppConfig::toggle_node_autostart();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,8 @@ use grin_servers::DiffBlock;
|
||||
use crate::gui::Colors;
|
||||
use crate::gui::icons::{AT, COINS, CUBE_TRANSPARENT, HASH, HOURGLASS_LOW, HOURGLASS_MEDIUM, TIMER};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, Network, NetworkTab, NetworkTabType, View};
|
||||
use crate::gui::views::network::{NetworkTab, NetworkTabType};
|
||||
use crate::gui::views::{Modal, NetworkContainer, View};
|
||||
use crate::node::Node;
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -36,23 +37,31 @@ impl NetworkTab for NetworkMetrics {
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
let server_stats = Node::get_stats();
|
||||
// Show message when node is not running or loading spinner when metrics are not available.
|
||||
// Show message to enable node when it's not running.
|
||||
if !Node::is_running() {
|
||||
NetworkContainer::disabled_node_ui(ui);
|
||||
return;
|
||||
}
|
||||
|
||||
// Show loading spinner when node is stopping.
|
||||
if Node::is_stopping() {
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::big_loading_spinner(ui);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Show message when metrics are not available.
|
||||
if server_stats.is_none() || Node::is_restarting()
|
||||
|| server_stats.as_ref().unwrap().diff_stats.height == 0 {
|
||||
if !Node::is_running() {
|
||||
Network::disabled_node_ui(ui);
|
||||
} else {
|
||||
View::center_content(ui, 162.0, |ui| {
|
||||
View::big_loading_spinner(ui);
|
||||
if !Node::is_stopping() {
|
||||
ui.add_space(18.0);
|
||||
ui.label(RichText::new(t!("network_metrics.loading"))
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
View::center_content(ui, 162.0, |ui| {
|
||||
View::big_loading_spinner(ui);
|
||||
ui.add_space(18.0);
|
||||
ui.label(RichText::new(t!("network_metrics.loading"))
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,9 @@ use grin_servers::WorkerStats;
|
||||
use crate::gui::Colors;
|
||||
use crate::gui::icons::{BARBELL, CLOCK_AFTERNOON, COMPUTER_TOWER, CPU, CUBE, FADERS, FOLDER_DASHED, FOLDER_NOTCH_MINUS, FOLDER_NOTCH_PLUS, PLUGS, PLUGS_CONNECTED, POLYGON};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, Network, NetworkTab, NetworkTabType, View};
|
||||
use crate::gui::views::settings_stratum::StratumServerSetup;
|
||||
use crate::gui::views::{Modal, NetworkContainer, View};
|
||||
use crate::gui::views::network::{NetworkTab, NetworkTabType};
|
||||
use crate::gui::views::network::settings::stratum::StratumServerSetup;
|
||||
use crate::node::{Node, NodeConfig};
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -37,69 +38,47 @@ impl NetworkTab for NetworkMining {
|
||||
fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
let server_stats = Node::get_stats();
|
||||
|
||||
// Show message when node is not running or loading spinner when mining is not available.
|
||||
if !server_stats.is_some() || Node::get_sync_status().unwrap() != SyncStatus::NoSync {
|
||||
if !Node::is_running() {
|
||||
Network::disabled_node_ui(ui);
|
||||
} else {
|
||||
View::center_content(ui, 162.0, |ui| {
|
||||
View::big_loading_spinner(ui);
|
||||
if !Node::is_stopping() {
|
||||
ui.add_space(18.0);
|
||||
ui.label(RichText::new(t!("network_mining.loading"))
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Show message to enable node when it's not running.
|
||||
if !Node::is_running() {
|
||||
NetworkContainer::disabled_node_ui(ui);
|
||||
return;
|
||||
}
|
||||
|
||||
let stratum_stats = &server_stats.as_ref().unwrap().stratum_stats;
|
||||
|
||||
// Show stratum server setup when mining server is not running.
|
||||
if !stratum_stats.is_running && !Node::is_stratum_server_starting() {
|
||||
ScrollArea::vertical()
|
||||
.id_source("stratum_server_setup")
|
||||
.auto_shrink([false; 2])
|
||||
.show(ui, |ui| {
|
||||
self.stratum_server_setup.ui(ui, cb);
|
||||
|
||||
ui.vertical_centered(|ui| {
|
||||
// Show message about stratum server config.
|
||||
let text = t!("network_mining.server_setting", "settings" => FADERS);
|
||||
ui.label(RichText::new(text)
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
ui.add_space(4.0);
|
||||
|
||||
// Show button to enable stratum server if port is available.
|
||||
if self.stratum_server_setup.is_port_available {
|
||||
ui.add_space(6.0);
|
||||
View::button(ui, t!("network_mining.enable_server"), Colors::GOLD, || {
|
||||
Node::start_stratum_server();
|
||||
});
|
||||
ui.add_space(2.0);
|
||||
|
||||
// Show stratum server autorun checkbox.
|
||||
let stratum_enabled = NodeConfig::is_stratum_autorun_enabled();
|
||||
View::checkbox(ui, stratum_enabled, t!("network.autorun"), || {
|
||||
NodeConfig::toggle_stratum_autorun();
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
}
|
||||
});
|
||||
});
|
||||
return;
|
||||
} else if Node::is_stratum_server_starting() {
|
||||
// Show loading spinner when node is stopping or stratum server is starting.
|
||||
if Node::is_stopping() || Node::is_stratum_server_starting() {
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::big_loading_spinner(ui);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Show message when mining is not available.
|
||||
if server_stats.is_none() || Node::is_restarting()
|
||||
|| Node::get_sync_status().unwrap() != SyncStatus::NoSync {
|
||||
View::center_content(ui, 162.0, |ui| {
|
||||
View::big_loading_spinner(ui);
|
||||
ui.add_space(18.0);
|
||||
ui.label(RichText::new(t!("network_mining.loading"))
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let stratum_stats = Node::get_stratum_stats();
|
||||
|
||||
// Show stratum server setup when mining server is not running.
|
||||
if !stratum_stats.is_running {
|
||||
ScrollArea::vertical()
|
||||
.id_source("stratum_setup_scroll")
|
||||
.auto_shrink([false; 2])
|
||||
.show(ui, |ui| {
|
||||
self.stratum_server_setup.ui(ui, cb);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Show stratum mining server info.
|
||||
View::sub_title(ui, format!("{} {}", COMPUTER_TOWER, t!("network_mining.server")));
|
||||
ui.columns(2, |columns| {
|
||||
@@ -221,7 +200,7 @@ impl NetworkTab for NetworkMining {
|
||||
fn on_modal_ui(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks) {
|
||||
match modal.id {
|
||||
StratumServerSetup::STRATUM_PORT_MODAL => {
|
||||
self.stratum_server_setup.stratum_port_modal_ui(ui, modal, cb);
|
||||
self.stratum_server_setup.port_modal(ui, modal, cb);
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
@@ -19,7 +19,8 @@ use grin_servers::PeerStats;
|
||||
use crate::gui::Colors;
|
||||
use crate::gui::icons::{AT, CUBE, DEVICES, FLOW_ARROW, HANDSHAKE, PACKAGE, PLUGS_CONNECTED, SHARE_NETWORK};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, Network, NetworkTab, NetworkTabType, View};
|
||||
use crate::gui::views::{Modal, View};
|
||||
use crate::gui::views::network::{NetworkContainer, NetworkTab, NetworkTabType};
|
||||
use crate::node::Node;
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -32,15 +33,17 @@ impl NetworkTab for NetworkNode {
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
let server_stats = Node::get_stats();
|
||||
// Show message when node is not running or loading spinner when stats are not available.
|
||||
if !server_stats.is_some() || Node::is_restarting() {
|
||||
if !Node::is_running() {
|
||||
Network::disabled_node_ui(ui);
|
||||
} else {
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::big_loading_spinner(ui);
|
||||
});
|
||||
}
|
||||
// Show message to enable node when it's not running.
|
||||
if !Node::is_running() {
|
||||
NetworkContainer::disabled_node_ui(ui);
|
||||
return;
|
||||
}
|
||||
|
||||
// Show loading spinner when stats are not available.
|
||||
if server_stats.is_none() || Node::is_restarting() || Node::is_stopping() {
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::big_loading_spinner(ui);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -19,16 +19,19 @@ use egui::{RichText, ScrollArea};
|
||||
|
||||
use crate::gui::{Colors, Navigator};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, ModalPosition, NetworkTab, NetworkTabType, View};
|
||||
use crate::gui::views::settings_node::NodeSetup;
|
||||
use crate::gui::views::{Modal, ModalPosition, View};
|
||||
use crate::gui::views::network::{NetworkTab, NetworkTabType};
|
||||
use crate::gui::views::network::settings::server::ServerSetup;
|
||||
use crate::gui::views::network::settings::stratum::StratumServerSetup;
|
||||
use crate::node::Node;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct NetworkSettings {
|
||||
node_setup: NodeSetup
|
||||
pub struct NetworkNodeSettings {
|
||||
server_setup: ServerSetup,
|
||||
stratum_server_setup: StratumServerSetup
|
||||
}
|
||||
|
||||
impl NetworkTab for NetworkSettings {
|
||||
impl NetworkTab for NetworkNodeSettings {
|
||||
fn get_type(&self) -> NetworkTabType {
|
||||
NetworkTabType::Settings
|
||||
}
|
||||
@@ -38,7 +41,8 @@ impl NetworkTab for NetworkSettings {
|
||||
.id_source("network_settings")
|
||||
.auto_shrink([false; 2])
|
||||
.show(ui, |ui| {
|
||||
self.node_setup.ui(ui, cb);
|
||||
self.server_setup.ui(ui, cb);
|
||||
self.stratum_server_setup.ui(ui, cb);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -47,24 +51,35 @@ impl NetworkTab for NetworkSettings {
|
||||
Self::NODE_RESTART_REQUIRED_MODAL => {
|
||||
self.node_restart_required_modal(ui, modal);
|
||||
}
|
||||
NodeSetup::API_PORT_MODAL => {
|
||||
self.node_setup.api_port_modal(ui, modal, cb);
|
||||
|
||||
ServerSetup::API_PORT_MODAL => {
|
||||
self.server_setup.api_port_modal(ui, modal, cb);
|
||||
},
|
||||
NodeSetup::API_SECRET_MODAL => {
|
||||
self.node_setup.secret_modal(ui, modal, cb);
|
||||
ServerSetup::API_SECRET_MODAL => {
|
||||
self.server_setup.secret_modal(ui, modal, cb);
|
||||
},
|
||||
NodeSetup::FOREIGN_API_SECRET_MODAL => {
|
||||
self.node_setup.secret_modal(ui, modal, cb);
|
||||
ServerSetup::FOREIGN_API_SECRET_MODAL => {
|
||||
self.server_setup.secret_modal(ui, modal, cb);
|
||||
},
|
||||
NodeSetup::FTL_MODAL => {
|
||||
self.node_setup.ftl_modal(ui, modal, cb);
|
||||
ServerSetup::FTL_MODAL => {
|
||||
self.server_setup.ftl_modal(ui, modal, cb);
|
||||
},
|
||||
|
||||
StratumServerSetup::STRATUM_PORT_MODAL => {
|
||||
self.stratum_server_setup.port_modal(ui, modal, cb);
|
||||
}
|
||||
StratumServerSetup::STRATUM_ATTEMPT_TIME_MODAL => {
|
||||
self.stratum_server_setup.attempt_modal(ui, modal, cb);
|
||||
}
|
||||
StratumServerSetup::STRATUM_MIN_SHARE_MODAL => {
|
||||
self.stratum_server_setup.min_diff_modal(ui, modal, cb);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkSettings {
|
||||
impl NetworkNodeSettings {
|
||||
pub const NODE_RESTART_REQUIRED_MODAL: &'static str = "node_restart_required";
|
||||
|
||||
/// Reminder to restart enabled node to show on edit setting at [`Modal`].
|
||||
@@ -82,7 +97,7 @@ impl NetworkSettings {
|
||||
pub fn show_node_restart_required_modal() {
|
||||
if Node::is_running() {
|
||||
// Show modal to apply changes by node restart.
|
||||
let port_modal = Modal::new(NetworkSettings::NODE_RESTART_REQUIRED_MODAL)
|
||||
let port_modal = Modal::new(NetworkNodeSettings::NODE_RESTART_REQUIRED_MODAL)
|
||||
.position(ModalPosition::Center)
|
||||
.title(t!("network.settings"));
|
||||
Navigator::show_modal(port_modal);
|
||||
@@ -121,19 +136,6 @@ impl NetworkSettings {
|
||||
});
|
||||
}
|
||||
|
||||
/// List of available IP addresses.
|
||||
pub fn get_ip_addrs() -> Vec<IpAddr> {
|
||||
let mut ip_addrs = Vec::new();
|
||||
for net_if in pnet::datalink::interfaces() {
|
||||
for ip in net_if.ips {
|
||||
if ip.is_ipv4() {
|
||||
ip_addrs.push(ip.ip());
|
||||
}
|
||||
}
|
||||
}
|
||||
ip_addrs
|
||||
}
|
||||
|
||||
/// Draw IP addresses as radio buttons.
|
||||
pub fn ip_addrs_ui(ui: &mut egui::Ui,
|
||||
saved_ip: &String,
|
||||
@@ -147,6 +149,7 @@ impl NetworkSettings {
|
||||
selected_ip_addr = ip_addrs.get(0).unwrap();
|
||||
}
|
||||
|
||||
ui.add_space(2.0);
|
||||
// Show available IP addresses on the system.
|
||||
let _ = ip_addrs.chunks(2).map(|x| {
|
||||
if x.len() == 2 {
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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.
|
||||
|
||||
pub mod stratum;
|
||||
pub mod server;
|
||||
pub mod p2p;
|
||||
pub mod pool;
|
||||
pub mod dandelion;
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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.
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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.
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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.
|
||||
|
||||
@@ -15,16 +15,17 @@
|
||||
use eframe::emath::Align;
|
||||
use egui::{Id, Layout, RichText, TextStyle, Widget};
|
||||
use grin_core::global::ChainTypes;
|
||||
|
||||
use crate::AppConfig;
|
||||
use crate::gui::{Colors, Navigator};
|
||||
use crate::gui::icons::{CLIPBOARD_TEXT, COMPUTER_TOWER, COPY, POWER, SHIELD, SHIELD_SLASH};
|
||||
use crate::gui::icons::{CLIPBOARD_TEXT, CLOCK_CLOCKWISE, COMPUTER_TOWER, COPY, PLUG, POWER, SHIELD, SHIELD_SLASH};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, ModalPosition, Network, View};
|
||||
use crate::gui::views::network_settings::NetworkSettings;
|
||||
use crate::gui::views::{Modal, ModalPosition, NetworkContainer, View};
|
||||
use crate::gui::views::network::node_settings::NetworkNodeSettings;
|
||||
use crate::node::{Node, NodeConfig};
|
||||
|
||||
/// Integrated node server setup ui section.
|
||||
pub struct NodeSetup {
|
||||
pub struct ServerSetup {
|
||||
/// API port to be used inside edit modal.
|
||||
api_port_edit: String,
|
||||
/// Flag to check if API port is available inside edit modal.
|
||||
@@ -43,7 +44,7 @@ pub struct NodeSetup {
|
||||
ftl_edit: String,
|
||||
}
|
||||
|
||||
impl Default for NodeSetup {
|
||||
impl Default for ServerSetup {
|
||||
fn default() -> Self {
|
||||
let (api_ip, api_port) = NodeConfig::get_api_address();
|
||||
let is_api_port_available = NodeConfig::is_api_port_available(&api_ip, &api_port);
|
||||
@@ -58,7 +59,7 @@ impl Default for NodeSetup {
|
||||
}
|
||||
}
|
||||
|
||||
impl NodeSetup {
|
||||
impl ServerSetup {
|
||||
pub const API_PORT_MODAL: &'static str = "api_port";
|
||||
pub const API_SECRET_MODAL: &'static str = "api_secret";
|
||||
pub const FOREIGN_API_SECRET_MODAL: &'static str = "foreign_api_secret";
|
||||
@@ -67,7 +68,7 @@ impl NodeSetup {
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
View::sub_title(ui, format!("{} {}", COMPUTER_TOWER, t!("network_settings.server")));
|
||||
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(4.0);
|
||||
|
||||
// Show chain type setup.
|
||||
self.chain_type_ui(ui);
|
||||
@@ -75,8 +76,9 @@ impl NodeSetup {
|
||||
// Show loading indicator or controls to stop/start/restart node.
|
||||
if Node::is_stopping() || Node::is_restarting() || Node::is_starting() {
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(8.0);
|
||||
View::small_loading_spinner(ui);
|
||||
ui.add_space(2.0);
|
||||
});
|
||||
} else {
|
||||
if Node::is_running() {
|
||||
@@ -110,21 +112,29 @@ impl NodeSetup {
|
||||
}
|
||||
|
||||
// Autorun node setup.
|
||||
ui.add_space(4.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
Network::autorun_node_ui(ui);
|
||||
ui.add_space(6.0);
|
||||
NetworkContainer::autorun_node_ui(ui);
|
||||
if Node::is_running() {
|
||||
ui.add_space(2.0);
|
||||
ui.label(RichText::new(t!("network_settings.restart_node_required"))
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
ui.add_space(4.0);
|
||||
}
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(6.0);
|
||||
|
||||
let addrs = NetworkSettings::get_ip_addrs();
|
||||
let addrs = NodeConfig::get_ip_addrs();
|
||||
if addrs.is_empty() {
|
||||
// Show message when IP addresses are not available on the system.
|
||||
NetworkSettings::no_ip_address_ui(ui);
|
||||
NetworkNodeSettings::no_ip_address_ui(ui);
|
||||
|
||||
ui.add_space(4.0);
|
||||
} else {
|
||||
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(6.0);
|
||||
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new(t!("network_settings.api_ip"))
|
||||
@@ -132,15 +142,13 @@ impl NodeSetup {
|
||||
.color(Colors::GRAY)
|
||||
);
|
||||
ui.add_space(6.0);
|
||||
|
||||
// Show API IP addresses to select.
|
||||
let (api_ip, api_port) = NodeConfig::get_api_address();
|
||||
NetworkSettings::ip_addrs_ui(ui, &api_ip, &addrs, |selected_ip| {
|
||||
NetworkNodeSettings::ip_addrs_ui(ui, &api_ip, &addrs, |selected_ip| {
|
||||
let api_available = NodeConfig::is_api_port_available(selected_ip, &api_port);
|
||||
self.is_api_port_available = api_available;
|
||||
NodeConfig::save_api_address(selected_ip, &api_port);
|
||||
if api_available {
|
||||
NetworkSettings::show_node_restart_required_modal();
|
||||
}
|
||||
});
|
||||
|
||||
ui.label(RichText::new(t!("network_settings.api_port"))
|
||||
@@ -209,6 +217,7 @@ impl NodeSetup {
|
||||
let saved_chain_type = AppConfig::chain_type();
|
||||
let mut selected_chain_type = saved_chain_type;
|
||||
|
||||
ui.add_space(8.0);
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered(|ui| {
|
||||
let main_type = ChainTypes::Mainnet;
|
||||
@@ -219,19 +228,18 @@ impl NodeSetup {
|
||||
View::radio_value(ui, &mut selected_chain_type, test_type, "Testnet".to_string());
|
||||
})
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(8.0);
|
||||
|
||||
if saved_chain_type != selected_chain_type {
|
||||
AppConfig::change_chain_type(&selected_chain_type);
|
||||
NetworkSettings::show_node_restart_required_modal();
|
||||
NetworkNodeSettings::show_node_restart_required_modal();
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw API port setup ui.
|
||||
fn api_port_setup_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
let (_, port) = NodeConfig::get_api_address();
|
||||
// Show button to enter API server port.
|
||||
View::button(ui, port.clone(), Colors::BUTTON, || {
|
||||
View::button(ui, format!("{} {}", PLUG, port.clone()), Colors::BUTTON, || {
|
||||
// Setup values for modal.
|
||||
self.api_port_edit = port;
|
||||
self.api_port_available_edit = self.is_api_port_available;
|
||||
@@ -285,7 +293,7 @@ impl NodeSetup {
|
||||
.size(16.0)
|
||||
.color(Colors::RED));
|
||||
} else {
|
||||
NetworkSettings::node_restart_required_ui(ui);
|
||||
NetworkNodeSettings::node_restart_required_ui(ui);
|
||||
}
|
||||
ui.add_space(12.0);
|
||||
});
|
||||
@@ -329,7 +337,6 @@ impl NodeSetup {
|
||||
|
||||
/// Draw API secret token setup ui.
|
||||
fn secret_ui(&mut self, modal_id: &'static str, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
// Setup values for modal
|
||||
let secret_value = match modal_id {
|
||||
Self::API_SECRET_MODAL => NodeConfig::get_api_secret(),
|
||||
_ => NodeConfig::get_foreign_api_secret()
|
||||
@@ -341,7 +348,6 @@ impl NodeSetup {
|
||||
format!("{} {}", SHIELD_SLASH, t!("network_settings.disabled"))
|
||||
};
|
||||
|
||||
// Show button to open secret modal.
|
||||
View::button(ui, secret_text, Colors::BUTTON, || {
|
||||
// Setup values for modal.
|
||||
match modal_id {
|
||||
@@ -428,7 +434,7 @@ impl NodeSetup {
|
||||
});
|
||||
|
||||
// Show reminder to restart enabled node.
|
||||
NetworkSettings::node_restart_required_ui(ui);
|
||||
NetworkNodeSettings::node_restart_required_ui(ui);
|
||||
|
||||
ui.add_space(12.0);
|
||||
});
|
||||
@@ -472,8 +478,7 @@ impl NodeSetup {
|
||||
/// Draw FTL setup ui.
|
||||
fn ftl_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
let ftl = NodeConfig::get_ftl();
|
||||
// Show button to enter FTL value.
|
||||
View::button(ui, ftl.clone(), Colors::BUTTON, || {
|
||||
View::button(ui, format!("{} {}", CLOCK_CLOCKWISE, ftl.clone()), Colors::BUTTON, || {
|
||||
// Setup values for modal.
|
||||
self.ftl_edit = ftl;
|
||||
// Show stratum port modal.
|
||||
@@ -519,7 +524,7 @@ impl NodeSetup {
|
||||
.size(18.0)
|
||||
.color(Colors::RED));
|
||||
} else {
|
||||
NetworkSettings::node_restart_required_ui(ui);
|
||||
NetworkNodeSettings::node_restart_required_ui(ui);
|
||||
}
|
||||
ui.add_space(12.0);
|
||||
});
|
||||
@@ -559,9 +564,9 @@ impl NodeSetup {
|
||||
let validate = NodeConfig::is_full_chain_validation();
|
||||
View::checkbox(ui, validate, t!("network_settings.full_validation"), || {
|
||||
NodeConfig::toggle_full_chain_validation();
|
||||
NetworkSettings::show_node_restart_required_modal();
|
||||
NetworkNodeSettings::show_node_restart_required_modal();
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(4.0);
|
||||
ui.label(RichText::new(t!("network_settings.full_validation_description"))
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
@@ -573,9 +578,9 @@ impl NodeSetup {
|
||||
let archive_mode = NodeConfig::is_archive_mode();
|
||||
View::checkbox(ui, archive_mode, t!("network_settings.archive_mode"), || {
|
||||
NodeConfig::toggle_archive_mode();
|
||||
NetworkSettings::show_node_restart_required_modal();
|
||||
NetworkNodeSettings::show_node_restart_required_modal();
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(4.0);
|
||||
ui.label(RichText::new(t!("network_settings.archive_mode_desc"))
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
@@ -0,0 +1,413 @@
|
||||
// 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.
|
||||
|
||||
use egui::{Id, RichText, TextStyle, Widget};
|
||||
|
||||
use crate::gui::{Colors, Navigator};
|
||||
use crate::gui::icons::{BARBELL, HARD_DRIVES, PLUG, TIMER};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, ModalPosition, View};
|
||||
use crate::gui::views::network::node_settings::NetworkNodeSettings;
|
||||
use crate::node::{Node, NodeConfig};
|
||||
|
||||
/// Stratum server setup ui section.
|
||||
pub struct StratumServerSetup {
|
||||
/// Stratum port value to be used inside edit modal.
|
||||
stratum_port_edit: String,
|
||||
/// Flag to check if stratum port is available inside edit modal.
|
||||
stratum_port_available_edit: bool,
|
||||
|
||||
/// Flag to check if stratum port is available from saved config value.
|
||||
pub(crate) is_port_available: bool,
|
||||
|
||||
/// Attempt time value to be used inside edit modal.
|
||||
attempt_time_edit: String,
|
||||
|
||||
/// Minimum share difficulty value to be used inside edit modal.
|
||||
min_share_diff_edit: String
|
||||
}
|
||||
|
||||
impl Default for StratumServerSetup {
|
||||
fn default() -> Self {
|
||||
let (ip, port) = NodeConfig::get_stratum_address();
|
||||
let is_port_available = NodeConfig::is_stratum_port_available(&ip, &port);
|
||||
let attempt_time = NodeConfig::get_stratum_attempt_time();
|
||||
let min_share_diff = NodeConfig::get_stratum_min_share_diff();
|
||||
Self {
|
||||
stratum_port_edit: port,
|
||||
stratum_port_available_edit: is_port_available,
|
||||
is_port_available,
|
||||
attempt_time_edit: attempt_time,
|
||||
min_share_diff_edit: min_share_diff
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StratumServerSetup {
|
||||
/// Identifier for stratum port [`Modal`].
|
||||
pub const STRATUM_PORT_MODAL: &'static str = "stratum_port";
|
||||
/// Identifier for attempt time [`Modal`].
|
||||
pub const STRATUM_ATTEMPT_TIME_MODAL: &'static str = "stratum_attempt_time";
|
||||
/// Identifier for minimum share difficulty [`Modal`].
|
||||
pub const STRATUM_MIN_SHARE_MODAL: &'static str = "stratum_min_share";
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
View::sub_title(ui, format!("{} {}", HARD_DRIVES, t!("network_mining.server_setup")));
|
||||
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||
ui.add_space(6.0);
|
||||
|
||||
ui.vertical_centered(|ui| {
|
||||
// Show button to enable stratum server if port is available and server is not running.
|
||||
if self.is_port_available && !Node::is_stratum_server_starting() && Node::is_running()
|
||||
&& !Node::get_stratum_stats().is_running {
|
||||
ui.add_space(6.0);
|
||||
View::button(ui, t!("network_mining.enable_server"), Colors::GOLD, || {
|
||||
Node::start_stratum_server();
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
}
|
||||
|
||||
// Show stratum server autorun checkbox.
|
||||
let stratum_enabled = NodeConfig::is_stratum_autorun_enabled();
|
||||
View::checkbox(ui, stratum_enabled, t!("network.autorun"), || {
|
||||
NodeConfig::toggle_stratum_autorun();
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
// Show message to restart node after changing of stratum settings
|
||||
ui.label(RichText::new(t!("network_mining.info_settings"))
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
ui.add_space(8.0);
|
||||
});
|
||||
|
||||
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||
ui.add_space(6.0);
|
||||
|
||||
// Show message when IP addresses are not available on the system.
|
||||
let all_ips = NodeConfig::get_ip_addrs();
|
||||
if all_ips.is_empty() {
|
||||
NetworkNodeSettings::no_ip_address_ui(ui);
|
||||
return;
|
||||
}
|
||||
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new(t!("network_settings.ip"))
|
||||
.size(16.0)
|
||||
.color(Colors::GRAY)
|
||||
);
|
||||
ui.add_space(6.0);
|
||||
// Show stratum IP addresses to select.
|
||||
let (ip, port) = NodeConfig::get_stratum_address();
|
||||
NetworkNodeSettings::ip_addrs_ui(ui, &ip, &all_ips, |selected_ip| {
|
||||
NodeConfig::save_stratum_address(selected_ip, &port);
|
||||
self.is_port_available = NodeConfig::is_stratum_port_available(selected_ip, &port);
|
||||
|
||||
});
|
||||
// Show stratum port setup.
|
||||
self.port_setup_ui(ui, cb);
|
||||
|
||||
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||
ui.add_space(6.0);
|
||||
|
||||
// Show attempt time setup.
|
||||
self.attempt_time_ui(ui, cb);
|
||||
|
||||
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||
ui.add_space(6.0);
|
||||
|
||||
// Show minimum acceptable share difficulty setup.
|
||||
self.min_diff_ui(ui, cb);
|
||||
});
|
||||
}
|
||||
|
||||
/// Draw stratum port value setup ui.
|
||||
fn port_setup_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
ui.label(RichText::new(t!("network_settings.port"))
|
||||
.size(16.0)
|
||||
.color(Colors::GRAY)
|
||||
);
|
||||
ui.add_space(6.0);
|
||||
|
||||
let (_, port) = NodeConfig::get_stratum_address();
|
||||
View::button(ui, format!("{} {}", PLUG, port.clone()), Colors::BUTTON, || {
|
||||
// Setup values for modal.
|
||||
self.stratum_port_edit = port;
|
||||
self.stratum_port_available_edit = self.is_port_available;
|
||||
// Show stratum port modal.
|
||||
let port_modal = Modal::new(Self::STRATUM_PORT_MODAL)
|
||||
.position(ModalPosition::CenterTop)
|
||||
.title(t!("network_settings.change_value"));
|
||||
Navigator::show_modal(port_modal);
|
||||
cb.show_keyboard();
|
||||
});
|
||||
ui.add_space(12.0);
|
||||
|
||||
// Show error when stratum server port is unavailable.
|
||||
if !self.is_port_available {
|
||||
ui.add_space(6.0);
|
||||
ui.label(RichText::new(t!("network_settings.port_unavailable"))
|
||||
.size(16.0)
|
||||
.color(Colors::RED));
|
||||
ui.add_space(12.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw stratum port [`Modal`] content ui.
|
||||
pub fn port_modal(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks) {
|
||||
ui.add_space(6.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new(t!("network_settings.stratum_port"))
|
||||
.size(18.0)
|
||||
.color(Colors::GRAY));
|
||||
ui.add_space(8.0);
|
||||
|
||||
// Draw stratum port text edit.
|
||||
let text_edit_resp = egui::TextEdit::singleline(&mut self.stratum_port_edit)
|
||||
.id(Id::from(modal.id))
|
||||
.font(TextStyle::Heading)
|
||||
.desired_width(58.0)
|
||||
.cursor_at_end(true)
|
||||
.ui(ui);
|
||||
text_edit_resp.request_focus();
|
||||
if text_edit_resp.clicked() {
|
||||
cb.show_keyboard();
|
||||
}
|
||||
|
||||
// Show error when specified port is unavailable.
|
||||
if !self.stratum_port_available_edit {
|
||||
ui.add_space(12.0);
|
||||
ui.label(RichText::new(t!("network_settings.port_unavailable"))
|
||||
.size(18.0)
|
||||
.color(Colors::RED));
|
||||
}
|
||||
|
||||
ui.add_space(12.0);
|
||||
|
||||
// Show modal buttons.
|
||||
ui.scope(|ui| {
|
||||
// Setup spacing between buttons.
|
||||
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
|
||||
|
||||
// Save button callback
|
||||
let on_save = || {
|
||||
// Check if port is available.
|
||||
let (stratum_ip, _) = NodeConfig::get_stratum_address();
|
||||
let available = NodeConfig::is_stratum_port_available(
|
||||
&stratum_ip,
|
||||
&self.stratum_port_edit
|
||||
);
|
||||
self.stratum_port_available_edit = available;
|
||||
|
||||
// Save port at config if it's available.
|
||||
if available {
|
||||
NodeConfig::save_stratum_address(&stratum_ip, &self.stratum_port_edit);
|
||||
|
||||
self.is_port_available = true;
|
||||
cb.hide_keyboard();
|
||||
modal.close();
|
||||
}
|
||||
};
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered_justified(|ui| {
|
||||
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
|
||||
// Close modal.
|
||||
cb.hide_keyboard();
|
||||
modal.close();
|
||||
});
|
||||
});
|
||||
columns[1].vertical_centered_justified(|ui| {
|
||||
View::button(ui, t!("modal.save"), Colors::WHITE, on_save);
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Draw attempt time value setup ui.
|
||||
fn attempt_time_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
ui.label(RichText::new(t!("network_settings.attempt_time_desc"))
|
||||
.size(16.0)
|
||||
.color(Colors::GRAY)
|
||||
);
|
||||
ui.add_space(6.0);
|
||||
|
||||
let time = NodeConfig::get_stratum_attempt_time();
|
||||
View::button(ui, format!("{} {}", TIMER, time.clone()), Colors::BUTTON, || {
|
||||
// Setup values for modal.
|
||||
self.attempt_time_edit = time;
|
||||
|
||||
// Show attempt time modal.
|
||||
let time_modal = Modal::new(Self::STRATUM_ATTEMPT_TIME_MODAL)
|
||||
.position(ModalPosition::CenterTop)
|
||||
.title(t!("network_settings.change_value"));
|
||||
Navigator::show_modal(time_modal);
|
||||
cb.show_keyboard();
|
||||
});
|
||||
ui.add_space(12.0);
|
||||
}
|
||||
|
||||
/// Draw attempt time [`Modal`] content ui.
|
||||
pub fn attempt_modal(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks) {
|
||||
ui.add_space(6.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new(t!("network_settings.attempt_time"))
|
||||
.size(18.0)
|
||||
.color(Colors::GRAY));
|
||||
ui.add_space(8.0);
|
||||
|
||||
// Draw stratum port text edit.
|
||||
let text_edit_resp = egui::TextEdit::singleline(&mut self.attempt_time_edit)
|
||||
.id(Id::from(modal.id))
|
||||
.font(TextStyle::Heading)
|
||||
.desired_width(34.0)
|
||||
.cursor_at_end(true)
|
||||
.ui(ui);
|
||||
text_edit_resp.request_focus();
|
||||
if text_edit_resp.clicked() {
|
||||
cb.show_keyboard();
|
||||
}
|
||||
|
||||
// Show error when specified value is not valid or reminder to restart enabled node.
|
||||
if self.attempt_time_edit.parse::<u32>().is_err() {
|
||||
ui.add_space(12.0);
|
||||
ui.label(RichText::new(t!("network_settings.not_valid_value"))
|
||||
.size(18.0)
|
||||
.color(Colors::RED));
|
||||
} else {
|
||||
NetworkNodeSettings::node_restart_required_ui(ui);
|
||||
}
|
||||
ui.add_space(12.0);
|
||||
});
|
||||
|
||||
// Show modal buttons.
|
||||
ui.scope(|ui| {
|
||||
// Setup spacing between buttons.
|
||||
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
|
||||
|
||||
// Save button callback
|
||||
let on_save = || {
|
||||
if let Ok(time) = self.attempt_time_edit.parse::<u32>() {
|
||||
NodeConfig::save_stratum_attempt_time(time);
|
||||
cb.hide_keyboard();
|
||||
modal.close();
|
||||
}
|
||||
};
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered_justified(|ui| {
|
||||
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
|
||||
// Close modal.
|
||||
cb.hide_keyboard();
|
||||
modal.close();
|
||||
});
|
||||
});
|
||||
columns[1].vertical_centered_justified(|ui| {
|
||||
View::button(ui, t!("modal.save"), Colors::WHITE, on_save);
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
});
|
||||
}
|
||||
|
||||
/// Draw minimum share difficulty value setup ui.
|
||||
fn min_diff_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
ui.label(RichText::new(t!("network_settings.min_share_diff"))
|
||||
.size(16.0)
|
||||
.color(Colors::GRAY)
|
||||
);
|
||||
ui.add_space(6.0);
|
||||
|
||||
let diff = NodeConfig::get_stratum_min_share_diff();
|
||||
View::button(ui, format!("{} {}", BARBELL, diff.clone()), Colors::BUTTON, || {
|
||||
// Setup values for modal.
|
||||
self.min_share_diff_edit = diff;
|
||||
|
||||
// Show attempt time modal.
|
||||
let diff_modal = Modal::new(Self::STRATUM_MIN_SHARE_MODAL)
|
||||
.position(ModalPosition::CenterTop)
|
||||
.title(t!("network_settings.change_value"));
|
||||
Navigator::show_modal(diff_modal);
|
||||
cb.show_keyboard();
|
||||
});
|
||||
ui.add_space(12.0);
|
||||
}
|
||||
|
||||
/// Draw minimum acceptable share difficulty [`Modal`] content ui.
|
||||
pub fn min_diff_modal(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks) {
|
||||
ui.add_space(6.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new(t!("network_settings.min_share_diff"))
|
||||
.size(18.0)
|
||||
.color(Colors::GRAY));
|
||||
ui.add_space(8.0);
|
||||
|
||||
// Draw stratum port text edit.
|
||||
let text_edit_resp = egui::TextEdit::singleline(&mut self.min_share_diff_edit)
|
||||
.id(Id::from(modal.id))
|
||||
.font(TextStyle::Heading)
|
||||
.desired_width(34.0)
|
||||
.cursor_at_end(true)
|
||||
.ui(ui);
|
||||
text_edit_resp.request_focus();
|
||||
if text_edit_resp.clicked() {
|
||||
cb.show_keyboard();
|
||||
}
|
||||
|
||||
// Show error when specified value is not valid or reminder to restart enabled node.
|
||||
if self.min_share_diff_edit.parse::<u64>().is_err() {
|
||||
ui.add_space(12.0);
|
||||
ui.label(RichText::new(t!("network_settings.not_valid_value"))
|
||||
.size(18.0)
|
||||
.color(Colors::RED));
|
||||
} else {
|
||||
NetworkNodeSettings::node_restart_required_ui(ui);
|
||||
}
|
||||
ui.add_space(12.0);
|
||||
});
|
||||
|
||||
// Show modal buttons.
|
||||
ui.scope(|ui| {
|
||||
// Setup spacing between buttons.
|
||||
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
|
||||
|
||||
// Save button callback
|
||||
let on_save = || {
|
||||
if let Ok(diff) = self.min_share_diff_edit.parse::<u64>() {
|
||||
NodeConfig::save_stratum_min_share_diff(diff);
|
||||
cb.hide_keyboard();
|
||||
modal.close();
|
||||
}
|
||||
};
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered_justified(|ui| {
|
||||
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
|
||||
// Close modal.
|
||||
cb.hide_keyboard();
|
||||
modal.close();
|
||||
});
|
||||
});
|
||||
columns[1].vertical_centered_justified(|ui| {
|
||||
View::button(ui, t!("modal.save"), Colors::WHITE, on_save);
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
// 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.
|
||||
|
||||
use egui::{RichText, TextStyle, Widget};
|
||||
|
||||
use crate::gui::{Colors, Navigator};
|
||||
use crate::gui::icons::WRENCH;
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, ModalPosition, View};
|
||||
use crate::gui::views::network_settings::NetworkSettings;
|
||||
use crate::node::NodeConfig;
|
||||
|
||||
/// Stratum server setup ui section.
|
||||
pub struct StratumServerSetup {
|
||||
/// Stratum port to be used inside edit modal.
|
||||
stratum_port_edit: String,
|
||||
/// Flag to check if stratum port is available inside edit modal.
|
||||
stratum_port_available_edit: bool,
|
||||
|
||||
/// Flag to check if stratum port is available from saved config value.
|
||||
pub(crate) is_port_available: bool
|
||||
}
|
||||
|
||||
impl Default for StratumServerSetup {
|
||||
fn default() -> Self {
|
||||
let (ip, port) = NodeConfig::get_stratum_address();
|
||||
let is_port_available = NodeConfig::is_stratum_port_available(&ip, &port);
|
||||
Self {
|
||||
stratum_port_edit: port,
|
||||
stratum_port_available_edit: is_port_available,
|
||||
is_port_available
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StratumServerSetup {
|
||||
/// Identifier for stratum port [`Modal`].
|
||||
pub const STRATUM_PORT_MODAL: &'static str = "stratum_port";
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
View::sub_title(ui, format!("{} {}", WRENCH, t!("network_mining.server_setup")));
|
||||
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||
ui.add_space(4.0);
|
||||
|
||||
// Show message when IP addresses are not available on the system.
|
||||
let all_ips = NetworkSettings::get_ip_addrs();
|
||||
if all_ips.is_empty() {
|
||||
NetworkSettings::no_ip_address_ui(ui);
|
||||
return;
|
||||
}
|
||||
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new(t!("network_settings.ip"))
|
||||
.size(16.0)
|
||||
.color(Colors::GRAY)
|
||||
);
|
||||
ui.add_space(6.0);
|
||||
// Show stratum IP addresses to select.
|
||||
let (ip, port) = NodeConfig::get_stratum_address();
|
||||
NetworkSettings::ip_addrs_ui(ui, &ip, &all_ips, |selected_ip| {
|
||||
self.is_port_available = NodeConfig::is_stratum_port_available(selected_ip, &port);
|
||||
NodeConfig::save_stratum_address(selected_ip, &port);
|
||||
});
|
||||
|
||||
ui.label(RichText::new(t!("network_settings.port"))
|
||||
.size(16.0)
|
||||
.color(Colors::GRAY)
|
||||
);
|
||||
ui.add_space(6.0);
|
||||
// Show stratum port setup.
|
||||
self.port_setup_ui(ui, cb);
|
||||
|
||||
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||
ui.add_space(6.0);
|
||||
});
|
||||
}
|
||||
|
||||
/// Draw stratum port setup ui.
|
||||
fn port_setup_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
|
||||
let (_, port) = NodeConfig::get_stratum_address();
|
||||
// Show button to enter stratum server port.
|
||||
View::button(ui, port.clone(), Colors::BUTTON, || {
|
||||
// Setup values for modal.
|
||||
self.stratum_port_edit = port;
|
||||
self.stratum_port_available_edit = self.is_port_available;
|
||||
// Show stratum port modal.
|
||||
let port_modal = Modal::new(Self::STRATUM_PORT_MODAL)
|
||||
.position(ModalPosition::CenterTop)
|
||||
.title(t!("network_settings.change_value"));
|
||||
Navigator::show_modal(port_modal);
|
||||
cb.show_keyboard();
|
||||
});
|
||||
ui.add_space(14.0);
|
||||
|
||||
// Show error when stratum server port is unavailable.
|
||||
if !self.is_port_available {
|
||||
ui.label(RichText::new(t!("network_settings.port_unavailable"))
|
||||
.size(16.0)
|
||||
.color(Colors::RED));
|
||||
ui.add_space(12.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw stratum port [`Modal`] content ui.
|
||||
pub fn stratum_port_modal_ui(&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
modal: &Modal,
|
||||
cb: &dyn PlatformCallbacks) {
|
||||
ui.add_space(6.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new(t!("network_settings.stratum_port"))
|
||||
.size(18.0)
|
||||
.color(Colors::GRAY));
|
||||
ui.add_space(8.0);
|
||||
|
||||
// Draw stratum port text edit.
|
||||
let text_edit_resp = egui::TextEdit::singleline(&mut self.stratum_port_edit)
|
||||
.font(TextStyle::Heading)
|
||||
.desired_width(58.0)
|
||||
.cursor_at_end(true)
|
||||
.ui(ui);
|
||||
text_edit_resp.request_focus();
|
||||
if text_edit_resp.clicked() {
|
||||
cb.show_keyboard();
|
||||
}
|
||||
|
||||
// Show error when specified port is unavailable.
|
||||
if !self.stratum_port_available_edit {
|
||||
ui.add_space(12.0);
|
||||
ui.label(RichText::new(t!("network_settings.port_unavailable"))
|
||||
.size(18.0)
|
||||
.color(Colors::RED));
|
||||
}
|
||||
|
||||
ui.add_space(12.0);
|
||||
|
||||
// Show modal buttons.
|
||||
ui.scope(|ui| {
|
||||
// Setup spacing between buttons.
|
||||
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
|
||||
|
||||
// Save button callback
|
||||
let on_save = || {
|
||||
// Check if port is available.
|
||||
let (stratum_ip, _) = NodeConfig::get_stratum_address();
|
||||
let available = NodeConfig::is_stratum_port_available(
|
||||
&stratum_ip,
|
||||
&self.stratum_port_edit
|
||||
);
|
||||
self.stratum_port_available_edit = available;
|
||||
|
||||
// Save port at config if it's available.
|
||||
if available {
|
||||
NodeConfig::save_stratum_address(&stratum_ip, &self.stratum_port_edit);
|
||||
|
||||
self.is_port_available = true;
|
||||
cb.hide_keyboard();
|
||||
modal.close();
|
||||
}
|
||||
};
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered_justified(|ui| {
|
||||
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
|
||||
// Close modal.
|
||||
cb.hide_keyboard();
|
||||
modal.close();
|
||||
});
|
||||
});
|
||||
columns[1].vertical_centered_justified(|ui| {
|
||||
View::button(ui, t!("modal.save"), Colors::WHITE, on_save);
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,13 @@ use egui_extras::{Size, StripBuilder};
|
||||
use crate::gui::Colors;
|
||||
use crate::gui::views::View;
|
||||
|
||||
pub struct TitlePanelAction<'action> {
|
||||
pub(crate) icon: Box<&'action str>,
|
||||
pub struct TitlePanelAction {
|
||||
pub(crate) icon: Box<&'static str>,
|
||||
pub(crate) on_click: Box<dyn Fn()>,
|
||||
}
|
||||
|
||||
impl<'action> TitlePanelAction<'action> {
|
||||
pub fn new(icon: &'action str, on_click: fn()) -> Option<Self> {
|
||||
impl TitlePanelAction {
|
||||
pub fn new(icon: &'static str, on_click: fn()) -> Option<Self> {
|
||||
Option::from(Self { icon: Box::new(icon), on_click: Box::new(on_click) })
|
||||
}
|
||||
}
|
||||
|
||||
+12
-11
@@ -17,7 +17,7 @@ use egui::epaint::{Color32, FontId, RectShape, Rounding, Stroke};
|
||||
use egui::epaint::text::TextWrapping;
|
||||
use egui::text::{LayoutJob, TextFormat};
|
||||
|
||||
use crate::gui::{Colors, Navigator};
|
||||
use crate::gui::Colors;
|
||||
use crate::gui::icons::{CHECK_SQUARE, SQUARE};
|
||||
|
||||
pub struct View;
|
||||
@@ -93,16 +93,16 @@ impl View {
|
||||
/// Tab button with white background fill color, contains only icon.
|
||||
pub fn tab_button(ui: &mut egui::Ui, icon: &str, active: bool, action: impl FnOnce()) {
|
||||
let text_color = match active {
|
||||
true => { Colors::TITLE }
|
||||
false => { Colors::TEXT }
|
||||
true => Colors::TITLE,
|
||||
false => Colors::TEXT
|
||||
};
|
||||
let stroke = match active {
|
||||
true => { Stroke::NONE }
|
||||
false => { Self::DEFAULT_STROKE }
|
||||
true => Stroke::NONE,
|
||||
false => Self::DEFAULT_STROKE
|
||||
};
|
||||
let color = match active {
|
||||
true => { Colors::FILL }
|
||||
false => { Colors::WHITE }
|
||||
true => Colors::FILL,
|
||||
false => Colors::WHITE
|
||||
};
|
||||
let br = Button::new(RichText::new(icon.to_string()).size(24.0).color(text_color))
|
||||
.stroke(stroke)
|
||||
@@ -115,7 +115,8 @@ impl View {
|
||||
|
||||
/// Draw [`Button`] with specified background fill color.
|
||||
pub fn button(ui: &mut egui::Ui, text: String, fill_color: Color32, action: impl FnOnce()) {
|
||||
let br = Button::new(RichText::new(text.to_uppercase()).size(18.0).color(Colors::TEXT_BUTTON))
|
||||
let button_text = RichText::new(text.to_uppercase()).size(18.0).color(Colors::TEXT_BUTTON);
|
||||
let br = Button::new(button_text)
|
||||
.stroke(Self::DEFAULT_STROKE)
|
||||
.fill(fill_color)
|
||||
.ui(ui);
|
||||
@@ -201,14 +202,14 @@ impl View {
|
||||
|
||||
/// Draw small gold loading spinner.
|
||||
pub fn small_loading_spinner(ui: &mut egui::Ui) {
|
||||
Spinner::new().size(42.0).color(Colors::GOLD).ui(ui);
|
||||
Spinner::new().size(38.0).color(Colors::GOLD).ui(ui);
|
||||
}
|
||||
|
||||
/// Draw the button that looks like checkbox with callback on check.
|
||||
pub fn checkbox(ui: &mut egui::Ui, checked: bool, text: String, callback: impl FnOnce()) {
|
||||
let (text_value, color) = match checked {
|
||||
true => { (format!("{} {}", CHECK_SQUARE, text), Colors::TEXT_BUTTON) }
|
||||
false => { (format!("{} {}", SQUARE, text), Colors::TEXT) }
|
||||
true => (format!("{} {}", CHECK_SQUARE, text), Colors::TEXT_BUTTON),
|
||||
false => (format!("{} {}", SQUARE, text), Colors::TEXT)
|
||||
};
|
||||
|
||||
let br = Button::new(RichText::new(text_value).size(18.0).color(color))
|
||||
|
||||
Reference in New Issue
Block a user