From fab3303147ad1933f9b434502b8cc5465b451dc5 Mon Sep 17 00:00:00 2001 From: edouardparis Date: Thu, 3 Oct 2024 16:58:43 +0200 Subject: [PATCH] installer step: ChooseDescriptorTemplate --- gui/src/installer/context.rs | 8 +++ gui/src/installer/message.rs | 1 + gui/src/installer/mod.rs | 5 +- .../installer/step/descriptor/editor/mod.rs | 1 + .../step/descriptor/editor/template.rs | 55 +++++++++++++++ gui/src/installer/step/mod.rs | 3 +- .../view/{editor.rs => editor/mod.rs} | 2 + gui/src/installer/view/editor/template/mod.rs | 69 +++++++++++++++++++ 8 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 gui/src/installer/step/descriptor/editor/template.rs rename gui/src/installer/view/{editor.rs => editor/mod.rs} (99%) create mode 100644 gui/src/installer/view/editor/template/mod.rs diff --git a/gui/src/installer/context.rs b/gui/src/installer/context.rs index 3f46cbe7..0849fc21 100644 --- a/gui/src/installer/context.rs +++ b/gui/src/installer/context.rs @@ -45,10 +45,17 @@ impl RemoteBackend { } } +#[derive(Debug, Clone, Copy)] +pub enum DescriptorTemplate { + SimpleInheritance, + Custom, +} + #[derive(Clone)] pub struct Context { pub bitcoin_config: BitcoinConfig, pub bitcoin_backend: Option, + pub descriptor_template: DescriptorTemplate, pub descriptor: Option, pub keys: Vec, pub hws: Vec<(DeviceKind, bitcoin::bip32::Fingerprint, Option<[u8; 32]>)>, @@ -71,6 +78,7 @@ impl Context { remote_backend: RemoteBackend, ) -> Self { Self { + descriptor_template: DescriptorTemplate::Custom, bitcoin_config: BitcoinConfig { network, poll_interval_secs: Duration::from_secs(30), diff --git a/gui/src/installer/message.rs b/gui/src/installer/message.rs index 3e7939cb..87a266c5 100644 --- a/gui/src/installer/message.rs +++ b/gui/src/installer/message.rs @@ -32,6 +32,7 @@ pub enum Message { UseHotSigner, Installed(Result), CreateTaprootDescriptor(bool), + SelectDescriptorTemplate(context::DescriptorTemplate), SelectBackend(SelectBackend), ImportRemoteWallet(ImportRemoteWallet), SelectBitcoindType(SelectBitcoindTypeMsg), diff --git a/gui/src/installer/mod.rs b/gui/src/installer/mod.rs index 43be9df3..f0f3262a 100644 --- a/gui/src/installer/mod.rs +++ b/gui/src/installer/mod.rs @@ -39,8 +39,8 @@ use crate::{ pub use message::Message; use step::{ - BackupDescriptor, BackupMnemonic, ChooseBackend, DefineDescriptor, DefineNode, Final, - ImportDescriptor, ImportRemoteWallet, InternalBitcoindStep, RecoverMnemonic, + BackupDescriptor, BackupMnemonic, ChooseBackend, ChooseDescriptorTemplate, DefineDescriptor, + DefineNode, Final, ImportDescriptor, ImportRemoteWallet, InternalBitcoindStep, RecoverMnemonic, RegisterDescriptor, RemoteBackendLogin, SelectBitcoindTypeStep, ShareXpubs, Step, }; @@ -119,6 +119,7 @@ impl Installer { hws: HardwareWallets::new(destination_path.clone(), network), steps: match user_flow { UserFlow::CreateWallet => vec![ + ChooseDescriptorTemplate::default().into(), DefineDescriptor::new(network, signer.clone()).into(), BackupMnemonic::new(signer.clone()).into(), BackupDescriptor::default().into(), diff --git a/gui/src/installer/step/descriptor/editor/mod.rs b/gui/src/installer/step/descriptor/editor/mod.rs index 493622cc..b6d42d24 100644 --- a/gui/src/installer/step/descriptor/editor/mod.rs +++ b/gui/src/installer/step/descriptor/editor/mod.rs @@ -1,4 +1,5 @@ pub mod key; +pub mod template; use std::collections::{BTreeMap, HashMap, HashSet}; use std::iter::FromIterator; diff --git a/gui/src/installer/step/descriptor/editor/template.rs b/gui/src/installer/step/descriptor/editor/template.rs new file mode 100644 index 00000000..ab9d5e2a --- /dev/null +++ b/gui/src/installer/step/descriptor/editor/template.rs @@ -0,0 +1,55 @@ +use iced::Command; + +use liana_ui::widget::Element; + +use crate::{ + hw::HardwareWallets, + installer::{ + context::DescriptorTemplate, + message::Message, + step::{Context, Step}, + view, + }, +}; + +pub struct ChooseDescriptorTemplate { + template: DescriptorTemplate, +} + +impl Default for ChooseDescriptorTemplate { + fn default() -> Self { + Self { + template: DescriptorTemplate::Custom, + } + } +} + +impl From for Box { + fn from(s: ChooseDescriptorTemplate) -> Box { + Box::new(s) + } +} +impl Step for ChooseDescriptorTemplate { + fn update(&mut self, _hws: &mut HardwareWallets, message: Message) -> Command { + if let Message::SelectDescriptorTemplate(template) = message { + self.template = template; + Command::perform(async move {}, |_| Message::Next) + } else { + Command::none() + } + } + + fn apply(&mut self, ctx: &mut Context) -> bool { + ctx.descriptor_template = self.template; + true + } + + fn view<'a>( + &'a self, + _hws: &'a HardwareWallets, + progress: (usize, usize), + _email: Option<&'a str>, + ) -> Element { + view::editor::template::choose_descriptor_template(progress) + } +} diff --git a/gui/src/installer/step/mod.rs b/gui/src/installer/step/mod.rs index d47c253a..01a8fcf1 100644 --- a/gui/src/installer/step/mod.rs +++ b/gui/src/installer/step/mod.rs @@ -10,7 +10,8 @@ pub use node::{ }; pub use descriptor::{ - editor::DefineDescriptor, BackupDescriptor, ImportDescriptor, RegisterDescriptor, + editor::template::ChooseDescriptorTemplate, editor::DefineDescriptor, BackupDescriptor, + ImportDescriptor, RegisterDescriptor, }; pub use backend::{ChooseBackend, ImportRemoteWallet, RemoteBackendLogin}; diff --git a/gui/src/installer/view/editor.rs b/gui/src/installer/view/editor/mod.rs similarity index 99% rename from gui/src/installer/view/editor.rs rename to gui/src/installer/view/editor/mod.rs index 14dda5ee..7dc0582e 100644 --- a/gui/src/installer/view/editor.rs +++ b/gui/src/installer/view/editor/mod.rs @@ -1,3 +1,5 @@ +pub mod template; + use iced::widget::{ container, pick_list, scrollable, scrollable::Properties, slider, Button, Space, }; diff --git a/gui/src/installer/view/editor/template/mod.rs b/gui/src/installer/view/editor/template/mod.rs new file mode 100644 index 00000000..486ff5bc --- /dev/null +++ b/gui/src/installer/view/editor/template/mod.rs @@ -0,0 +1,69 @@ +use iced::{alignment, Alignment, Length}; + +use liana_ui::{ + color, + component::{ + button, card, + text::{h3, p1_regular, p2_regular}, + }, + widget::*, +}; + +use crate::installer::context; +use crate::installer::{message::Message, view::layout}; + +pub fn choose_descriptor_template(progress: (usize, usize)) -> Element<'static, Message> { + layout( + progress, + None, + "Choose Wallet Type", + Column::new() + .align_items(Alignment::Start) + .push(Container::new( + p1_regular("What do you want your wallet for? Also consider this depends on the amount of funds you have, the more funds, higher the security should be. Not sure about the wallet type? We can help you.") + .style(color::GREY_3) + .horizontal_alignment(alignment::Horizontal::Left) + ).align_x(alignment::Horizontal::Left).width(Length::Fill)) + .push( + card::simple( + Row::new() + .align_items(Alignment::Center) + .push( + Column::new() + .align_items(Alignment::Start) + .push(h3("Simple inheritance")) + .push(p2_regular("Two keys required, one for yourself to spend and another for your heir.").style(color::GREY_3)) + .width(Length::Fill) + ) + .push(button::secondary(None, "Select").on_press( + Message::SelectDescriptorTemplate( + context::DescriptorTemplate::SimpleInheritance, + ), + )), + ) + .width(Length::Fill), + ) + .push( + card::simple( + Row::new() + .align_items(Alignment::Center) + .push( + Column::new() + .align_items(Alignment::Start) + .push(h3("Custom (choose your own)")) + .push(p2_regular("Create a custom set up that fits all your need").style(color::GREY_3)) + .width(Length::Fill) + ) + .push(button::secondary(None, "Select").on_press( + Message::SelectDescriptorTemplate( + context::DescriptorTemplate::Custom, + ), + )), + ) + .width(Length::Fill), + ) + .spacing(20), + true, + Some(Message::Previous), + ) +}