mirror of
https://github.com/jwinterm/grim.git
synced 2026-10-24 08:28:33 +02:00
config + ui: config refactoring, stratum server launch, mining ui (without worker list yet)
This commit is contained in:
+25
-15
@@ -20,7 +20,7 @@ use egui_extras::{Size, StripBuilder};
|
||||
use grin_chain::SyncStatus;
|
||||
|
||||
use crate::gui::{Colors, Navigator};
|
||||
use crate::gui::icons::{CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE, POWER};
|
||||
use crate::gui::icons::{CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::network_metrics::NetworkMetrics;
|
||||
use crate::gui::views::network_mining::NetworkMining;
|
||||
@@ -32,7 +32,6 @@ use crate::Settings;
|
||||
|
||||
pub trait NetworkTab {
|
||||
fn get_type(&self) -> NetworkTabType;
|
||||
fn name(&self) -> String;
|
||||
fn ui(&mut self, ui: &mut egui::Ui);
|
||||
}
|
||||
|
||||
@@ -44,6 +43,17 @@ pub enum NetworkTabType {
|
||||
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>,
|
||||
}
|
||||
@@ -101,26 +111,22 @@ impl Network {
|
||||
|
||||
ui.columns(4, |columns| {
|
||||
columns[0].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, DATABASE,
|
||||
self.current_tab.get_type() == NetworkTabType::Node, || {
|
||||
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.current_tab.get_type() == NetworkTabType::Metrics, || {
|
||||
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.current_tab.get_type() == NetworkTabType::Mining, || {
|
||||
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.current_tab.get_type() == NetworkTabType::Settings, || {
|
||||
View::tab_button(ui, FADERS, self.is_current_tab(NetworkTabType::Settings), || {
|
||||
self.current_tab = Box::new(NetworkSettings::default());
|
||||
});
|
||||
});
|
||||
@@ -128,6 +134,10 @@ impl Network {
|
||||
});
|
||||
}
|
||||
|
||||
fn is_current_tab(&self, tab_type: NetworkTabType) -> bool {
|
||||
self.current_tab.get_type() == tab_type
|
||||
}
|
||||
|
||||
fn draw_title(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
StripBuilder::new(ui)
|
||||
.size(Size::exact(52.0))
|
||||
@@ -170,7 +180,7 @@ impl Network {
|
||||
strip.cell(|ui| {
|
||||
ui.add_space(2.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new(self.current_tab.name().to_uppercase())
|
||||
ui.label(RichText::new(self.current_tab.get_type().name().to_uppercase())
|
||||
.size(18.0)
|
||||
.color(Colors::TITLE));
|
||||
});
|
||||
@@ -217,15 +227,15 @@ impl Network {
|
||||
|
||||
ui.add_space(10.0);
|
||||
|
||||
View::button(ui, format!("{} {}", POWER, t!("network.enable")), Colors::GOLD, || {
|
||||
View::button(ui, t!("network.enable_node"), Colors::GOLD, || {
|
||||
Node::start();
|
||||
});
|
||||
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(2.0);
|
||||
|
||||
let autostart: bool = Settings::get_app_config().auto_start_node;
|
||||
let autostart: bool = Settings::app_config_to_read().auto_start_node;
|
||||
View::checkbox(ui, autostart, t!("network.autorun"), || {
|
||||
let mut w_app_config = Settings::get_app_config_to_update();
|
||||
let mut w_app_config = Settings::app_config_to_update();
|
||||
w_app_config.auto_start_node = !autostart;
|
||||
w_app_config.save();
|
||||
});
|
||||
|
||||
@@ -34,23 +34,19 @@ impl NetworkTab for NetworkMetrics {
|
||||
NetworkTabType::Metrics
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
t!("network.metrics")
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
let server_stats = Node::get_stats();
|
||||
// Show loading spinner when stats are not available or message when server is not enabled.
|
||||
// Show message when node is not running or loading spinner when metrics are not available.
|
||||
if server_stats.is_none() || server_stats.as_ref().unwrap().diff_stats.height == 0 {
|
||||
if !Node::is_running() {
|
||||
Network::disabled_server_content(ui);
|
||||
} else {
|
||||
View::center_content(ui, 160.0, |ui| {
|
||||
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::TEXT)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -88,7 +84,7 @@ impl NetworkTab for NetworkMetrics {
|
||||
[false, true, false, true]);
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(4.0);
|
||||
|
||||
// Show difficulty adjustment window info
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
@@ -119,7 +115,7 @@ impl NetworkTab for NetworkMetrics {
|
||||
[false, true, false, true]);
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(4.0);
|
||||
|
||||
// Show difficulty adjustment window blocks
|
||||
let blocks_size = stats.diff_stats.last_blocks.len();
|
||||
|
||||
@@ -12,9 +12,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use egui::RichText;
|
||||
use grin_chain::SyncStatus;
|
||||
|
||||
use crate::gui::Colors;
|
||||
use crate::gui::icons::{COMPUTER_TOWER, CPU, FADERS, POLYGON};
|
||||
use crate::gui::views::{Network, NetworkTab, NetworkTabType, View};
|
||||
use crate::node::Node;
|
||||
use crate::Settings;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct NetworkMining;
|
||||
@@ -24,25 +29,184 @@ impl NetworkTab for NetworkMining {
|
||||
NetworkTabType::Mining
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
t!("network.mining")
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
let server_stats = Node::get_stats();
|
||||
// Show loading spinner when stats are not available or message when server is not enabled.
|
||||
if !server_stats.is_some() {
|
||||
// Show message when node is not running or loading spinner when mining are not available.
|
||||
if !server_stats.is_some() || Node::get_sync_status().unwrap() != SyncStatus::NoSync {
|
||||
if !Node::is_running() {
|
||||
Network::disabled_server_content(ui);
|
||||
} else {
|
||||
ui.centered_and_justified(|ui| {
|
||||
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 stats = server_stats.as_ref().unwrap();
|
||||
// Stratum mining server address.
|
||||
let stratum_address = Settings::node_config_to_read()
|
||||
.members.clone()
|
||||
.server.stratum_mining_config.unwrap()
|
||||
.stratum_server_addr.unwrap();
|
||||
|
||||
let stratum_stats = &server_stats.as_ref().unwrap().stratum_stats;
|
||||
if !stratum_stats.is_running && !Node::is_stratum_server_starting() {
|
||||
// Show Stratum setup when mining server is not enabled.
|
||||
View::center_content(ui, 162.0, |ui| {
|
||||
let text = t!(
|
||||
"network_mining.disabled_server",
|
||||
"address" => stratum_address,
|
||||
"settings" => FADERS
|
||||
);
|
||||
ui.label(RichText::new(text)
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
|
||||
ui.add_space(10.0);
|
||||
|
||||
View::button(ui, t!("network_mining.enable_server"), Colors::GOLD, || {
|
||||
Node::start_stratum_server();
|
||||
});
|
||||
|
||||
ui.add_space(2.0);
|
||||
|
||||
// Check if stratum server is enabled at config
|
||||
let stratum_enabled = Settings::node_config_to_read()
|
||||
.members.clone()
|
||||
.server.stratum_mining_config.unwrap()
|
||||
.enable_stratum_server.unwrap();
|
||||
|
||||
View::checkbox(ui, stratum_enabled, t!("network.autorun"), || {
|
||||
let mut w_node_config = Settings::node_config_to_update();
|
||||
w_node_config.members
|
||||
.server.stratum_mining_config.as_mut().unwrap()
|
||||
.enable_stratum_server = Some(!stratum_enabled);
|
||||
w_node_config.save();
|
||||
});
|
||||
});
|
||||
return;
|
||||
} else if Node::is_stratum_server_starting() {
|
||||
// Show loading spinner when mining server is starting.
|
||||
View::center_content(ui, 162.0, |ui| {
|
||||
View::big_loading_spinner(ui);
|
||||
ui.add_space(18.0);
|
||||
ui.label(RichText::new(t!("network_mining.starting"))
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Show stratum mining server info.
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
View::sub_header(ui, format!("{} {}", COMPUTER_TOWER, t!("network_mining.server")));
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered(|ui| {
|
||||
View::rounded_box(ui,
|
||||
stratum_address,
|
||||
t!("network_mining.address"),
|
||||
[true, false, true, false]);
|
||||
});
|
||||
columns[1].vertical_centered(|ui| {
|
||||
// Stratum mining wallet address.
|
||||
let wallet_address = Settings::node_config_to_read()
|
||||
.members.clone()
|
||||
.server.stratum_mining_config.unwrap()
|
||||
.wallet_listener_url;
|
||||
View::rounded_box(ui,
|
||||
wallet_address,
|
||||
t!("network_mining.wallet"),
|
||||
[false, true, false, true]);
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
// Show network info.
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
View::sub_header(ui, format!("{} {}", POLYGON, t!("network.self")));
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
ui.columns(3, |columns| {
|
||||
columns[0].vertical_centered(|ui| {
|
||||
let difficulty = if stratum_stats.network_difficulty > 0 {
|
||||
stratum_stats.network_difficulty.to_string()
|
||||
} else {
|
||||
"-".into()
|
||||
};
|
||||
View::rounded_box(ui,
|
||||
difficulty,
|
||||
t!("network_node.difficulty"),
|
||||
[true, false, true, false]);
|
||||
});
|
||||
columns[1].vertical_centered(|ui| {
|
||||
let block_height = if stratum_stats.block_height > 0 {
|
||||
stratum_stats.block_height.to_string()
|
||||
} else {
|
||||
"-".into()
|
||||
};
|
||||
View::rounded_box(ui,
|
||||
block_height,
|
||||
t!("network_node.header"),
|
||||
[false, false, false, false]);
|
||||
});
|
||||
columns[2].vertical_centered(|ui| {
|
||||
let hashrate = if stratum_stats.network_hashrate > 0.0 {
|
||||
stratum_stats.network_hashrate.to_string()
|
||||
} else {
|
||||
"-".into()
|
||||
};
|
||||
View::rounded_box(ui,
|
||||
hashrate,
|
||||
t!("network_mining.hashrate"),
|
||||
[false, true, false, true]);
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
// Show mining info.
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
View::sub_header(ui, format!("{} {}", CPU, t!("network_mining.miners")));
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered(|ui| {
|
||||
View::rounded_box(ui,
|
||||
stratum_stats.num_workers.to_string(),
|
||||
t!("network_mining.devices"),
|
||||
[true, false, true, false]);
|
||||
});
|
||||
|
||||
columns[1].vertical_centered(|ui| {
|
||||
View::rounded_box(ui,
|
||||
stratum_stats.blocks_found.to_string(),
|
||||
t!("network_mining.blocks_found"),
|
||||
[false, true, false, true]);
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
// Show miners info.
|
||||
if !stratum_stats.worker_stats.is_empty() {
|
||||
//TODO: miners workers
|
||||
} else if ui.available_height() > 142.0 {
|
||||
View::center_content(ui, 142.0, |ui| {
|
||||
ui.label(RichText::new(t!("network_mining.info", "settings" => FADERS))
|
||||
.size(16.0)
|
||||
.color(Colors::INACTIVE_TEXT)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,16 +26,12 @@ pub struct NetworkNode;
|
||||
|
||||
impl NetworkTab for NetworkNode {
|
||||
fn get_type(&self) -> NetworkTabType {
|
||||
NetworkTabType::Metrics
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
t!("network.node")
|
||||
NetworkTabType::Node
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
let server_stats = Node::get_stats();
|
||||
// Show loading spinner when stats are not available or message when server is not enabled.
|
||||
// Show message when node is not running or loading spinner when stats are not available.
|
||||
if !server_stats.is_some() {
|
||||
if !Node::is_running() {
|
||||
Network::disabled_server_content(ui);
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use grin_core::global::ChainTypes;
|
||||
use crate::gui::views::{NetworkTab, NetworkTabType};
|
||||
use crate::Settings;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct NetworkSettings;
|
||||
@@ -22,11 +24,6 @@ impl NetworkTab for NetworkSettings {
|
||||
NetworkTabType::Settings
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
t!("network.settings")
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
|
||||
}
|
||||
}
|
||||
+5
-13
@@ -196,27 +196,19 @@ impl View {
|
||||
Spinner::new().size(48.0).color(Colors::GOLD).ui(ui);
|
||||
}
|
||||
|
||||
// let wt = RichText::new(text.to_uppercase()).size(18.0).color(Colors::BUTTON);
|
||||
// let br = Button::new(wt)
|
||||
// .stroke(Self::DEFAULT_STROKE)
|
||||
// .fill(fill_color)
|
||||
// .ui(ui).interact(Sense::click_and_drag());
|
||||
//
|
||||
// Self::on_button_click(ui, br, action);
|
||||
|
||||
/// Draw button that looks like checkbox with callback to change value.
|
||||
pub fn checkbox(ui: &mut egui::Ui, value: bool, text: String, cb: impl FnOnce()) {
|
||||
let text_value = match value {
|
||||
/// Draw the button that looks like checkbox with callback after change.
|
||||
pub fn checkbox(ui: &mut egui::Ui, checked: bool, text: String, callback: impl FnOnce()) {
|
||||
let text_value = match checked {
|
||||
true => { format!("{} {}", CHECK_SQUARE, text)}
|
||||
false => { format!("{} {}", SQUARE, text)}
|
||||
};
|
||||
let wt = RichText::new(text_value).size(18.0).color(Colors::BUTTON);
|
||||
let wt = RichText::new(text_value).size(19.0).color(Colors::BUTTON);
|
||||
let br = Button::new(wt)
|
||||
.frame(false)
|
||||
.stroke(Stroke::NONE)
|
||||
.fill(Colors::TRANSPARENT)
|
||||
.ui(ui).interact(Sense::click_and_drag());
|
||||
|
||||
Self::on_button_click(ui, br, cb);
|
||||
Self::on_button_click(ui, br, callback);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user