diff --git a/gui/src/app/view/home.rs b/gui/src/app/view/home.rs index abd1e078..9a3f2bcf 100644 --- a/gui/src/app/view/home.rs +++ b/gui/src/app/view/home.rs @@ -314,19 +314,33 @@ pub fn payment_view<'a>( ) .spacing(5), )) - .push(super::psbt::inputs_and_outputs_view( - &tx.coins, - &tx.tx, - cache.network, - if tx.is_external() { - None - } else { - Some(tx.change_indexes.clone()) - }, - &tx.labels, - labels_editing, - tx.is_single_payment().is_some(), - )) + .push( + Column::new() + .spacing(20) + // We do not need to display inputs for external incoming transactions + .push_maybe(if tx.is_external() { + None + } else { + Some(super::psbt::inputs_view( + &tx.coins, + &tx.tx, + &tx.labels, + labels_editing, + )) + }) + .push(super::psbt::outputs_view( + &tx.tx, + cache.network, + if tx.is_external() { + None + } else { + Some(tx.change_indexes.clone()) + }, + &tx.labels, + labels_editing, + tx.is_single_payment().is_some(), + )), + ) .spacing(20), ) } diff --git a/gui/src/app/view/psbt.rs b/gui/src/app/view/psbt.rs index d76b8844..d0a8d76b 100644 --- a/gui/src/app/view/psbt.rs +++ b/gui/src/app/view/psbt.rs @@ -74,15 +74,24 @@ pub fn psbt_view<'a>( ) .push(spend_header(tx, labels_editing)) .push(spend_overview_view(tx, desc_info, key_aliases)) - .push(inputs_and_outputs_view( - &tx.coins, - &tx.psbt.unsigned_tx, - network, - Some(tx.change_indexes.clone()), - &tx.labels, - labels_editing, - tx.is_single_payment().is_some(), - )) + .push( + Column::new() + .spacing(20) + .push(inputs_view( + &tx.coins, + &tx.psbt.unsigned_tx, + &tx.labels, + labels_editing, + )) + .push(outputs_view( + &tx.psbt.unsigned_tx, + network, + Some(tx.change_indexes.clone()), + &tx.labels, + labels_editing, + tx.is_single_payment().is_some(), + )), + ) .push(if saved { Row::new() .push( @@ -525,8 +534,71 @@ pub fn path_view<'a>( .into() } -pub fn inputs_and_outputs_view<'a>( +pub fn inputs_view<'a>( coins: &'a HashMap, + tx: &'a Transaction, + labels: &'a HashMap, + labels_editing: &'a HashMap>, +) -> Element<'a, Message> { + Container::new(Collapse::new( + move || { + Button::new( + Row::new() + .align_items(Alignment::Center) + .push( + h4_bold(format!( + "{} coin{} spent", + tx.input.len(), + if tx.input.len() == 1 { "" } else { "s" } + )) + .width(Length::Fill), + ) + .push(icon::collapse_icon()), + ) + .padding(20) + .width(Length::Fill) + .style(theme::Button::TransparentBorder) + }, + move || { + Button::new( + Row::new() + .align_items(Alignment::Center) + .push( + h4_bold(format!( + "{} coin{} spent", + tx.input.len(), + if tx.input.len() == 1 { "" } else { "s" } + )) + .width(Length::Fill), + ) + .push(icon::collapsed_icon()), + ) + .padding(20) + .width(Length::Fill) + .style(theme::Button::TransparentBorder) + }, + move || { + tx.input + .iter() + .fold( + Column::new().spacing(10).padding(20), + |col: Column<'a, Message>, input| { + col.push(input_view( + &input.previous_output, + coins.get(&input.previous_output), + labels, + labels_editing, + )) + }, + ) + .into() + }, + )) + .style(theme::Container::Card(theme::Card::Simple)) + .into() +} + +pub fn outputs_view<'a>( tx: &'a Transaction, network: Network, change_indexes: Option>, @@ -537,67 +609,6 @@ pub fn inputs_and_outputs_view<'a>( let change_indexes_copy = change_indexes.clone(); Column::new() .spacing(20) - .push_maybe(if !coins.is_empty() { - Some( - Container::new(Collapse::new( - move || { - Button::new( - Row::new() - .align_items(Alignment::Center) - .push( - h4_bold(format!( - "{} coin{} spent", - coins.len(), - if coins.len() == 1 { "" } else { "s" } - )) - .width(Length::Fill), - ) - .push(icon::collapse_icon()), - ) - .padding(20) - .width(Length::Fill) - .style(theme::Button::TransparentBorder) - }, - move || { - Button::new( - Row::new() - .align_items(Alignment::Center) - .push( - h4_bold(format!( - "{} coin{} spent", - coins.len(), - if coins.len() == 1 { "" } else { "s" } - )) - .width(Length::Fill), - ) - .push(icon::collapsed_icon()), - ) - .padding(20) - .width(Length::Fill) - .style(theme::Button::TransparentBorder) - }, - move || { - tx.input - .iter() - .fold( - Column::new().spacing(10).padding(20), - |col: Column<'a, Message>, input| { - col.push(input_view( - &input.previous_output, - coins.get(&input.previous_output), - labels, - labels_editing, - )) - }, - ) - .into() - }, - )) - .style(theme::Container::Card(theme::Card::Simple)), - ) - } else { - None - }) .push({ let count = tx .output diff --git a/gui/src/app/view/spend/mod.rs b/gui/src/app/view/spend/mod.rs index 54b273ca..06468a07 100644 --- a/gui/src/app/view/spend/mod.rs +++ b/gui/src/app/view/spend/mod.rs @@ -49,15 +49,24 @@ pub fn spend_view<'a>( .push(Container::new(h3("Send")).width(Length::Fill)) .push(psbt::spend_header(tx, labels_editing)) .push(psbt::spend_overview_view(tx, desc_info, key_aliases)) - .push(psbt::inputs_and_outputs_view( - &tx.coins, - &tx.psbt.unsigned_tx, - network, - Some(tx.change_indexes.clone()), - &tx.labels, - labels_editing, - tx.is_single_payment().is_some(), - )) + .push( + Column::new() + .spacing(20) + .push(psbt::inputs_view( + &tx.coins, + &tx.psbt.unsigned_tx, + &tx.labels, + labels_editing, + )) + .push(psbt::outputs_view( + &tx.psbt.unsigned_tx, + network, + Some(tx.change_indexes.clone()), + &tx.labels, + labels_editing, + tx.is_single_payment().is_some(), + )), + ) .push(if saved { Row::new() .push( diff --git a/gui/src/app/view/transactions.rs b/gui/src/app/view/transactions.rs index 75a6217d..eb702c02 100644 --- a/gui/src/app/view/transactions.rs +++ b/gui/src/app/view/transactions.rs @@ -99,9 +99,11 @@ fn tx_list_view(i: usize, tx: &HistoryTransaction) -> Element<'_, Message> { }) .push( Column::new() - .push_maybe( - tx.labels.get(&tx.tx.txid().to_string()).map(p1_regular), - ) + .push_maybe(if let Some(outpoint) = tx.is_single_payment() { + tx.labels.get(&outpoint.to_string()).map(p1_regular) + } else { + tx.labels.get(&tx.tx.txid().to_string()).map(p1_regular) + }) .push_maybe(tx.time.map(|t| { Container::new( text(format!( @@ -249,19 +251,33 @@ pub fn tx_view<'a>( ) .spacing(5), )) - .push(super::psbt::inputs_and_outputs_view( - &tx.coins, - &tx.tx, - cache.network, - if tx.is_external() { - None - } else { - Some(tx.change_indexes.clone()) - }, - &tx.labels, - labels_editing, - tx.is_single_payment().is_some(), - )) + .push( + Column::new() + .spacing(20) + // We do not need to display inputs for external incoming transactions + .push_maybe(if tx.is_external() { + None + } else { + Some(super::psbt::inputs_view( + &tx.coins, + &tx.tx, + &tx.labels, + labels_editing, + )) + }) + .push(super::psbt::outputs_view( + &tx.tx, + cache.network, + if tx.is_external() { + None + } else { + Some(tx.change_indexes.clone()) + }, + &tx.labels, + labels_editing, + tx.is_single_payment().is_some(), + )), + ) .spacing(20), ) }