Skip to content

Commit

Permalink
gui: add a modal for export tasks in transactions panels
Browse files Browse the repository at this point in the history
  • Loading branch information
pythcoiner committed Dec 19, 2024
1 parent ef766e6 commit 9bf5c50
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 62 deletions.
2 changes: 2 additions & 0 deletions liana-gui/src/app/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use lianad::config::Config as DaemonConfig;
use crate::{
app::{cache::Cache, error::Error, view, wallet::Wallet},
daemon::model::*,
export::ExportMessage,
hw::HardwareWalletMessage,
};

Expand Down Expand Up @@ -43,4 +44,5 @@ pub enum Message {
LabelsUpdated(Result<HashMap<String, Option<String>>, Error>),
BroadcastModal(Result<HashSet<Txid>, Error>),
RbfModal(Box<HistoryTransaction>, bool, Result<HashSet<Txid>, Error>),
Export(ExportMessage),
}
1 change: 0 additions & 1 deletion liana-gui/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub mod settings;
pub mod state;
pub mod view;
pub mod wallet;
pub mod export;

mod error;

Expand Down
48 changes: 10 additions & 38 deletions liana-gui/src/app/state/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,15 @@ 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},
};
use crate::daemon::Daemon;
use crate::export::{self, get_path, ExportProgress};

#[derive(Debug, Clone)]
pub enum ExportMessage {
Open,
ExportProgress(ExportProgress),
TimedOut,
UserStop,
Path(Option<PathBuf>),
Close,
}

impl From<ExportMessage> for view::Message {
fn from(value: ExportMessage) -> Self {
Self::Export(value)
}
}

#[derive(Debug, PartialEq)]
pub enum ExportState {
Init,
ChoosePath,
Path(PathBuf),
Started,
Progress(f32),
TimedOut,
Aborted,
Ended,
Closed,
}
use crate::{
app::{
message::Message,
view::{self, export::export_modal},
},
export::ExportState,
};
use crate::{daemon::Daemon, export::ExportMessage};

#[derive(Debug)]
pub struct ExportModal {
Expand Down Expand Up @@ -83,7 +57,7 @@ impl ExportModal {
self.state = ExportState::Progress(p);
}
}
ExportProgress::Finnished | ExportProgress::Ended => {
ExportProgress::Finished | ExportProgress::Ended => {
self.state = ExportState::Ended
}
ExportProgress::Error(e) => self.error = Some(e),
Expand Down Expand Up @@ -135,8 +109,6 @@ impl ExportModal {
if let Some(handle) = self.handle.take() {
handle.lock().expect("poisoined").abort();
self.state = state;
} else {
log::warn!("no handle !!!!!!!!!!!!!!!!!!!!!!!!");
}
}

Expand All @@ -146,7 +118,7 @@ impl ExportModal {
ExportState::Started | ExportState::Progress(_) => {
Some(iced::subscription::unfold(
"transactions",
export::ExportState::new(self.daemon.clone(), Box::new(path.to_path_buf())),
export::State::new(self.daemon.clone(), Box::new(path.to_path_buf())),
export::export_subscription,
))
}
Expand Down
1 change: 1 addition & 0 deletions liana-gui/src/app/state/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod coins;
pub mod export;
mod label;
mod psbt;
mod psbts;
Expand Down
73 changes: 57 additions & 16 deletions liana-gui/src/app/state/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,30 @@ use crate::{
wallet::Wallet,
},
daemon::model,
export::ExportMessage,
};

use crate::daemon::{
model::{CreateSpendResult, HistoryTransaction, LabelItem, Labelled},
Daemon,
};

use super::export::ExportModal;

#[derive(Debug)]
pub enum TransactionsModal {
CreateRbf(CreateRbfModal),
Export(ExportModal),
None,
}

pub struct TransactionsPanel {
wallet: Arc<Wallet>,
txs: Vec<HistoryTransaction>,
labels_edited: LabelsEdited,
selected_tx: Option<HistoryTransaction>,
warning: Option<Error>,
create_rbf_modal: Option<CreateRbfModal>,
modal: TransactionsModal,
is_last_page: bool,
processing: bool,
}
Expand All @@ -54,7 +64,7 @@ impl TransactionsPanel {
txs: Vec::new(),
labels_edited: LabelsEdited::default(),
warning: None,
create_rbf_modal: None,
modal: TransactionsModal::None,
is_last_page: false,
processing: false,
}
Expand All @@ -63,7 +73,7 @@ impl TransactionsPanel {
pub fn preselect(&mut self, tx: HistoryTransaction) {
self.selected_tx = Some(tx);
self.warning = None;
self.create_rbf_modal = None;
self.modal = TransactionsModal::None;
}
}

Expand All @@ -76,19 +86,22 @@ impl State for TransactionsPanel {
self.labels_edited.cache(),
self.warning.as_ref(),
);
if let Some(modal) = &self.create_rbf_modal {
modal.view(content)
} else {
content
match &self.modal {
TransactionsModal::CreateRbf(rbf) => rbf.view(content),
_ => content,
}
} else {
view::transactions::transactions_view(
let content = view::transactions::transactions_view(
cache,
&self.txs,
self.warning.as_ref(),
self.is_last_page,
self.processing,
)
);
match &self.modal {
TransactionsModal::Export(export) => export.view(content),
_ => content,
}
}
}

Expand Down Expand Up @@ -134,7 +147,7 @@ impl State for TransactionsPanel {
Message::RbfModal(tx, is_cancel, res) => match res {
Ok(descendant_txids) => {
let modal = CreateRbfModal::new(*tx, is_cancel, descendant_txids);
self.create_rbf_modal = Some(modal);
self.modal = TransactionsModal::CreateRbf(modal);
}
Err(e) => {
self.warning = e.into();
Expand All @@ -146,16 +159,16 @@ impl State for TransactionsPanel {
Message::View(view::Message::Select(i)) => {
self.selected_tx = self.txs.get(i).cloned();
// Clear modal if it's for a different tx.
if let Some(modal) = &self.create_rbf_modal {
if let TransactionsModal::CreateRbf(modal) = &self.modal {
if Some(modal.tx.tx.txid())
!= self.selected_tx.as_ref().map(|selected| selected.tx.txid())
{
self.create_rbf_modal = None;
self.modal = TransactionsModal::None;
}
}
}
Message::View(view::Message::CreateRbf(view::CreateRbfMessage::Cancel)) => {
self.create_rbf_modal = None;
self.modal = TransactionsModal::None;
}
Message::View(view::Message::CreateRbf(view::CreateRbfMessage::New(is_cancel))) => {
if let Some(tx) = &self.selected_tx {
Expand Down Expand Up @@ -246,11 +259,27 @@ impl State for TransactionsPanel {
);
}
}
_ => {
if let Some(modal) = &mut self.create_rbf_modal {
return modal.update(daemon, _cache, message);
Message::View(view::Message::Export(ExportMessage::Open)) => {
if let TransactionsModal::None = &self.modal {
self.modal = TransactionsModal::Export(ExportModal::new(daemon));
if let TransactionsModal::Export(m) = &mut self.modal {
return m.launch();
}
}
}
Message::View(view::Message::Export(ExportMessage::Close)) => {
// Message::Export(ExportMessage::Close) => {
if let TransactionsModal::Export(_) = &self.modal {
self.modal = TransactionsModal::None;
}
}
_ => {
return match &mut self.modal {
TransactionsModal::CreateRbf(modal) => modal.update(daemon, _cache, message),
TransactionsModal::Export(modal) => modal.update(message),
TransactionsModal::None => Command::none(),
};
}
};
Command::none()
}
Expand Down Expand Up @@ -281,6 +310,17 @@ impl State for TransactionsPanel {
Message::HistoryTransactions,
)])
}

fn subscription(&self) -> iced::Subscription<Message> {
if let TransactionsModal::Export(modal) = &self.modal {
if let Some(sub) = modal.subscription() {
return sub.map(|m| {
Message::View(view::Message::Export(ExportMessage::ExportProgress(m)))
});
}
}
iced::Subscription::none()
}
}

impl From<TransactionsPanel> for Box<dyn State> {
Expand All @@ -289,6 +329,7 @@ impl From<TransactionsPanel> for Box<dyn State> {
}
}

#[derive(Debug)]
pub struct CreateRbfModal {
/// Transaction to replace.
tx: model::HistoryTransaction,
Expand Down
5 changes: 2 additions & 3 deletions liana-gui/src/app/view/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use liana_ui::{
widget::Element,
};

use crate::app::state::export::ExportState;
use crate::app::{state::export::ExportMessage, view::message::Message};
use crate::export::Error;
use crate::export::{Error, ExportMessage};
use crate::{app::view::message::Message, export::ExportState};

/// Return the modal view for an export task
pub fn export_modal<'a>(
Expand Down
3 changes: 2 additions & 1 deletion liana-gui/src/app/view/message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{app::menu::Menu, node::bitcoind::RpcAuthType};
use crate::{app::menu::Menu, export::ExportMessage, node::bitcoind::RpcAuthType};
use liana::miniscript::bitcoin::bip32::Fingerprint;

#[derive(Debug, Clone)]
Expand All @@ -19,6 +19,7 @@ pub enum Message {
SelectHardwareWallet(usize),
CreateRbf(CreateRbfMessage),
ShowQrCode(usize),
Export(ExportMessage),
}

#[derive(Debug, Clone)]
Expand Down
1 change: 1 addition & 0 deletions liana-gui/src/app/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod message;
mod warning;

pub mod coins;
pub mod export;
pub mod home;
pub mod hw;
pub mod psbt;
Expand Down
24 changes: 21 additions & 3 deletions liana-gui/src/app/view/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::collections::{HashMap, HashSet};

use chrono::{DateTime, Local, Utc};
use iced::{alignment, widget::tooltip, Alignment, Length};
use iced::{
alignment,
widget::{tooltip, Space},
Alignment, Length,
};

use liana_ui::{
color,
Expand All @@ -15,9 +19,14 @@ use crate::{
cache::Cache,
error::Error,
menu::Menu,
view::{dashboard, label, message::CreateRbfMessage, message::Message, warning::warn},
view::{
dashboard, label,
message::{CreateRbfMessage, Message},
warning::warn,
},
},
daemon::model::{HistoryTransaction, Txid},
export::ExportMessage,
};

pub fn transactions_view<'a>(
Expand All @@ -32,7 +41,16 @@ pub fn transactions_view<'a>(
cache,
warning,
Column::new()
.push(Container::new(h3("Transactions")).width(Length::Fill))
.push(
Row::new()
.push(Container::new(h3("Transactions")))
.push(Space::with_width(Length::Fill))
.push(
Button::new("Export")
.on_press(ExportMessage::Open.into())
.style(theme::Button::Secondary),
),
)
.push(
Column::new()
.spacing(10)
Expand Down

0 comments on commit 9bf5c50

Please sign in to comment.