From d7e388707b3368e12b73b578524b8e0c667ddb92 Mon Sep 17 00:00:00 2001 From: pythcoiner Date: Mon, 7 Apr 2025 06:37:14 +0200 Subject: [PATCH] installer: integrate export xpub feature --- liana-gui/src/installer/message.rs | 1 + liana-gui/src/installer/step/share_xpubs.rs | 41 +++++++++++++++++++-- liana-gui/src/installer/view/mod.rs | 8 ++-- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/liana-gui/src/installer/message.rs b/liana-gui/src/installer/message.rs index efe5dc2f..e0ff8ddd 100644 --- a/liana-gui/src/installer/message.rs +++ b/liana-gui/src/installer/message.rs @@ -56,6 +56,7 @@ pub enum Message { AllKeysRedeemed, BackupWallet, ExportWallet(Result), + ExportXpub(String), ImportExport(ImportExportMessage), ImportBackup, WalletFromBackup((HashMap, Backup)), diff --git a/liana-gui/src/installer/step/share_xpubs.rs b/liana-gui/src/installer/step/share_xpubs.rs index 39db3fb7..1befe594 100644 --- a/liana-gui/src/installer/step/share_xpubs.rs +++ b/liana-gui/src/installer/step/share_xpubs.rs @@ -9,6 +9,8 @@ use liana::miniscript::bitcoin::{ use liana_ui::widget::Element; use crate::{ + app::state::export::ExportModal, + export::{ImportExportMessage, ImportExportType}, hw::{HardwareWallet, HardwareWallets}, installer::{ message::Message, @@ -70,6 +72,7 @@ pub struct ShareXpubs { network: Network, hw_xpubs: Vec, xpubs_signer: SignerXpubs, + modal: Option, } impl ShareXpubs { @@ -78,6 +81,7 @@ impl ShareXpubs { network, hw_xpubs: Vec::new(), xpubs_signer: SignerXpubs::new(signer), + modal: None, } } } @@ -102,6 +106,24 @@ impl Step for ShareXpubs { } } } + Message::ExportXpub(xpub_str) => { + if self.modal.is_none() { + let modal = ExportModal::new(None, ImportExportType::ExportXpub(xpub_str)); + let launch = modal.launch(true); + self.modal = Some(modal); + return launch; + } + } + Message::ImportExport(ImportExportMessage::Close) => { + if self.modal.is_some() { + self.modal = None; + } + } + Message::ImportExport(msg) => { + if let Some(modal) = self.modal.as_mut() { + return modal.update(msg); + } + } Message::UseHotSigner => { self.xpubs_signer.select(self.network); } @@ -150,7 +172,14 @@ impl Step for ShareXpubs { } fn subscription(&self, hws: &HardwareWallets) -> Subscription { - hws.refresh().map(Message::HardwareWallets) + let hw = hws.refresh().map(Message::HardwareWallets); + if let Some(modal) = self.modal.as_ref() { + if let Some(sub) = modal.subscription() { + let export = sub.map(|m| Message::ImportExport(ImportExportMessage::Progress(m))); + return Subscription::batch(vec![hw, export]); + } + } + hw } fn apply(&mut self, ctx: &mut Context) -> bool { @@ -166,7 +195,7 @@ impl Step for ShareXpubs { _progress: (usize, usize), email: Option<&'a str>, ) -> Element { - view::share_xpubs( + let content = view::share_xpubs( email, hws.list .iter() @@ -190,7 +219,13 @@ impl Step for ShareXpubs { }) .collect(), self.xpubs_signer.view(), - ) + ); + + if let Some(modal) = &self.modal { + modal.view(content) + } else { + content + } } } diff --git a/liana-gui/src/installer/view/mod.rs b/liana-gui/src/installer/view/mod.rs index b91f19fd..d11d8478 100644 --- a/liana-gui/src/installer/view/mod.rs +++ b/liana-gui/src/installer/view/mod.rs @@ -446,8 +446,8 @@ pub fn signer_xpubs<'a>( ) .push( Container::new( - button::secondary(Some(icon::clipboard_icon()), "Copy") - .on_press(Message::Clibpboard(xpub.clone())) + button::primary(Some(icon::backup_icon()), "Export") + .on_press(Message::ExportXpub(xpub.clone())) .width(Length::Shrink), ) .padding(10), @@ -539,8 +539,8 @@ pub fn hardware_wallet_xpubs<'a>( ) .push( Container::new( - button::secondary(Some(icon::clipboard_icon()), "Copy") - .on_press(Message::Clibpboard(xpub.clone())) + button::primary(Some(icon::backup_icon()), "Export") + .on_press(Message::ExportXpub(xpub.clone())) .width(Length::Shrink), ) .padding(10),