diff --git a/gui/src/app/state/coins.rs b/gui/src/app/state/coins.rs index 23490db5..3474d37d 100644 --- a/gui/src/app/state/coins.rs +++ b/gui/src/app/state/coins.rs @@ -29,10 +29,13 @@ pub struct Coins { impl Labelled for Coins { fn labelled(&self) -> Vec { - self.list - .iter() - .map(|a| LabelItem::OutPoint(a.outpoint)) - .collect() + let mut items = Vec::new(); + for coin in &self.list { + items.push(LabelItem::OutPoint(coin.outpoint)); + items.push(LabelItem::Txid(coin.outpoint.txid)); + items.push(LabelItem::Address(coin.address.clone())); + } + items } fn labels(&mut self) -> &mut HashMap { &mut self.labels @@ -169,6 +172,7 @@ impl State for CoinsPanel { let mut targets = HashSet::::new(); for coin in coins { targets.insert(LabelItem::OutPoint(coin.outpoint)); + targets.insert(LabelItem::Txid(coin.outpoint.txid)); targets.insert(LabelItem::Address(coin.address)); } daemon2.get_labels(&targets).map_err(|e| e.into()) diff --git a/gui/src/app/state/spend/step.rs b/gui/src/app/state/spend/step.rs index b43f8092..77775286 100644 --- a/gui/src/app/state/spend/step.rs +++ b/gui/src/app/state/spend/step.rs @@ -528,30 +528,12 @@ impl Step for SaveSpend { if let Some(label) = &draft.batch_label { tx.labels .insert(tx.psbt.unsigned_tx.txid().to_string(), label.clone()); - for (i, output) in tx.psbt.unsigned_tx.output.iter().enumerate() { - let address_str = Address::from_script(&output.script_pubkey, tx.network) - .unwrap() - .to_string(); - if tx.change_indexes.contains(&i) && tx.labels.contains_key(&address_str) { - tx.labels - .insert(address_str, format!("Change of {}", label.clone())); - } - } } } else if let Some(recipient) = draft.recipients.first() { if !recipient.label.value.is_empty() { let label = recipient.label.value.clone(); tx.labels .insert(tx.psbt.unsigned_tx.txid().to_string(), label.clone()); - for (i, output) in tx.psbt.unsigned_tx.output.iter().enumerate() { - let address_str = Address::from_script(&output.script_pubkey, tx.network) - .unwrap() - .to_string(); - if tx.change_indexes.contains(&i) && tx.labels.contains_key(&address_str) { - tx.labels - .insert(address_str, format!("Change of {}", label.clone())); - } - } } } diff --git a/gui/src/app/view/coins.rs b/gui/src/app/view/coins.rs index 1bab2fec..d8a32f6c 100644 --- a/gui/src/app/view/coins.rs +++ b/gui/src/app/view/coins.rs @@ -64,6 +64,7 @@ fn coin_list_view<'a>( ) -> Container<'a, Message> { let outpoint = coin.outpoint.to_string(); let address = coin.address.to_string(); + let txid = coin.outpoint.txid.to_string(); Container::new( Column::new() .push( @@ -75,6 +76,19 @@ fn coin_list_view<'a>( .push(if !collapsed { if let Some(label) = labels.get(&outpoint) { Container::new(p1_bold(label)).width(Length::Fill) + } else if let Some(label) = labels.get(&txid) { + Container::new( + Row::new() + .spacing(5) + .push( + // It it not possible to know if a coin is a + // change coin or not so for now, From is + // enough + p1_bold("From").style(color::GREY_3), + ) + .push(p1_bold(label)), + ) + .width(Length::Fill) } else { Container::new(Space::with_width(Length::Fill)) .width(Length::Fill) @@ -141,6 +155,21 @@ fn coin_list_view<'a>( }) .push( Column::new() + .push( + Row::new() + .align_items(Alignment::Center) + .push( + p2_regular("Address label:") + .bold() + .style(color::GREY_2), + ) + .push(if let Some(label) = labels.get(&address) { + p2_regular(label).style(color::GREY_2) + } else { + p2_regular("No label").style(color::GREY_2) + }) + .spacing(5), + ) .push( Row::new() .align_items(Alignment::Center) @@ -166,11 +195,11 @@ fn coin_list_view<'a>( Row::new() .align_items(Alignment::Center) .push( - p2_regular("Address label:") + p2_regular("Deposit transaction label:") .bold() .style(color::GREY_2), ) - .push(if let Some(label) = labels.get(&address) { + .push(if let Some(label) = labels.get(&txid) { p2_regular(label).style(color::GREY_2) } else { p2_regular("No label").style(color::GREY_2) diff --git a/gui/src/app/view/home.rs b/gui/src/app/view/home.rs index 131a9f8e..652268b3 100644 --- a/gui/src/app/view/home.rs +++ b/gui/src/app/view/home.rs @@ -237,7 +237,7 @@ pub fn payment_view<'a>( }) .push(Container::new(amount_with_size( &Amount::from_sat(tx.tx.output[output_index].value), - H1_SIZE, + H3_SIZE, ))) .push(Space::with_height(H3_SIZE)) .push(Container::new(h3("Transaction")).width(Length::Fill)) diff --git a/gui/src/app/view/psbt.rs b/gui/src/app/view/psbt.rs index b0bad4ce..0189617b 100644 --- a/gui/src/app/view/psbt.rs +++ b/gui/src/app/view/psbt.rs @@ -707,15 +707,8 @@ pub fn inputs_and_outputs_view<'a>( .filter(|(i, _)| change_indexes.as_ref().unwrap().contains(i)) .fold( Column::new().padding(20), - |col: Column<'a, Message>, (i, output)| { - col.spacing(10).push(change_view( - i, - tx.txid(), - output, - network, - labels, - labels_editing, - )) + |col: Column<'a, Message>, (_, output)| { + col.spacing(10).push(change_view(output, network)) }, ) .into() @@ -881,77 +874,32 @@ fn payment_view<'a>( .into() } -fn change_view<'a>( - i: usize, - txid: Txid, - output: &'a TxOut, - network: Network, - labels: &'a HashMap, - labels_editing: &'a HashMap>, -) -> Element<'a, Message> { +fn change_view(output: &TxOut, network: Network) -> Element { let addr = Address::from_script(&output.script_pubkey, network) .unwrap() .to_string(); - let outpoint = OutPoint { - txid, - vout: i as u32, - } - .to_string(); - Column::new() + Row::new() .width(Length::Fill) .spacing(5) .push( Row::new() - .spacing(5) .align_items(Alignment::Center) - .push( - Container::new(if let Some(label) = labels_editing.get(&outpoint) { - label::label_editing(outpoint.clone(), label, text::P1_SIZE) - } else { - label::label_editable( - outpoint.clone(), - labels.get(&outpoint), - text::P1_SIZE, - ) - }) - .width(Length::Fill), - ) - .push(amount(&Amount::from_sat(output.value))), - ) - .push( - Column::new() + .width(Length::Fill) .push( Row::new() .align_items(Alignment::Center) .width(Length::Fill) + .spacing(5) + .push(p1_bold("Address:").style(color::GREY_3)) + .push(p2_regular(addr.clone()).style(color::GREY_3)) .push( - Row::new() - .align_items(Alignment::Center) - .width(Length::Fill) - .spacing(5) - .push(p1_bold("Address:").style(color::GREY_3)) - .push(p2_regular(addr.clone()).style(color::GREY_3)) - .push( - Button::new(icon::clipboard_icon().style(color::GREY_3)) - .on_press(Message::Clipboard(addr.clone())) - .style(theme::Button::TransparentBorder), - ), + Button::new(icon::clipboard_icon().style(color::GREY_3)) + .on_press(Message::Clipboard(addr)) + .style(theme::Button::TransparentBorder), ), - ) - .push_maybe(labels.get(&addr).map(|label| { - Row::new() - .align_items(Alignment::Center) - .width(Length::Fill) - .push( - Row::new() - .align_items(Alignment::Center) - .width(Length::Fill) - .spacing(5) - .push(p1_bold("Address label:").style(color::GREY_3)) - .push(p2_regular(label).style(color::GREY_3)), - ) - })), + ), ) + .push(amount(&Amount::from_sat(output.value))) .into() }