Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Dec 12, 2024
1 parent 3992e03 commit 524b36e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
"{}",
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 9 additions & 12 deletions base_layer/wallet/src/transaction_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3529,28 +3529,25 @@ where
) -> Result<TxId, TransactionServiceError> {
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(),
Expand All @@ -3562,7 +3559,7 @@ where
amount,
source_address,
destination_address,
status,
TransactionStatus::try_from(import_status.clone())?,
current_height,
mined_timestamp,
scanned_output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ where
..
} |
PaymentId::Address(address) => address.clone(),
PaymentId::TransactionInfo { .. } => self.resources.one_sided_tari_address.clone(),
_ => TariAddress::default(),
}
};
Expand Down

0 comments on commit 524b36e

Please sign in to comment.