-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gui: add and export transactions feature
- Loading branch information
1 parent
c9de7dc
commit aeffc50
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.