Skip to content

Commit

Permalink
Add installer dropdown for advanced settings
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Mar 14, 2024
1 parent 1f0b72e commit 1aca594
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 24 deletions.
6 changes: 3 additions & 3 deletions gui/src/installer/step/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ impl Setup {
}

pub struct DefineDescriptor {
data_dir: Option<PathBuf>,
setup: HashMap<Network, Setup>,

network: Network,
network_valid: bool,
use_taproot: bool,
data_dir: Option<PathBuf>,
setup: HashMap<Network, Setup>,

modal: Option<Box<dyn DescriptorEditModal>>,
signer: Arc<Mutex<Signer>>,
Expand All @@ -203,7 +204,6 @@ impl DefineDescriptor {
setup: HashMap::from([(Network::Bitcoin, Setup::new())]),
data_dir: None,
network_valid: true,

modal: None,
signer,
error: None,
Expand Down
85 changes: 65 additions & 20 deletions gui/src/installer/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,32 +175,26 @@ pub fn welcome<'a>() -> Element<'a, Message> {

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DescriptorKind {
Legacy,
P2WSH,
Taproot,
}

const DESCRIPTOR_KINDS: [DescriptorKind; 2] = [DescriptorKind::Legacy, DescriptorKind::Taproot];
const DESCRIPTOR_KINDS: [DescriptorKind; 2] = [DescriptorKind::P2WSH, DescriptorKind::Taproot];

impl std::fmt::Display for DescriptorKind {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Legacy => write!(f, "Default"),
Self::P2WSH => write!(f, "P2WSH"),
Self::Taproot => write!(f, "Taproot"),
}
}
}

#[allow(clippy::too_many_arguments)]
pub fn define_descriptor<'a>(
progress: (usize, usize),
pub fn define_descriptor_advanced_settings<'a>(
network: bitcoin::Network,
network_valid: bool,
use_taproot: bool,
spending_keys: Vec<Element<'a, Message>>,
spending_threshold: usize,
recovery_paths: Vec<Element<'a, Message>>,
valid: bool,
error: Option<&String>,
) -> Element<'a, Message> {
let col_network = Column::new()
.spacing(10)
Expand All @@ -210,7 +204,7 @@ pub fn define_descriptor<'a>(
Message::Network(net.into())
})
.style(if network_valid {
theme::PickList::Simple
theme::PickList::Secondary
} else {
theme::PickList::Invalid
})
Expand All @@ -224,21 +218,56 @@ pub fn define_descriptor<'a>(

let col_wallet = Column::new()
.spacing(10)
.push(text("Wallet").bold())
.push(text("Descriptor type").bold())
.push(container(
pick_list(
&DESCRIPTOR_KINDS[..],
Some(if use_taproot {
DescriptorKind::Taproot
} else {
DescriptorKind::Legacy
DescriptorKind::P2WSH
}),
|kind| Message::CreateTaprootDescriptor(kind == DescriptorKind::Taproot),
)
.style(theme::PickList::Secondary)
.padding(10),
));

container(
Column::new()
.spacing(20)
.push(Space::with_height(0))
.push(separation().width(500))
.push(
Row::new()
.push(col_network)
.push(Space::with_width(100))
.push(col_wallet),
)
.push_maybe(if use_taproot {
Some(
p1_regular("Taproot is only supported by Liana version 5.0 and above")
.style(color::GREY_2),
)
} else {
None
}),
)
.into()
}

#[allow(clippy::too_many_arguments)]
pub fn define_descriptor<'a>(
progress: (usize, usize),
network: bitcoin::Network,
network_valid: bool,
use_taproot: bool,
spending_keys: Vec<Element<'a, Message>>,
spending_threshold: usize,
recovery_paths: Vec<Element<'a, Message>>,
valid: bool,
error: Option<&String>,
) -> Element<'a, Message> {
let col_spending_keys = Column::new()
.push(
Row::new()
Expand Down Expand Up @@ -301,13 +330,6 @@ pub fn define_descriptor<'a>(
.push(
Column::new()
.width(Length::Fill)
.push(
Row::new()
.push(col_network)
.push(Space::with_width(Length::Fixed(100.0)))
.push(col_wallet)
.align_items(Alignment::Start),
)
.push(
Column::new()
.spacing(25)
Expand Down Expand Up @@ -341,6 +363,29 @@ pub fn define_descriptor<'a>(
}),
)
.push_maybe(error.map(|e| card::error("Failed to create descriptor", e.to_string())))
.push(collapse::Collapse::new(
|| {
Button::new(
Row::new()
.align_items(Alignment::Center)
.spacing(10)
.push(text("Advanced settings").small().bold())
.push(icon::collapse_icon()),
)
.style(theme::Button::Transparent)
},
|| {
Button::new(
Row::new()
.align_items(Alignment::Center)
.spacing(10)
.push(text("Advanced settings").small().bold())
.push(icon::collapsed_icon()),
)
.style(theme::Button::Transparent)
},
move || define_descriptor_advanced_settings(network, network_valid, use_taproot),
))
.push(Space::with_height(Length::Fixed(20.0)))
.spacing(50),
false,
Expand Down
2 changes: 1 addition & 1 deletion gui/ui/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl pick_list::StyleSheet for Theme {
border_width: 1.0,
border_color: color::GREY_3,
border_radius: 25.0,
text_color: color::GREY_3,
text_color: color::GREY_2,
},
}
}
Expand Down

0 comments on commit 1aca594

Please sign in to comment.