From 524b36e996f0582ecd8c02628b02728f1169e2d2 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Thu, 12 Dec 2024 22:14:18 +0200 Subject: [PATCH] wip --- .../src/ui/components/transactions_tab.rs | 79 ++++++++++++------- .../src/ui/state/app_state.rs | 7 +- .../wallet/src/transaction_service/service.rs | 21 +++-- .../utxo_scanner_service/utxo_scanner_task.rs | 1 + 4 files changed, 67 insertions(+), 41 deletions(-) diff --git a/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs b/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs index fd8bb185e7..6f0cdcd3c7 100644 --- a/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs +++ b/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs @@ -206,44 +206,57 @@ impl TransactionsTab { let mut column2_items = Vec::new(); let mut column3_items = Vec::new(); - for t in windowed_view { - let cancelled = t.cancelled.is_some(); + for tx in windowed_view { + let cancelled = tx.cancelled.is_some(); let text_color = text_colors.get(&cancelled).unwrap_or(&Color::Reset).to_owned(); - let address_text = match (&t.direction, &t.coinbase, &t.burn) { + let (status, burn) = if let Some(PaymentId::TransactionInfo { burn, .. }) = tx.payment_id.clone() { + ( + match tx.status { + TransactionStatus::OneSidedUnconfirmed => TransactionStatus::MinedUnconfirmed, + TransactionStatus::OneSidedConfirmed => TransactionStatus::MinedConfirmed, + _ => tx.status.clone(), + }, + burn, + ) + } else { + (tx.status.clone(), tx.burn) + }; + + let address_text = match (&tx.direction, &tx.coinbase, burn) { (_, true, _) => "Mining reward", (_, _, true) => "Burned output", - (TransactionDirection::Outbound, _, _) => &app_state.get_alias(t.destination_address.to_base58()), - _ => &app_state.get_alias(t.source_address.to_base58()), + (TransactionDirection::Outbound, _, _) => &app_state.get_alias(tx.destination_address.to_base58()), + _ => &app_state.get_alias(tx.source_address.to_base58()), }; column0_items.push(ListItem::new(Span::styled( app_state.get_alias(address_text.to_string()), Style::default().fg(text_color), ))); - if t.direction == TransactionDirection::Outbound { - let amount_style = if t.cancelled.is_some() { + if tx.direction == TransactionDirection::Outbound { + let amount_style = if tx.cancelled.is_some() { Style::default().fg(Color::Red).add_modifier(Modifier::DIM) } else { Style::default().fg(Color::Red) }; - let amount = format!("{}", t.amount); + let amount = format!("{}", tx.amount); column1_items.push(ListItem::new(Span::styled(amount, amount_style))); } else { - let color = match (t.cancelled.is_some(), chain_height) { + let color = match (tx.cancelled.is_some(), chain_height) { // cancelled (true, _) => Color::DarkGray, // not mature yet - (_, Some(height)) if t.maturity > height => Color::Yellow, + (_, Some(height)) if tx.maturity > height => Color::Yellow, // default _ => Color::Green, }; let amount_style = Style::default().fg(color); - let amount = format!("{}", t.amount); + let amount = format!("{}", tx.amount); column1_items.push(ListItem::new(Span::styled(amount, amount_style))); } column2_items.push(ListItem::new(Span::styled( - match t.mined_timestamp { + match tx.mined_timestamp { None => String::new(), Some(mined_timestamp) => format!( "{}", @@ -254,14 +267,17 @@ impl TransactionsTab { Style::default().fg(text_color), ))); - let status = if matches!(t.cancelled, Some(TxCancellationReason::UserCancelled)) { + let status_display = if matches!(tx.cancelled, Some(TxCancellationReason::UserCancelled)) { "Cancelled".to_string() - } else if t.cancelled.is_some() { + } else if tx.cancelled.is_some() { "Rejected".to_string() } else { - t.status.to_string() + status.to_string() }; - column3_items.push(ListItem::new(Span::styled(status, Style::default().fg(text_color)))); + column3_items.push(ListItem::new(Span::styled( + status_display, + Style::default().fg(text_color), + ))); } let column_list = MultiColumnList::new() @@ -344,32 +360,39 @@ impl TransactionsTab { let content_layout = Layout::default().constraints(constraints).split(columns[1]); let excess_sig = Span::styled(format!("({})", tx.excess_signature), Style::default().fg(Color::White)); - let (direction, amount, fee, weight, inputs_count, outputs_count, payment_id, source, destination) = + let (status, direction, amount, fee, weight, inputs_count, outputs_count, payment_id, source, destination) = if let Some(PaymentId::TransactionInfo { - recipient_address, - sender_one_sided: _sender_one_sided, - amount, + // recipient_address, + // amount, fee, weight, inputs_count, outputs_count, - user_data, - burn: _burn, + // user_data, + .. }) = tx.payment_id.clone() { + let status = match tx.status { + TransactionStatus::OneSidedUnconfirmed => TransactionStatus::MinedUnconfirmed, + TransactionStatus::OneSidedConfirmed => TransactionStatus::MinedConfirmed, + _ => tx.status.clone(), + }; + ( - TransactionDirection::Outbound, - amount, + status, + tx.direction.clone(), // TransactionDirection::Outbound, + tx.amount, // amount, fee, weight, inputs_count, outputs_count, - PaymentId::stringify_bytes(&user_data), - app_state.get_identity().tari_address_interactive.clone(), - recipient_address, + tx.payment_id.clone().unwrap_or_default().user_data_as_string(), + tx.source_address.clone(), // app_state.get_identity().tari_address_interactive.clone(), + tx.destination_address.clone(), // recipient_address, ) } else { ( + tx.status.clone(), tx.direction.clone(), tx.amount, tx.fee, @@ -415,7 +438,7 @@ impl TransactionsTab { let status_msg = if let Some(reason) = tx.cancelled { format!("Cancelled: {}", reason) } else { - tx.status.to_string() + status.to_string() }; let status = Span::styled(status_msg, Style::default().fg(Color::White)); diff --git a/applications/minotari_console_wallet/src/ui/state/app_state.rs b/applications/minotari_console_wallet/src/ui/state/app_state.rs index 5062e0cd05..973c2a0a80 100644 --- a/applications/minotari_console_wallet/src/ui/state/app_state.rs +++ b/applications/minotari_console_wallet/src/ui/state/app_state.rs @@ -1207,7 +1207,12 @@ impl CompletedTransactionInfo { let inputs_count = tx.transaction.body.inputs().len(); let outputs_count = tx.transaction.body.outputs().len(); let coinbase = tx.transaction.body.contains_coinbase(); - let burn = tx.transaction.body.contains_burn(); + // Faux transactions for scanned change outputs must correspond to the original transaction + let burn = if let PaymentId::TransactionInfo { burn, .. } = tx.payment_id { + burn + } else { + tx.transaction.body.contains_burn() + }; Ok(Self { tx_id: tx.tx_id, diff --git a/base_layer/wallet/src/transaction_service/service.rs b/base_layer/wallet/src/transaction_service/service.rs index 71817b09f7..c6108fb797 100644 --- a/base_layer/wallet/src/transaction_service/service.rs +++ b/base_layer/wallet/src/transaction_service/service.rs @@ -3529,28 +3529,25 @@ where ) -> Result { let tx_id = if let Some(id) = tx_id { id } else { TxId::new_random() }; - let (status, direction, amount, destination_address) = if let PaymentId::TransactionInfo { + // Faux transactions for scanned change outputs must correspond to the original transaction + let (direction, amount, destination_address) = if let PaymentId::TransactionInfo { recipient_address, amount, + burn, .. } = payment_id.clone() { ( - match import_status.clone() { - ImportStatus::Broadcast | - ImportStatus::Imported | - ImportStatus::CoinbaseUnconfirmed | - ImportStatus::CoinbaseConfirmed => TransactionStatus::try_from(import_status.clone())?, - ImportStatus::OneSidedUnconfirmed => TransactionStatus::MinedUnconfirmed, - ImportStatus::OneSidedConfirmed => TransactionStatus::MinedConfirmed, - }, TransactionDirection::Outbound, amount, - recipient_address, + if burn { + TariAddress::default() + } else { + recipient_address + }, ) } else { ( - TransactionStatus::try_from(import_status.clone())?, TransactionDirection::Inbound, value, self.resources.one_sided_tari_address.clone(), @@ -3562,7 +3559,7 @@ where amount, source_address, destination_address, - status, + TransactionStatus::try_from(import_status.clone())?, current_height, mined_timestamp, scanned_output, diff --git a/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs b/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs index 83f8f54561..5e74dba12b 100644 --- a/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs +++ b/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs @@ -646,6 +646,7 @@ where .. } | PaymentId::Address(address) => address.clone(), + PaymentId::TransactionInfo { .. } => self.resources.one_sided_tari_address.clone(), _ => TariAddress::default(), } };