gui: make 'ExportModal' generic
This commit is contained in:
parent
f13cd1fe73
commit
a3bf250696
@ -23,22 +23,35 @@ pub struct ExportModal {
|
||||
state: ExportState,
|
||||
error: Option<export::Error>,
|
||||
daemon: Arc<dyn Daemon + Sync + Send>,
|
||||
export_type: ExportType,
|
||||
}
|
||||
|
||||
impl ExportModal {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new(daemon: Arc<dyn Daemon + Sync + Send>) -> Self {
|
||||
pub fn new(daemon: Arc<dyn Daemon + Sync + Send>, export_type: ExportType) -> Self {
|
||||
Self {
|
||||
path: None,
|
||||
handle: None,
|
||||
state: ExportState::Init,
|
||||
error: None,
|
||||
daemon,
|
||||
export_type,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_filename(&self) -> String {
|
||||
match self.export_type {
|
||||
ExportType::Transactions => {
|
||||
let date = chrono::Local::now().format("%Y-%m-%dT%H-%M-%S");
|
||||
format!("liana-txs-{date}.csv")
|
||||
}
|
||||
ExportType::Psbt => todo!(),
|
||||
ExportType::Descriptor => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn launch(&self) -> Task<app::message::Message> {
|
||||
Task::perform(get_path(), |m| {
|
||||
Task::perform(get_path(self.default_filename()), |m| {
|
||||
app::message::Message::View(view::Message::Export(ExportMessage::Path(m)))
|
||||
})
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ use crate::{
|
||||
wallet::Wallet,
|
||||
},
|
||||
daemon::model::{self, LabelsLoader},
|
||||
export::ExportMessage,
|
||||
export::{ExportMessage, ExportType},
|
||||
};
|
||||
|
||||
use crate::daemon::{
|
||||
@ -268,7 +268,10 @@ impl State for TransactionsPanel {
|
||||
}
|
||||
Message::View(view::Message::Export(ExportMessage::Open)) => {
|
||||
if let TransactionsModal::None = &self.modal {
|
||||
self.modal = TransactionsModal::Export(ExportModal::new(daemon));
|
||||
self.modal = TransactionsModal::Export(ExportModal::new(
|
||||
daemon,
|
||||
ExportType::Transactions,
|
||||
));
|
||||
if let TransactionsModal::Export(m) = &self.modal {
|
||||
return m.launch();
|
||||
}
|
||||
|
||||
@ -447,12 +447,10 @@ pub async fn export_transactions(
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn get_path() -> Option<PathBuf> {
|
||||
let date = chrono::Local::now().format("%Y-%m-%dT%H-%M-%S");
|
||||
let file_name = format!("liana-txs-{date}.csv");
|
||||
pub async fn get_path(filename: String) -> Option<PathBuf> {
|
||||
rfd::AsyncFileDialog::new()
|
||||
.set_title("Choose a location to export...")
|
||||
.set_file_name(file_name)
|
||||
.set_file_name(filename)
|
||||
.save_file()
|
||||
.await
|
||||
.map(|fh| fh.path().to_path_buf())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user