Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge launcher and first installer step #1245

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions gui/src/installer/message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use liana::miniscript::{bitcoin::bip32::Fingerprint, DescriptorPublicKey};
use liana::miniscript::{
bitcoin::{bip32::Fingerprint, Network},
DescriptorPublicKey,
};
use std::path::PathBuf;

use super::{context, Error};
Expand All @@ -12,16 +15,13 @@ use async_hwi::{DeviceKind, Version};

#[derive(Debug, Clone)]
pub enum Message {
CreateWallet,
ShareXpubs,
ImportWallet,
UserActionDone(bool),
Exit(PathBuf, Option<Bitcoind>),
Clibpboard(String),
Next,
Skip,
Previous,
BackToLauncher,
BackToLauncher(Network),
Install,
Close,
Reload,
Expand Down
131 changes: 64 additions & 67 deletions gui/src/installer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ pub use message::Message;
use step::{
BackupDescriptor, BackupMnemonic, ChooseBackend, DefineBitcoind, DefineDescriptor, Final,
ImportDescriptor, ImportRemoteWallet, InternalBitcoindStep, RecoverMnemonic,
RegisterDescriptor, SelectBitcoindTypeStep, ShareXpubs, Step, Welcome,
RegisterDescriptor, SelectBitcoindTypeStep, ShareXpubs, Step,
};

#[derive(Debug, Clone)]
pub enum UserFlow {
CreateWallet,
AddWallet,
ShareXpubs,
}

pub struct Installer {
pub network: bitcoin::Network,
pub datadir: PathBuf,
Expand All @@ -58,9 +65,12 @@ pub struct Installer {
}

impl Installer {
fn previous(&mut self) {
fn previous(&mut self) -> Command<Message> {
let network = self.network;
if self.current > 0 {
self.current -= 1;
} else {
return Command::perform(async move { network }, Message::BackToLauncher);
}
// skip the previous step according to the current context.
while self.current > 0
Expand All @@ -76,44 +86,72 @@ impl Installer {
if let Some(step) = self.steps.get(self.current) {
step.revert(&mut self.context)
}
Command::none()
}

pub fn new(
destination_path: PathBuf,
network: bitcoin::Network,
remote_backend: Option<BackendClient>,
user_flow: UserFlow,
) -> (Installer, Command<Message>) {
(
Installer {
network,
datadir: destination_path.clone(),
current: 0,
hws: HardwareWallets::new(destination_path.clone(), network),
steps: vec![Welcome::default().into()],
context: Context::new(
network,
destination_path,
remote_backend.map(RemoteBackend::WithoutWallet),
),
signer: Arc::new(Mutex::new(Signer::generate(network).unwrap())),
let signer = Arc::new(Mutex::new(Signer::generate(network).unwrap()));
let context = Context::new(
network,
destination_path.clone(),
remote_backend.map(RemoteBackend::WithoutWallet),
);
let mut installer = Installer {
network,
datadir: destination_path.clone(),
current: 0,
hws: HardwareWallets::new(destination_path.clone(), network),
steps: match user_flow {
UserFlow::CreateWallet => vec![
DefineDescriptor::new(network, signer.clone()).into(),
BackupMnemonic::new(signer.clone()).into(),
BackupDescriptor::default().into(),
RegisterDescriptor::new_create_wallet().into(),
ChooseBackend::new(network).into(),
SelectBitcoindTypeStep::new().into(),
InternalBitcoindStep::new(&context.data_dir).into(),
DefineBitcoind::new().into(),
Final::new().into(),
],
UserFlow::ShareXpubs => vec![ShareXpubs::new(network, signer.clone()).into()],
UserFlow::AddWallet => vec![
ChooseBackend::new(network).into(),
ImportRemoteWallet::new(network).into(),
ImportDescriptor::new(network).into(),
RecoverMnemonic::default().into(),
RegisterDescriptor::new_import_wallet().into(),
SelectBitcoindTypeStep::new().into(),
InternalBitcoindStep::new(&context.data_dir).into(),
DefineBitcoind::new().into(),
Final::new().into(),
],
},
Command::none(),
)
context,
signer,
};
let current_step = installer
.steps
.get_mut(installer.current)
.expect("There is always a step");
current_step.load_context(&installer.context);
let command = current_step.load();
(installer, command)
}

pub fn destination_path(&self) -> PathBuf {
self.context.data_dir.clone()
}

pub fn subscription(&self) -> Subscription<Message> {
if self.current > 0 {
self.steps
.get(self.current)
.expect("There is always a step")
.subscription(&self.hws)
} else {
Subscription::none()
}
self.steps
.get(self.current)
.expect("There is always a step")
.subscription(&self.hws)
}

pub fn stop(&mut self) {
Expand Down Expand Up @@ -166,44 +204,6 @@ impl Installer {

pub fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::CreateWallet => {
self.steps = vec![
Welcome::default().into(),
DefineDescriptor::new(self.network, self.signer.clone()).into(),
BackupMnemonic::new(self.signer.clone()).into(),
BackupDescriptor::default().into(),
RegisterDescriptor::new_create_wallet().into(),
ChooseBackend::new(self.network).into(),
SelectBitcoindTypeStep::new().into(),
InternalBitcoindStep::new(&self.context.data_dir).into(),
DefineBitcoind::new().into(),
Final::new().into(),
];
self.next()
}
Message::ShareXpubs => {
self.steps = vec![
Welcome::default().into(),
ShareXpubs::new(self.network, self.signer.clone()).into(),
];
self.next()
}
Message::ImportWallet => {
self.steps = vec![
Welcome::default().into(),
ChooseBackend::new(self.network).into(),
ImportRemoteWallet::new(self.network).into(),
ImportDescriptor::new(self.network).into(),
RecoverMnemonic::default().into(),
RegisterDescriptor::new_import_wallet().into(),
SelectBitcoindTypeStep::new().into(),
InternalBitcoindStep::new(&self.context.data_dir).into(),
DefineBitcoind::new().into(),
Final::new().into(),
];

self.next()
}
Message::HardwareWallets(msg) => match self.hws.update(msg) {
Ok(cmd) => cmd.map(Message::HardwareWallets),
Err(e) => {
Expand All @@ -213,10 +213,7 @@ impl Installer {
},
Message::Clibpboard(s) => clipboard::write(s),
Message::Next => self.next(),
Message::Previous => {
self.previous();
Command::none()
}
Message::Previous => self.previous(),
Message::Install => {
let _cmd = self
.steps
Expand Down
20 changes: 0 additions & 20 deletions gui/src/installer/step/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,6 @@ pub trait Step {
fn stop(&self) {}
}

#[derive(Default)]
pub struct Welcome {}

impl Step for Welcome {
fn view<'a>(
&'a self,
_hws: &'a HardwareWallets,
_progress: (usize, usize),
_email: Option<&'a str>,
) -> Element<Message> {
view::welcome()
}
}

impl From<Welcome> for Box<dyn Step> {
fn from(s: Welcome) -> Box<dyn Step> {
Box::new(s)
}
}

pub struct Final {
generating: bool,
internal_bitcoind: Option<Bitcoind>,
Expand Down
96 changes: 0 additions & 96 deletions gui/src/installer/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,102 +42,6 @@ use crate::{
},
};

pub fn welcome<'a>() -> Element<'a, Message> {
Container::new(
Column::new()
.push(
Container::new(
Row::new()
.align_items(Alignment::Center)
.push(
Container::new(image::liana_brand_grey().width(Length::Fixed(200.0)))
.width(Length::Fill),
)
.push(
Row::new()
.push(
button::secondary(
Some(icon::previous_icon()),
"Change network",
)
.width(Length::Fixed(200.0))
.on_press(Message::BackToLauncher),
)
.push(
button::secondary(None, "Share Xpubs")
.width(Length::Fixed(200.0))
.on_press(Message::ShareXpubs),
)
.spacing(20),
),
)
.padding(100),
)
.push(
Container::new(
Column::new()
.push(
Row::new()
.align_items(Alignment::End)
.spacing(20)
.push(
Container::new(
Column::new()
.spacing(20)
.align_items(Alignment::Center)
.push(
image::create_new_wallet_icon()
.width(Length::Fixed(100.0)),
)
.push(
p1_regular("Create a new wallet")
.style(color::GREY_3),
)
.push(
button::secondary(None, "Select")
.width(Length::Fixed(200.0))
.on_press(Message::CreateWallet),
)
.align_items(Alignment::Center),
)
.padding(20),
)
.push(
Container::new(
Column::new()
.spacing(20)
.align_items(Alignment::Center)
.push(
image::restore_wallet_icon()
.width(Length::Fixed(100.0)),
)
.push(
p1_regular("Add an existing wallet")
.style(color::GREY_3),
)
.push(
button::secondary(None, "Select")
.width(Length::Fixed(200.0))
.on_press(Message::ImportWallet),
)
.align_items(Alignment::Center),
)
.padding(20),
),
)
.push(Space::with_height(Length::Fixed(100.0)))
.spacing(50)
.align_items(Alignment::Center),
)
.center_y()
.center_x()
.width(Length::Fill)
.height(Length::Fill),
),
)
.into()
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DescriptorKind {
P2WSH,
Expand Down
Loading
Loading