From 4536eff561459648cbf0666ec757db95ac29de4f Mon Sep 17 00:00:00 2001 From: Michael Mallan Date: Wed, 28 Aug 2024 11:34:50 +0100 Subject: [PATCH] gui(installer): extract logic for try ping bitcoind --- gui/src/installer/step/node/bitcoind.rs | 11 +++++++++++ gui/src/installer/view.rs | 10 ++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/gui/src/installer/step/node/bitcoind.rs b/gui/src/installer/step/node/bitcoind.rs index a76d8408..9a5959e0 100644 --- a/gui/src/installer/step/node/bitcoind.rs +++ b/gui/src/installer/step/node/bitcoind.rs @@ -392,6 +392,16 @@ impl DefineBitcoind { |res| Message::DefineBitcoind(message::DefineBitcoind::PingBitcoindResult(res)), ) } + + pub fn can_try_ping(&self) -> bool { + if let RpcAuthType::UserPass = self.selected_auth_type { + self.address.valid + && !self.rpc_auth_vals.password.value.is_empty() + && !self.rpc_auth_vals.user.value.is_empty() + } else { + self.address.valid && !self.rpc_auth_vals.cookie_path.value.is_empty() + } + } } impl Step for DefineBitcoind { @@ -503,6 +513,7 @@ impl Step for DefineBitcoind { &self.rpc_auth_vals, &self.selected_auth_type, self.is_running.as_ref(), + self.can_try_ping(), ) } diff --git a/gui/src/installer/view.rs b/gui/src/installer/view.rs index cae776e0..7cac0dfa 100644 --- a/gui/src/installer/view.rs +++ b/gui/src/installer/view.rs @@ -1165,6 +1165,7 @@ pub fn define_bitcoin<'a>( rpc_auth_vals: &RpcAuthValues, selected_auth_type: &RpcAuthType, is_running: Option<&Result<(), Error>>, + can_try_ping: bool, ) -> Element<'a, Message> { let is_loopback = if let Some((ip, _port)) = address.value.clone().rsplit_once(':') { let (ipv4, ipv6) = (Ipv4Addr::from_str(ip), Ipv6Addr::from_str(ip)); @@ -1268,13 +1269,6 @@ pub fn define_bitcoin<'a>( }) .spacing(10); - let check_connect_enable = if let RpcAuthType::UserPass = selected_auth_type { - address.valid - && !rpc_auth_vals.password.value.is_empty() - && !rpc_auth_vals.user.value.is_empty() - } else { - address.valid && !rpc_auth_vals.cookie_path.value.is_empty() - }; layout( progress, None, @@ -1310,7 +1304,7 @@ pub fn define_bitcoin<'a>( .spacing(10) .push(Container::new( button::secondary(None, "Check connection") - .on_press_maybe(if check_connect_enable { + .on_press_maybe(if can_try_ping { Some(Message::DefineBitcoind( message::DefineBitcoind::PingBitcoind, ))