diff --git a/src/gui/app.rs b/src/gui/app.rs index e1dbb784..d3062799 100755 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -53,10 +53,6 @@ impl App { if View::is_desktop() { self.platform.set_context(ctx); } - // Check connections availability at dual panel mode. - if Content::is_dual_panel_mode(ctx) && AppConfig::show_connections_network_panel() { - ExternalConnection::check(None, ctx); - } // Setup visuals. crate::setup_visuals(ctx); } diff --git a/src/gui/views/network/connections.rs b/src/gui/views/network/connections.rs index 9a48694c..82729228 100644 --- a/src/gui/views/network/connections.rs +++ b/src/gui/views/network/connections.rs @@ -27,6 +27,8 @@ use crate::wallet::{ConnectionsConfig, ExternalConnection}; /// Network connections content. pub struct ConnectionsContent { + /// Flag to check connections state on first draw. + first_draw: bool, /// External connection [`Modal`] content. ext_conn_modal: ExternalConnectionModal, } @@ -34,6 +36,7 @@ pub struct ConnectionsContent { impl Default for ConnectionsContent { fn default() -> Self { Self { + first_draw: true, ext_conn_modal: ExternalConnectionModal::new(None), } } @@ -59,6 +62,12 @@ impl ContentContainer for ConnectionsContent { } fn container_ui(&mut self, ui: &mut egui::Ui, _: &dyn PlatformCallbacks) { + // Check connections state on first draw. + if self.first_draw { + ExternalConnection::check(None, ui.ctx()); + self.first_draw = false; + } + ui.add_space(2.0); // Show network type selection. diff --git a/src/gui/views/network/content.rs b/src/gui/views/network/content.rs index 94f18614..5fda40db 100644 --- a/src/gui/views/network/content.rs +++ b/src/gui/views/network/content.rs @@ -12,20 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -use egui::{Id, Margin, RichText, ScrollArea}; use egui::scroll_area::ScrollBarVisibility; +use egui::{Id, Margin, RichText, ScrollArea}; -use crate::AppConfig; -use crate::gui::Colors; use crate::gui::icons::{ARROWS_COUNTER_CLOCKWISE, ARROW_LEFT, BRIEFCASE, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE, GEAR, POWER}; use crate::gui::platform::PlatformCallbacks; -use crate::gui::views::{Content, TitlePanel, View}; -use crate::gui::views::network::{ConnectionsContent, NetworkMetrics, NetworkMining, NetworkNode, NetworkSettings}; use crate::gui::views::network::types::{NodeTab, NodeTabType}; +use crate::gui::views::network::{ConnectionsContent, NetworkMetrics, NetworkMining, NetworkNode, NetworkSettings}; use crate::gui::views::settings::SettingsContent; use crate::gui::views::types::{ContentContainer, LinePosition, TitleContentType, TitleType}; +use crate::gui::views::{Content, TitlePanel, View}; +use crate::gui::Colors; use crate::node::{Node, NodeConfig, NodeError}; -use crate::wallet::ExternalConnection; +use crate::AppConfig; /// Network content. pub struct NetworkContent { @@ -279,9 +278,6 @@ impl NetworkContent { } else if !show_connections { View::title_button_big(ui, DOTS_THREE_OUTLINE_VERTICAL, |ui| { AppConfig::toggle_show_connections_network_panel(); - if AppConfig::show_connections_network_panel() { - ExternalConnection::check(None, ui.ctx()); - } }); } else if !dual_panel { View::title_button_big(ui, GEAR, |_| { diff --git a/src/gui/views/wallets/modals/conn.rs b/src/gui/views/wallets/modals/conn.rs index 7868ba9a..52461062 100644 --- a/src/gui/views/wallets/modals/conn.rs +++ b/src/gui/views/wallets/modals/conn.rs @@ -21,7 +21,7 @@ use crate::gui::platform::PlatformCallbacks; use crate::gui::views::{Modal, View}; use crate::gui::views::network::ConnectionsContent; use crate::gui::views::network::modals::ExternalConnectionModal; -use crate::wallet::ConnectionsConfig; +use crate::wallet::{ConnectionsConfig, ExternalConnection}; use crate::wallet::types::ConnectionMethod; /// Wallet connection selection [`Modal`] content. @@ -29,8 +29,8 @@ pub struct WalletConnectionModal { /// Current connection method. pub conn: ConnectionMethod, - /// External connection content. - ext_conn_content: Option + /// External connection creation content. + new_ext_conn_content: Option } impl WalletConnectionModal { @@ -38,7 +38,7 @@ impl WalletConnectionModal { pub fn new(conn: ConnectionMethod) -> Self { Self { conn, - ext_conn_content: None, + new_ext_conn_content: None, } } @@ -48,14 +48,19 @@ impl WalletConnectionModal { modal: &Modal, cb: &dyn PlatformCallbacks, on_select: impl Fn(ConnectionMethod)) { - // Draw external connection content. - if let Some(ext_content) = self.ext_conn_content.as_mut() { + // Draw external connection creation content. + if let Some(ext_content) = self.new_ext_conn_content.as_mut() { ext_content.ui(ui, cb, modal, |conn| { on_select(ConnectionMethod::External(conn.id, conn.url)); }); return; } + // Check connections state on first draw. + if Modal::first_draw() { + ExternalConnection::check(None, ui.ctx()); + } + ui.add_space(4.0); let ext_conn_list = ConnectionsConfig::ext_conn_list(); @@ -97,7 +102,7 @@ impl WalletConnectionModal { // Show button to add new external node connection. let add_node_text = format!("{} {}", PLUS_CIRCLE, t!("wallets.add_node")); View::button(ui, add_node_text, Colors::white_or_black(false), || { - self.ext_conn_content = Some(ExternalConnectionModal::new(None)); + self.new_ext_conn_content = Some(ExternalConnectionModal::new(None)); }); }); ui.add_space(4.0);