forked from wizardsardine/liana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge wizardsardine#1496: gui: tx export feature
22f4875 gui: add and export transactions feature (pythcoiner) Pull request description: This PR add a feature to export transactions: Done: - [x] Subscription to run the feature in a detached thread w/ possibility to send update about the ongoing progress. - [x] Let user choose the path using `rfd` crate - [x] Add a modal that show progress of the process - [x] estimate the progress - [x] cancel feature ACKs for top commit: jp1ac4: Tested ACK 22f4875. Tree-SHA512: 5cf271d52878c4845347c5951a562e08e7f7efea08f0dc702d0500e41d6ad8eab7cb31f7e8a7b4edba48916648759ce97a9f591d1bcb4564a0c7067d5274fa08
Showing
12 changed files
with
1,155 additions
and
23 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
use std::{ | ||
path::PathBuf, | ||
sync::{Arc, Mutex}, | ||
}; | ||
|
||
use iced::{Command, Subscription}; | ||
use liana_ui::{component::modal::Modal, widget::Element}; | ||
use tokio::task::JoinHandle; | ||
|
||
use crate::{ | ||
app::{ | ||
message::Message, | ||
view::{self, export::export_modal}, | ||
}, | ||
daemon::Daemon, | ||
export::{self, get_path, ExportMessage, ExportProgress, ExportState}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct ExportModal { | ||
path: Option<PathBuf>, | ||
handle: Option<Arc<Mutex<JoinHandle<()>>>>, | ||
state: ExportState, | ||
error: Option<export::Error>, | ||
daemon: Arc<dyn Daemon + Sync + Send>, | ||
} | ||
|
||
impl ExportModal { | ||
#[allow(clippy::new_without_default)] | ||
pub fn new(daemon: Arc<dyn Daemon + Sync + Send>) -> Self { | ||
Self { | ||
path: None, | ||
handle: None, | ||
state: ExportState::Init, | ||
error: None, | ||
daemon, | ||
} | ||
} | ||
|
||
pub fn launch(&self) -> Command<Message> { | ||
Command::perform(get_path(), |m| { | ||
Message::View(view::Message::Export(ExportMessage::Path(m))) | ||
}) | ||
} | ||
|
||
pub fn update(&mut self, message: Message) -> Command<Message> { | ||
if let Message::View(view::Message::Export(m)) = message { | ||
match m { | ||
ExportMessage::ExportProgress(m) => match m { | ||
ExportProgress::Started(handle) => { | ||
self.handle = Some(handle); | ||
self.state = ExportState::Progress(0.0); | ||
} | ||
ExportProgress::Progress(p) => { | ||
if let ExportState::Progress(_) = self.state { | ||
self.state = ExportState::Progress(p); | ||
} | ||
} | ||
ExportProgress::Finished | ExportProgress::Ended => { | ||
self.state = ExportState::Ended | ||
} | ||
ExportProgress::Error(e) => self.error = Some(e), | ||
ExportProgress::None => {} | ||
}, | ||
ExportMessage::TimedOut => { | ||
self.stop(ExportState::TimedOut); | ||
} | ||
ExportMessage::UserStop => { | ||
self.stop(ExportState::Aborted); | ||
} | ||
ExportMessage::Path(p) => { | ||
if let Some(path) = p { | ||
self.path = Some(path); | ||
self.start(); | ||
} else { | ||
return Command::perform(async {}, |_| { | ||
Message::View(view::Message::Export(ExportMessage::Close)) | ||
}); | ||
} | ||
} | ||
ExportMessage::Close | ExportMessage::Open => { /* unreachable */ } | ||
} | ||
Command::none() | ||
} else { | ||
Command::none() | ||
} | ||
} | ||
pub fn view<'a>(&'a self, content: Element<'a, view::Message>) -> Element<view::Message> { | ||
let modal = Modal::new( | ||
content, | ||
export_modal(&self.state, self.error.as_ref(), "Transactions"), | ||
); | ||
match self.state { | ||
ExportState::TimedOut | ||
| ExportState::Aborted | ||
| ExportState::Ended | ||
| ExportState::Closed => modal.on_blur(Some(view::Message::Close)), | ||
_ => modal, | ||
} | ||
.into() | ||
} | ||
|
||
pub fn start(&mut self) { | ||
self.state = ExportState::Started; | ||
} | ||
|
||
pub fn stop(&mut self, state: ExportState) { | ||
if let Some(handle) = self.handle.take() { | ||
handle.lock().expect("poisoned").abort(); | ||
self.state = state; | ||
} | ||
} | ||
|
||
pub fn subscription(&self) -> Option<Subscription<export::ExportProgress>> { | ||
if let Some(path) = &self.path { | ||
match &self.state { | ||
ExportState::Started | ExportState::Progress(_) => { | ||
Some(iced::subscription::unfold( | ||
"transactions", | ||
export::State::new(self.daemon.clone(), Box::new(path.to_path_buf())), | ||
export::export_subscription, | ||
)) | ||
} | ||
_ => None, | ||
} | ||
} else { | ||
None | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod coins; | ||
mod export; | ||
mod label; | ||
mod psbt; | ||
mod psbts; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.