Merge #1096: Add a warning in installer if mainnet wallet already exists

d770e62e19687a4e6357ac24f899653d922d9293 Collapse advanced settings menu and grey-out `Next` button in installer if mainnet wallet already exists (pythcoiner)

Pull request description:

  this PR fixes #1039, it add a warning in the installer if an wallet already exists on mainnet & grey-out `Next` button if the network  is not valid.

  ![image](https://github.com/wizardsardine/liana/assets/124568858/87b5017d-f44b-47d2-b3bc-77babc0e7cdf)

ACKs for top commit:
  edouardparis:
    ACK d770e62e19687a4e6357ac24f899653d922d9293

Tree-SHA512: c756804fb89aa9cc8bc1009517f88745521580c8d3128ebfdd5b364280fd56dbdbc7490680e0e7208b6c0e1fb55279ce357f46ad2c312311c5cb6e941d27a214
This commit is contained in:
edouardparis 2024-05-27 16:41:16 +02:00
commit a12d7f5788
No known key found for this signature in database
GPG Key ID: E65F7A089C20DC8F
2 changed files with 40 additions and 28 deletions

View File

@ -329,29 +329,34 @@ pub fn define_descriptor<'a>(
progress, progress,
"Create the wallet", "Create the wallet",
Column::new() Column::new()
.push(collapse::Collapse::new( .push(
|| { collapse::Collapse::new(
Button::new( || {
Row::new() Button::new(
.align_items(Alignment::Center) Row::new()
.spacing(10) .align_items(Alignment::Center)
.push(text("Advanced settings").small().bold()) .spacing(10)
.push(icon::collapse_icon()), .push(text("Advanced settings").small().bold())
) .push(icon::collapse_icon()),
.style(theme::Button::Transparent) )
}, .style(theme::Button::Transparent)
|| { },
Button::new( || {
Row::new() Button::new(
.align_items(Alignment::Center) Row::new()
.spacing(10) .align_items(Alignment::Center)
.push(text("Advanced settings").small().bold()) .spacing(10)
.push(icon::collapsed_icon()), .push(text("Advanced settings").small().bold())
) .push(icon::collapsed_icon()),
.style(theme::Button::Transparent) )
}, .style(theme::Button::Transparent)
move || define_descriptor_advanced_settings(network, network_valid, use_taproot), },
)) move || {
define_descriptor_advanced_settings(network, network_valid, use_taproot)
},
)
.collapsed(!network_valid),
)
.push( .push(
Column::new() Column::new()
.width(Length::Fill) .width(Length::Fill)
@ -379,7 +384,7 @@ pub fn define_descriptor<'a>(
)) ))
.width(Length::Fixed(200.0)), .width(Length::Fixed(200.0)),
) )
.push(if !valid { .push(if !valid || !network_valid {
button::primary(None, "Next").width(Length::Fixed(200.0)) button::primary(None, "Next").width(Length::Fixed(200.0))
} else { } else {
button::primary(None, "Next") button::primary(None, "Next")

View File

@ -10,6 +10,7 @@ pub struct Collapse<'a, M, H, F, C> {
after: F, after: F,
content: C, content: C,
phantom: PhantomData<&'a M>, phantom: PhantomData<&'a M>,
state: bool,
} }
impl<'a, Message, T, H, F, C, Theme, Renderer> Collapse<'a, Message, H, F, C> impl<'a, Message, T, H, F, C, Theme, Renderer> Collapse<'a, Message, H, F, C>
@ -28,8 +29,14 @@ where
after, after,
content, content,
phantom: PhantomData, phantom: PhantomData,
state: false,
} }
} }
pub fn collapsed(mut self, state: bool) -> Self {
self.state = state;
self
}
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
@ -51,18 +58,18 @@ where
type State = bool; type State = bool;
type Event = Event<T>; type Event = Event<T>;
fn update(&mut self, state: &mut Self::State, event: Event<T>) -> Option<Message> { fn update(&mut self, _state: &mut Self::State, event: Event<T>) -> Option<Message> {
match event { match event {
Event::Internal(e) => Some(e.into()), Event::Internal(e) => Some(e.into()),
Event::Collapse(s) => { Event::Collapse(s) => {
*state = s; self.state = s;
None None
} }
} }
} }
fn view(&self, state: &Self::State) -> Element<Self::Event, Theme, Renderer> { fn view(&self, _state: &Self::State) -> Element<Self::Event, Theme, Renderer> {
if *state { if self.state {
column![ column![
(self.after)().on_press(Event::Collapse(false)), (self.after)().on_press(Event::Collapse(false)),
(self.content)().map(Event::Internal) (self.content)().map(Event::Internal)