Skip to content

Commit

Permalink
Merge #1303: backend settings
Browse files Browse the repository at this point in the history
6349df9 gui(installer): implement Default for DefineElectrum (pythcoiner)
530a8c5 gui(settings): do not switch between backend types (pythcoiner)

Pull request description:

  22ed096 fixes #1306
  2bd22b4 fixes #1305
  fd50913 in order to make clippy happy

ACKs for top commit:
  jp1ac4:
    ACK 6349df9.

Tree-SHA512: 55fcac1a6e2129269e54106b354d22d6ddd4eae68034ecca030f7eb17adf1d7e6cb3cd3118dd877df3b934d26f61c6f7b5af0f354dc1000fa0c1fc6c6d833df5
  • Loading branch information
darosior committed Sep 11, 2024
2 parents 2a40701 + 6349df9 commit ea49d12
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
68 changes: 32 additions & 36 deletions gui/src/app/state/settings/bitcoind.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::convert::{From, TryInto};
use std::net::{SocketAddr, SocketAddrV4};
use std::net::SocketAddr;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
Expand Down Expand Up @@ -31,7 +31,7 @@ pub struct BitcoindSettingsState {
warning: Option<Error>,
config_updated: bool,

node_settings: Option<BitcoindSettings>,
bitcoind_settings: Option<BitcoindSettings>,
electrum_settings: Option<ElectrumSettings>,
rescan_settings: RescanSetting,
}
Expand All @@ -48,26 +48,18 @@ impl BitcoindSettingsState {
match config.clone().and_then(|c| c.bitcoin_backend) {
Some(BitcoinBackend::Bitcoind(bitcoind_config)) => {
configured_node_type = Some(NodeType::Bitcoind);
let dummy_electrum = ElectrumConfig {
addr: String::default(),
};
(Some(bitcoind_config), Some(dummy_electrum))
(Some(bitcoind_config), None)
}
Some(BitcoinBackend::Electrum(electrum_config)) => {
configured_node_type = Some(NodeType::Electrum);
// The dummy values will be ignored.
let dummy_bitcoind = BitcoindConfig {
addr: SocketAddr::V4(SocketAddrV4::from_str("127.0.0.1:10000").unwrap()),
rpc_auth: BitcoindRpcAuth::CookieFile(PathBuf::from_str("").unwrap()),
};
(Some(dummy_bitcoind), Some(electrum_config))
(None, Some(electrum_config))
}
_ => (None, None),
};
BitcoindSettingsState {
warning: None,
config_updated: false,
node_settings: bitcoind_config.map(|bitcoind_config| {
bitcoind_settings: bitcoind_config.map(|bitcoind_config| {
BitcoindSettings::new(
configured_node_type,
config
Expand Down Expand Up @@ -106,7 +98,7 @@ impl State for BitcoindSettingsState {
Ok(()) => {
self.config_updated = true;
self.warning = None;
if let Some(settings) = &mut self.node_settings {
if let Some(settings) = &mut self.bitcoind_settings {
settings.edited(true);
return Command::perform(async {}, |_| {
Message::View(view::Message::Settings(
Expand All @@ -126,7 +118,7 @@ impl State for BitcoindSettingsState {
Err(e) => {
self.config_updated = false;
self.warning = Some(e);
if let Some(settings) = &mut self.node_settings {
if let Some(settings) = &mut self.bitcoind_settings {
settings.edited(false);
}
if let Some(settings) = &mut self.electrum_settings {
Expand All @@ -149,7 +141,7 @@ impl State for BitcoindSettingsState {
Message::View(view::Message::Settings(view::SettingsMessage::BitcoindSettings(
msg,
))) => {
if let Some(settings) = &mut self.node_settings {
if let Some(settings) = &mut self.bitcoind_settings {
return settings.update(daemon, cache, msg);
}
}
Expand All @@ -170,10 +162,14 @@ impl State for BitcoindSettingsState {

fn view<'a>(&'a self, cache: &'a Cache) -> Element<'a, view::Message> {
let can_edit_bitcoind_settings =
self.node_settings.is_some() && !self.rescan_settings.processing;
self.bitcoind_settings.is_some() && !self.rescan_settings.processing;
let can_edit_electrum_settings =
self.electrum_settings.is_some() && !self.rescan_settings.processing;
let settings_edit = self.node_settings.as_ref().map(|settings| settings.edit) == Some(true)
let settings_edit = self
.bitcoind_settings
.as_ref()
.map(|settings| settings.edit)
== Some(true)
|| self
.electrum_settings
.as_ref()
Expand All @@ -183,26 +179,26 @@ impl State for BitcoindSettingsState {
view::settings::bitcoind_settings(
cache,
self.warning.as_ref(),
if let Some(settings) = &self.node_settings {
vec![
settings
.view(cache, can_edit_bitcoind_settings)
.map(move |msg| {
if self.bitcoind_settings.is_some() || self.electrum_settings.is_some() {
let mut setting_panels = Vec::new();
if let Some(settings) = self.bitcoind_settings.as_ref() {
setting_panels.push(settings.view(cache, can_edit_bitcoind_settings).map(
move |msg| {
view::Message::Settings(view::SettingsMessage::BitcoindSettings(msg))
}),
self.electrum_settings
.as_ref()
.expect("If we have bitcoind, we must also have electrum")
.view(cache, can_edit_electrum_settings)
.map(move |msg| {
},
))
}
if let Some(settings) = self.electrum_settings.as_ref() {
setting_panels.push(settings.view(cache, can_edit_electrum_settings).map(
move |msg| {
view::Message::Settings(view::SettingsMessage::ElectrumSettings(msg))
}),
self.rescan_settings
.view(cache, can_do_rescan)
.map(move |msg| {
view::Message::Settings(view::SettingsMessage::RescanSettings(msg))
}),
]
},
))
}
setting_panels.push(self.rescan_settings.view(cache, can_do_rescan).map(
move |msg| view::Message::Settings(view::SettingsMessage::RescanSettings(msg)),
));
setting_panels
} else {
vec![self
.rescan_settings
Expand Down
6 changes: 2 additions & 4 deletions gui/src/installer/step/node/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ use crate::{
node::electrum::ConfigField,
};

#[derive(Clone)]
#[derive(Clone, Default)]
pub struct DefineElectrum {
address: form::Value<String>,
}

impl DefineElectrum {
pub fn new() -> Self {
Self {
address: form::Value::default(),
}
Self::default()
}

pub fn can_try_ping(&self) -> bool {
Expand Down

0 comments on commit ea49d12

Please sign in to comment.