installer: add final step summary
This commit is contained in:
parent
437faef1af
commit
0365794f91
@ -166,9 +166,13 @@ impl Installer {
|
||||
|
||||
pub async fn install(ctx: Context) -> Result<PathBuf, Error> {
|
||||
let hardware_wallets = ctx
|
||||
.hw_tokens
|
||||
.hws
|
||||
.iter()
|
||||
.map(|(kind, fingerprint, token)| HardwareWalletConfig::new(kind, fingerprint, token))
|
||||
.filter_map(|(kind, fingerprint, token)| {
|
||||
token
|
||||
.as_ref()
|
||||
.map(|token| HardwareWalletConfig::new(kind, fingerprint, token))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut cfg: liana::config::Config = ctx
|
||||
|
||||
@ -399,7 +399,7 @@ pub struct RegisterDescriptor {
|
||||
descriptor: Option<MultipathDescriptor>,
|
||||
processing: bool,
|
||||
chosen_hw: Option<usize>,
|
||||
hws: Vec<(HardwareWallet, Option<[u8; 32]>)>,
|
||||
hws: Vec<(HardwareWallet, Option<[u8; 32]>, bool)>,
|
||||
error: Option<Error>,
|
||||
}
|
||||
|
||||
@ -410,7 +410,7 @@ impl Step for RegisterDescriptor {
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
match message {
|
||||
Message::Select(i) => {
|
||||
if let Some((hw, hmac)) = self.hws.get(i) {
|
||||
if let Some((hw, hmac, _)) = self.hws.get(i) {
|
||||
if hmac.is_none() {
|
||||
let device = hw.device.clone();
|
||||
let descriptor = self.descriptor.as_ref().unwrap().to_string();
|
||||
@ -434,7 +434,8 @@ impl Step for RegisterDescriptor {
|
||||
.iter_mut()
|
||||
.find(|hw_h| hw_h.0.fingerprint == fingerprint)
|
||||
{
|
||||
hw_h.1 = Some(hmac.unwrap_or([0x00; 32]));
|
||||
hw_h.1 = hmac;
|
||||
hw_h.2 = true;
|
||||
}
|
||||
}
|
||||
Err(e) => self.error = Some(e),
|
||||
@ -445,9 +446,9 @@ impl Step for RegisterDescriptor {
|
||||
if !self
|
||||
.hws
|
||||
.iter()
|
||||
.any(|(h, _)| h.fingerprint == hw.fingerprint)
|
||||
.any(|(h, _, _)| h.fingerprint == hw.fingerprint)
|
||||
{
|
||||
self.hws.push((hw, None));
|
||||
self.hws.push((hw, None, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -459,11 +460,9 @@ impl Step for RegisterDescriptor {
|
||||
Command::none()
|
||||
}
|
||||
fn apply(&mut self, ctx: &mut Context) -> bool {
|
||||
for (hw, token) in &self.hws {
|
||||
if let Some(token) = token {
|
||||
if *token != [0x00; 32] {
|
||||
ctx.hw_tokens.push((hw.kind, hw.fingerprint, *token));
|
||||
}
|
||||
for (hw, token, registered) in &self.hws {
|
||||
if *registered {
|
||||
ctx.hws.push((hw.kind, hw.fingerprint, *token));
|
||||
}
|
||||
}
|
||||
true
|
||||
|
||||
@ -42,7 +42,11 @@ pub struct Context {
|
||||
pub bitcoin_config: BitcoinConfig,
|
||||
pub bitcoind_config: Option<BitcoindConfig>,
|
||||
pub descriptor: Option<MultipathDescriptor>,
|
||||
pub hw_tokens: Vec<(DeviceKind, bitcoin::util::bip32::Fingerprint, [u8; 32])>,
|
||||
pub hws: Vec<(
|
||||
DeviceKind,
|
||||
bitcoin::util::bip32::Fingerprint,
|
||||
Option<[u8; 32]>,
|
||||
)>,
|
||||
pub data_dir: PathBuf,
|
||||
}
|
||||
|
||||
@ -53,7 +57,7 @@ impl Context {
|
||||
network,
|
||||
poll_interval_secs: Duration::from_secs(30),
|
||||
},
|
||||
hw_tokens: Vec::new(),
|
||||
hws: Vec::new(),
|
||||
bitcoind_config: None,
|
||||
descriptor: None,
|
||||
data_dir,
|
||||
@ -206,6 +210,7 @@ impl From<DefineBitcoind> for Box<dyn Step> {
|
||||
|
||||
pub struct Final {
|
||||
generating: bool,
|
||||
context: Option<Context>,
|
||||
warning: Option<String>,
|
||||
config_path: Option<PathBuf>,
|
||||
}
|
||||
@ -213,6 +218,7 @@ pub struct Final {
|
||||
impl Final {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
context: None,
|
||||
generating: false,
|
||||
warning: None,
|
||||
config_path: None,
|
||||
@ -221,6 +227,9 @@ impl Final {
|
||||
}
|
||||
|
||||
impl Step for Final {
|
||||
fn load_context(&mut self, ctx: &Context) {
|
||||
self.context = Some(ctx.clone());
|
||||
}
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
match message {
|
||||
Message::Installed(res) => {
|
||||
@ -244,7 +253,11 @@ impl Step for Final {
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
let ctx = self.context.as_ref().unwrap();
|
||||
let desc = ctx.descriptor.as_ref().unwrap().to_string();
|
||||
view::install(
|
||||
ctx,
|
||||
desc,
|
||||
self.generating,
|
||||
self.config_path.as_ref(),
|
||||
self.warning.as_ref(),
|
||||
|
||||
@ -7,6 +7,7 @@ use crate::{
|
||||
hw::HardwareWallet,
|
||||
installer::{
|
||||
message::{self, Message},
|
||||
step::Context,
|
||||
Error,
|
||||
},
|
||||
ui::{
|
||||
@ -298,7 +299,7 @@ pub fn import_descriptor<'a>(
|
||||
|
||||
pub fn register_descriptor<'a>(
|
||||
descriptor: String,
|
||||
hws: &[(HardwareWallet, Option<[u8; 32]>)],
|
||||
hws: &[(HardwareWallet, Option<[u8; 32]>, bool)],
|
||||
error: Option<&Error>,
|
||||
processing: bool,
|
||||
chosen_hw: Option<usize>,
|
||||
@ -306,16 +307,19 @@ pub fn register_descriptor<'a>(
|
||||
layout(
|
||||
Column::new()
|
||||
.push(text("Register descriptor").bold().size(50))
|
||||
.push(
|
||||
.push(card::simple(
|
||||
Column::new()
|
||||
.push(text("The descriptor:").small().bold())
|
||||
.push(text(descriptor.clone()).small())
|
||||
.push(
|
||||
button::transparent_border(Some(icon::clipboard_icon()), "Copy")
|
||||
.on_press(Message::Clibpboard(descriptor)),
|
||||
Row::new().push(Column::new().width(Length::Fill)).push(
|
||||
button::transparent_border(Some(icon::clipboard_icon()), "Copy")
|
||||
.on_press(Message::Clibpboard(descriptor)),
|
||||
),
|
||||
)
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.max_width(1000),
|
||||
))
|
||||
.push_maybe(error.map(|e| card::error("Failed to import xpub", e.to_string())))
|
||||
.push(
|
||||
Column::new()
|
||||
@ -345,7 +349,7 @@ pub fn register_descriptor<'a>(
|
||||
&hw.0,
|
||||
Some(i) == chosen_hw,
|
||||
processing,
|
||||
hw.1.is_some(),
|
||||
hw.2,
|
||||
))
|
||||
}),
|
||||
)
|
||||
@ -488,15 +492,87 @@ pub fn define_bitcoin<'a>(
|
||||
}
|
||||
|
||||
pub fn install<'a>(
|
||||
context: &Context,
|
||||
descriptor: String,
|
||||
generating: bool,
|
||||
config_path: Option<&std::path::PathBuf>,
|
||||
warning: Option<&'a String>,
|
||||
) -> Element<'a, Message> {
|
||||
let mut col = Column::new()
|
||||
.push(
|
||||
Container::new(
|
||||
Column::new()
|
||||
.spacing(10)
|
||||
.push(
|
||||
card::simple(
|
||||
Column::new()
|
||||
.spacing(5)
|
||||
.push(text("Descriptor:").small().bold())
|
||||
.push(text(descriptor).small()),
|
||||
)
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.push(
|
||||
card::simple(
|
||||
Column::new()
|
||||
.spacing(5)
|
||||
.push(text("Hardware devices:").small().bold())
|
||||
.push(context.hws.iter().fold(Column::new(), |acc, hw| {
|
||||
acc.push(
|
||||
Row::new()
|
||||
.spacing(5)
|
||||
.push(text(hw.0.to_string()).small())
|
||||
.push(text(format!("(fingerprint: {})", hw.1)).small()),
|
||||
)
|
||||
})),
|
||||
)
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.push(
|
||||
card::simple(
|
||||
Column::new()
|
||||
.push(text("Bitcoind:").small().bold())
|
||||
.push(
|
||||
Row::new()
|
||||
.spacing(5)
|
||||
.align_items(Alignment::Center)
|
||||
.push(text("Cookie path:").small())
|
||||
.push(
|
||||
text(format!(
|
||||
"{}",
|
||||
context
|
||||
.bitcoind_config
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.cookie_path
|
||||
.to_string_lossy()
|
||||
))
|
||||
.small(),
|
||||
),
|
||||
)
|
||||
.push(
|
||||
Row::new()
|
||||
.spacing(5)
|
||||
.align_items(Alignment::Center)
|
||||
.push(text("Address:").small())
|
||||
.push(
|
||||
text(format!(
|
||||
"{}",
|
||||
context.bitcoind_config.as_ref().unwrap().addr
|
||||
))
|
||||
.small(),
|
||||
),
|
||||
),
|
||||
)
|
||||
.width(Length::Fill),
|
||||
),
|
||||
)
|
||||
.padding(50)
|
||||
.max_width(1000),
|
||||
)
|
||||
.spacing(50)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.padding(100)
|
||||
.spacing(50)
|
||||
.align_items(Alignment::Center);
|
||||
|
||||
if let Some(error) = warning {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user