ui: stratum wallet selection button, fix de i18n, modal padding, rename connection

This commit is contained in:
ardocrat 2024-07-10 20:58:05 +03:00
parent f142ae110a
commit 383d733c2a
12 changed files with 93 additions and 21 deletions

View file

@ -23,8 +23,8 @@ scan_result: Scan Ergebnis
back: zurück back: zurück
share: teilen share: teilen
theme: 'Theme:' theme: 'Theme:'
dark: dunkel dark: Dunkel
light: hell light: Hell
choose_file: Datei auswählen choose_file: Datei auswählen
wallets: wallets:
await_conf_amount: Erwarte Bestätigung await_conf_amount: Erwarte Bestätigung
@ -146,7 +146,7 @@ transport:
network: network:
self: Netzwerk self: Netzwerk
type: 'Netzwerk Typ:' type: 'Netzwerk Typ:'
mainnet: Haupt mainnet: Main
testnet: Test testnet: Test
connections: Verbindungen connections: Verbindungen
node: Integrierte Node node: Integrierte Node
@ -226,6 +226,7 @@ network_settings:
stratum_port: 'Stratum Port:' stratum_port: 'Stratum Port:'
port_unavailable: Der angegebene Port ist nicht verfügbar port_unavailable: Der angegebene Port ist nicht verfügbar
restart_node_required: Ein Neustart der Node ist erforderlich, um die Änderungen zu übernehmen. restart_node_required: Ein Neustart der Node ist erforderlich, um die Änderungen zu übernehmen.
choose_wallet: Wählen Wallet
enable: Aktivieren enable: Aktivieren
disable: Deaktivieren disable: Deaktivieren
restart: Neustarten restart: Neustarten

View file

@ -226,6 +226,7 @@ network_settings:
stratum_port: 'Stratum port:' stratum_port: 'Stratum port:'
port_unavailable: Specified port is unavailable port_unavailable: Specified port is unavailable
restart_node_required: Node restart is required to apply changes. restart_node_required: Node restart is required to apply changes.
choose_wallet: Choose wallet
enable: Enable enable: Enable
disable: Disable disable: Disable
restart: Restart restart: Restart

View file

@ -226,6 +226,7 @@ network_settings:
stratum_port: 'Port Stratum :' stratum_port: 'Port Stratum :'
port_unavailable: Le port spécifié est indisponible port_unavailable: Le port spécifié est indisponible
restart_node_required: Le redémarrage du noeud est nécessaire pour appliquer les modifications. restart_node_required: Le redémarrage du noeud est nécessaire pour appliquer les modifications.
choose_wallet: Choisir un portefeuille
enable: Activer enable: Activer
disable: Désactiver disable: Désactiver
restart: Redémarrer restart: Redémarrer

View file

@ -226,6 +226,7 @@ network_settings:
stratum_port: 'Порт Stratum:' stratum_port: 'Порт Stratum:'
port_unavailable: Указанный порт недоступен port_unavailable: Указанный порт недоступен
restart_node_required: Для применения изменений требуется перезапуск узла. restart_node_required: Для применения изменений требуется перезапуск узла.
choose_wallet: Выбрать кошелёк
enable: Включить enable: Включить
disable: Выключить disable: Выключить
restart: Перезапуск restart: Перезапуск

View file

@ -226,6 +226,7 @@ network_settings:
stratum_port: 'Stratum port:' stratum_port: 'Stratum port:'
port_unavailable: Belirlenen port mevcut degil port_unavailable: Belirlenen port mevcut degil
restart_node_required: Degisiklikler için yeniden Node BASLAT restart_node_required: Degisiklikler için yeniden Node BASLAT
choose_wallet: Cüzdan seç
enable: Etkinlestir enable: Etkinlestir
disable: Devredisi birak disable: Devredisi birak
restart: Restart restart: Restart

View file

@ -319,24 +319,19 @@ impl Modal {
// Draw title content. // Draw title content.
let title_resp = ui.allocate_ui_at_rect(rect, |ui| { let title_resp = ui.allocate_ui_at_rect(rect, |ui| {
ui.vertical_centered_justified(|ui| { ui.vertical_centered_justified(|ui| {
ui.add_space(Self::DEFAULT_MARGIN + if !View::is_desktop() { ui.add_space(Self::DEFAULT_MARGIN + 1.0);
1.0
} else {
0.0
});
ui.label(RichText::new(self.title.as_ref().unwrap()) ui.label(RichText::new(self.title.as_ref().unwrap())
.size(19.0) .size(19.0)
.color(Colors::title(true)) .color(Colors::title(true))
); );
ui.add_space(Self::DEFAULT_MARGIN); ui.add_space(Self::DEFAULT_MARGIN);
// Draw line below title.
View::horizontal_line(ui, Colors::item_stroke());
}); });
}).response; }).response;
// Setup background shape to be painted behind title content. // Setup background shape to be painted behind title content.
bg_shape.rect = title_resp.rect; bg_shape.rect = title_resp.rect;
ui.painter().set(bg_idx, bg_shape); ui.painter().set(bg_idx, bg_shape);
// Draw line below title.
View::horizontal_line(ui, Colors::stroke());
} }
} }

View file

@ -24,17 +24,27 @@ use crate::gui::views::{NetworkContent, Content, View};
use crate::gui::views::network::setup::StratumSetup; use crate::gui::views::network::setup::StratumSetup;
use crate::gui::views::network::types::{NetworkTab, NetworkTabType}; use crate::gui::views::network::types::{NetworkTab, NetworkTabType};
use crate::node::{Node, NodeConfig}; use crate::node::{Node, NodeConfig};
use crate::wallet::WalletConfig;
/// Mining tab content. /// Mining tab content.
pub struct NetworkMining { pub struct NetworkMining {
/// Stratum server setup content. /// Stratum server setup content.
stratum_server_setup: StratumSetup, stratum_server_setup: StratumSetup,
/// Wallet name for rewards.
wallet_name: String,
} }
impl Default for NetworkMining { impl Default for NetworkMining {
fn default() -> Self { fn default() -> Self {
let wallet_name = if let Some(id) = NodeConfig::get_stratum_wallet_id() {
WalletConfig::name_by_id(id).unwrap_or("-".to_string())
} else {
"-".to_string()
};
Self { Self {
stratum_server_setup: StratumSetup::default() stratum_server_setup: StratumSetup::default(),
wallet_name,
} }
} }
} }
@ -103,10 +113,8 @@ impl NetworkTab for NetworkMining {
[true, false, true, false]); [true, false, true, false]);
}); });
columns[1].vertical_centered(|ui| { columns[1].vertical_centered(|ui| {
//TODO: Stratum mining wallet listening address. Replace with local wallet name.
let wallet_addr = NodeConfig::get_stratum_wallet_addr().replace("http://", "");
View::rounded_box(ui, View::rounded_box(ui,
wallet_addr, self.wallet_name.clone(),
t!("network_mining.rewards_wallet"), t!("network_mining.rewards_wallet"),
[false, true, false, true]); [false, true, false, true]);
}); });

View file

@ -21,6 +21,7 @@ use crate::gui::views::{Modal, View};
use crate::gui::views::network::settings::NetworkSettings; use crate::gui::views::network::settings::NetworkSettings;
use crate::gui::views::types::{ModalContainer, ModalPosition, TextEditOptions}; use crate::gui::views::types::{ModalContainer, ModalPosition, TextEditOptions};
use crate::node::{Node, NodeConfig}; use crate::node::{Node, NodeConfig};
use crate::wallet::WalletConfig;
/// Stratum server setup section content. /// Stratum server setup section content.
pub struct StratumSetup { pub struct StratumSetup {
@ -35,6 +36,9 @@ pub struct StratumSetup {
/// Flag to check if stratum port from saved config value is available. /// Flag to check if stratum port from saved config value is available.
is_port_available: bool, is_port_available: bool,
/// Wallet name to receive rewards.
wallet_name: Option<String>,
/// Attempt time value in seconds to mine on a particular header. /// Attempt time value in seconds to mine on a particular header.
attempt_time_edit: String, attempt_time_edit: String,
@ -56,11 +60,17 @@ impl Default for StratumSetup {
fn default() -> Self { fn default() -> Self {
let (ip, port) = NodeConfig::get_stratum_address(); let (ip, port) = NodeConfig::get_stratum_address();
let is_port_available = NodeConfig::is_stratum_port_available(&ip, &port); let is_port_available = NodeConfig::is_stratum_port_available(&ip, &port);
let wallet_name = if let Some(id) = NodeConfig::get_stratum_wallet_id() {
WalletConfig::name_by_id(id)
} else {
None
};
Self { Self {
available_ips: NodeConfig::get_ip_addrs(), available_ips: NodeConfig::get_ip_addrs(),
stratum_port_edit: port, stratum_port_edit: port,
stratum_port_available_edit: is_port_available, stratum_port_available_edit: is_port_available,
is_port_available, is_port_available,
wallet_name,
attempt_time_edit: NodeConfig::get_stratum_attempt_time(), attempt_time_edit: NodeConfig::get_stratum_attempt_time(),
min_share_diff_edit: NodeConfig::get_stratum_min_share_diff(), min_share_diff_edit: NodeConfig::get_stratum_min_share_diff(),
modal_ids: vec![ modal_ids: vec![
@ -101,7 +111,7 @@ impl StratumSetup {
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
// Show loading indicator or controls to start/stop stratum server if port is available. // Show loading indicator or controls to start/stop stratum server if port is available.
if self.is_port_available { if self.is_port_available && self.wallet_name.is_some() {
if Node::is_stratum_starting() || Node::is_stratum_stopping() { if Node::is_stratum_starting() || Node::is_stratum_stopping() {
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
ui.add_space(8.0); ui.add_space(8.0);
@ -145,6 +155,25 @@ impl StratumSetup {
View::horizontal_line(ui, Colors::item_stroke()); View::horizontal_line(ui, Colors::item_stroke());
ui.add_space(6.0); ui.add_space(6.0);
// Show wallet name.
ui.add_space(2.0);
ui.label(RichText::new(t!("wallets.wallet"))
.size(16.0)
.color(Colors::gray()));
ui.add_space(2.0);
ui.label(RichText::new(self.wallet_name.as_ref().unwrap_or(&"-".to_string()))
.size(16.0)
.color(Colors::white_or_black(true)));
ui.add_space(8.0);
View::button(ui, t!("network_settings.choose_wallet"), Colors::button(), || {
//TODO: select wallet
});
ui.add_space(12.0);
View::horizontal_line(ui, Colors::item_stroke());
ui.add_space(6.0);
// Show message when IP addresses are not available on the system. // Show message when IP addresses are not available on the system.
if self.available_ips.is_empty() { if self.available_ips.is_empty() {
NetworkSettings::no_ip_address_ui(ui); NetworkSettings::no_ip_address_ui(ui);

View file

@ -30,6 +30,7 @@ pub struct WalletConnectionModal {
/// Flag to show connection creation. /// Flag to show connection creation.
show_conn_creation: bool, show_conn_creation: bool,
/// External connection creation content.
add_ext_conn_content: ExternalConnectionModal add_ext_conn_content: ExternalConnectionModal
} }
@ -72,7 +73,7 @@ impl WalletConnectionModal {
}) })
.id_source("integrated_node") .id_source("integrated_node")
.scroll_bar_visibility(ScrollBarVisibility::AlwaysHidden) .scroll_bar_visibility(ScrollBarVisibility::AlwaysHidden)
.auto_shrink([false; 2]) .auto_shrink([true; 2])
.show(ui, |ui| { .show(ui, |ui| {
ui.add_space(2.0); ui.add_space(2.0);

View file

@ -12,5 +12,5 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
mod connection; mod conn;
pub use connection::*; pub use conn::*;

View file

@ -185,6 +185,9 @@ impl NodeConfig {
// Generate random p2p and api ports. // Generate random p2p and api ports.
Self::setup_default_ports(&mut config); Self::setup_default_ports(&mut config);
// Clear wallet listener url (actually it will be wallet id).
config.server.stratum_mining_config.clone().unwrap().wallet_listener_url = "".to_string();
Settings::write_to_file(&config, path); Settings::write_to_file(&config, path);
config config
} }
@ -364,9 +367,30 @@ impl NodeConfig {
} }
/// Get stratum mining server wallet address to get rewards. /// Get stratum mining server wallet address to get rewards.
pub fn get_stratum_wallet_addr() -> String { pub fn get_stratum_wallet_id() -> Option<i64> {
let r_config = Settings::node_config_to_read(); let r_config = Settings::node_config_to_read();
r_config.node.clone().server.stratum_mining_config.unwrap().wallet_listener_url let id = r_config.node.clone().server.stratum_mining_config.unwrap().wallet_listener_url;
return if id.is_empty() {
None
} else {
if let Ok(id) = id.parse::<i64>() {
Some(id)
} else {
None
}
}
}
/// Save stratum mining server wallet address to get rewards.
pub fn save_stratum_wallet_id(id: i64) {
let w_config = Settings::node_config_to_update();
w_config.node
.clone()
.server
.stratum_mining_config
.unwrap()
.wallet_listener_url = id.to_string();
w_config.save();
} }
/// Get the amount of time in seconds to attempt to mine on a particular header. /// Get the amount of time in seconds to attempt to mine on a particular header.

View file

@ -92,6 +92,16 @@ impl WalletConfig {
None None
} }
/// Get wallet name by provided identifier.
pub fn name_by_id(id: i64) -> Option<String> {
let mut wallet_dir = WalletConfig::get_base_path(AppConfig::chain_type());
wallet_dir.push(id.to_string());
if let Some(cfg) = Self::load(wallet_dir) {
return Some(cfg.name);
}
None
}
/// Save wallet config. /// Save wallet config.
pub fn save(&self) { pub fn save(&self) {
let config_path = Self::get_config_file_path(self.chain_type, self.id); let config_path = Self::get_config_file_path(self.chain_type, self.id);