installer step: ChooseDescriptorTemplate

This commit is contained in:
edouardparis 2024-10-03 16:58:43 +02:00
parent d0ec811bef
commit fab3303147
8 changed files with 141 additions and 3 deletions

View File

@ -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<BitcoinBackend>,
pub descriptor_template: DescriptorTemplate,
pub descriptor: Option<LianaDescriptor>,
pub keys: Vec<KeySetting>,
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),

View File

@ -32,6 +32,7 @@ pub enum Message {
UseHotSigner,
Installed(Result<PathBuf, Error>),
CreateTaprootDescriptor(bool),
SelectDescriptorTemplate(context::DescriptorTemplate),
SelectBackend(SelectBackend),
ImportRemoteWallet(ImportRemoteWallet),
SelectBitcoindType(SelectBitcoindTypeMsg),

View File

@ -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(),

View File

@ -1,4 +1,5 @@
pub mod key;
pub mod template;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::iter::FromIterator;

View File

@ -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<ChooseDescriptorTemplate> for Box<dyn Step> {
fn from(s: ChooseDescriptorTemplate) -> Box<dyn Step> {
Box::new(s)
}
}
impl Step for ChooseDescriptorTemplate {
fn update(&mut self, _hws: &mut HardwareWallets, message: Message) -> Command<Message> {
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<Message> {
view::editor::template::choose_descriptor_template(progress)
}
}

View File

@ -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};

View File

@ -1,3 +1,5 @@
pub mod template;
use iced::widget::{
container, pick_list, scrollable, scrollable::Properties, slider, Button, Space,
};

View File

@ -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),
)
}