tui: peer payment history behind the F9 payments row (key p)
All checks were successful
ci / test (pull_request) Successful in 5m47s
ci / sdk (pull_request) Successful in 1m28s
ci / fuzz (pull_request) Successful in 4m51s
android-ci / android (pull_request) Successful in 10m36s

The F9 / `/settings` menu's only payment row showed the wallet's own transfer
list (`Node::wallet_recent_transfers`, F6). The signed `/pay` invoices and
`/tip` receipts a peer sent live in the `payments` table and had no path from
the TUI, so they were invisible. `Node::list_payments` (PR #119) closes that
gap; this wires it into a screen.

- `Screen::PeerPayments { state }` + `PeerPaymentsState` /
  `PeerPaymentRow`, built by `PeerPaymentsState::from_payments` from
  `Node::list_payments`' rows (newest first: the store returns `payments.id`
  ascending, the screen windows the vector).
- Key handler: `p` on the F9 screen opens it (`open_peer_payments`); `up`/`down`
  (or `k`/`j`) move the selection, `Esc` goes back, `F9` reopens the menu.
- Rows carry direction, kind, amount (`pay::atomic_to_xmr_str`, the same
  piconero formatter the chat lines use), memo (sanitized at draw time) and the
  receipt's `verified` / `unverified` word; the focused row is marked with `>`
  and bold. The selected row's txid and address sit under the rows — the
  address wrapped over two lines rather than clipped.
- States: populated, `no payments with {peer}`, `could not read payments`, and
  a menu row that refuses when no friend is selected. An empty history is a
  state, never an error.
- Menu: the wallet's own list is retitled `transfers` (F6, unchanged), and the
  new `payments` row (key `p`) names the peer and the count. Two histories, two
  rows, no ambiguity.
- Widths are measured in cells (`Span::width`); trailing columns are dropped
  before they can wrap, so the body fits 80x24 (20 inner rows of 21) as well as
  120x40 and 200x60.

Tests: new `tests/tui_payments.rs` (11 tests) dumps and asserts the screen at
80x24, 120x40 and 200x60 including the empty history, asserts a memo carrying
ESC/BEL/C1/bidi/newline bytes never reaches the frame buffer, and asserts the
window/column invariants for every width from 20 to 200.

Also relaxes one width assertion in `tests/tui_spec.rs`: `fit_cells` was
asserted to start with `"abcdef"`, which only holds when another test's
in-flight `ONIONWIRE_ASCII` mutation is not visible — the suite mutates env vars
without a global lock, so that test flaked (it also fails on an unmodified tree,
1 run in 2). It now accepts either chrome's cut point, which is what the comment
already claimed.

Docs: `docs/TUI.md` gains the screen's section, the retitled/replaced rows and
the updated row count; the "peer payment history" gap entry is closed.
This commit is contained in:
Lance Walters 2026-09-18 23:53:10 -04:00
commit 2fa3466019
No known key found for this signature in database
4 changed files with 1095 additions and 26 deletions

View file

@ -6,11 +6,11 @@ use onionwire::outbox::{OutboxEntry, OutboxStatus};
use onionwire::qr;
use onionwire::tui::{
OutboxSummary, SlashCmd, WalletMenuState, alert_line, ascii_chrome, cell_width,
chat_with_delivery, delivery_tag, draw_chat, draw_share, draw_text_overlay, draw_wallets_settings,
empty_friend_chat_text, fit_cells, help_overlay_text, main_footer_hints, main_header_line,
osc52_copy_sequence, parse_cmd, paste_screen_text, retry_in_text, roster_col_width,
short_send_reason, status_footer, wallets_settings_menu_lines, wallets_settings_menu_text,
wrap_invite,
chat_with_delivery, delivery_tag, draw_chat, draw_share, draw_text_overlay,
draw_wallets_settings, empty_friend_chat_text, fit_cells, help_overlay_text, main_footer_hints,
main_header_line, osc52_copy_sequence, parse_cmd, paste_screen_text, retry_in_text,
roster_col_width, short_send_reason, status_footer, wallets_settings_menu_lines,
wallets_settings_menu_text, wrap_invite,
};
use ratatui::Frame;
use ratatui::Terminal;
@ -429,7 +429,14 @@ fn pending_row(
}
fn queued_row(message_id: i64, body: &str, attempts: u32, next_in: i64, now: i64) -> OutboxEntry {
pending_row(message_id, body, OutboxStatus::Queued, attempts, next_in, now)
pending_row(
message_id,
body,
OutboxStatus::Queued,
attempts,
next_in,
now,
)
}
fn sending_row(message_id: i64, body: &str, now: i64) -> OutboxEntry {
@ -555,7 +562,12 @@ fn delivery_markers_have_exercised_ascii_fallbacks() {
in_msg(5, "epsilon"),
];
let pending = vec![
failed_row(1, "alpha", "connect peer.onion:80: connection timed out", now),
failed_row(
1,
"alpha",
"connect peer.onion:80: connection timed out",
now,
),
queued_row(2, "beta", 1, 30, now),
sending_row(3, "gamma", now),
];
@ -841,9 +853,7 @@ fn rgb_tokens_resolve_to_palette_fg() {
assert_eq!(t.highlight.fg, Some(Color::Rgb(232, 165, 75)));
assert_eq!(t.highlight.bg, Some(Color::Rgb(48, 42, 28)));
assert!(
t.highlight
.add_modifier
.contains(Modifier::BOLD),
t.highlight.add_modifier.contains(Modifier::BOLD),
"RGB highlight must be bold"
);
}
@ -906,7 +916,10 @@ fn alert_line_prefixes_when_no_color() {
let _guard = std::env::var_os("NO_COLOR");
unsafe { std::env::set_var("NO_COLOR", "1") };
let line = alert_line("peer down", 80);
assert!(line.starts_with("! "), "expected '! ' prefix in None mode: {line:?}");
assert!(
line.starts_with("! "),
"expected '! ' prefix in None mode: {line:?}"
);
unsafe {
match _guard {
Some(v) => std::env::set_var("NO_COLOR", v),
@ -938,6 +951,8 @@ fn menu_state() -> WalletMenuState {
bio_set: true,
xmr_set: true,
me_fp: FP.into(),
peer: "lance".into(),
peer_payments: Some(3),
}
}
@ -978,8 +993,18 @@ fn wallets_settings_menu_lists_both_groups_and_every_key() {
// F6 wallet screen's own keys, so the menu teaches the shortcuts it sits
// beside instead of hiding them.
for key in [
"F6 s/x", "F6 p", "c copy F6 r", "F6 c", "F6 i", "F6 r", "F2", "/profile", "/backup",
"/restore", "/wipe", "/wipe-all",
"F6 s/x",
"F6 p",
"c copy F6 r",
"F6 c",
"F6 i",
"F6 r",
"F2",
"/profile",
"/backup",
"/restore",
"/wipe",
"/wipe-all",
] {
assert!(
body.contains(key),
@ -1072,7 +1097,10 @@ fn wallets_settings_menu_words_every_state() {
};
let body = wallets_settings_menu_text(78, &stale);
assert!(body.contains("configured · not connected"), "\n{body}");
assert!(body.contains("wallet answering · chain not at tip"), "\n{body}");
assert!(
body.contains("wallet answering · chain not at tip"),
"\n{body}"
);
let exited = WalletMenuState {
child_state: "exited".into(),
@ -1136,7 +1164,11 @@ fn wallets_settings_menu_truncates_wide_values_in_cells() {
// contract.
let ascii = fit_cells("abcdefghij", 8);
assert!(cell_width(&ascii) <= 8, "{ascii:?}");
assert!(ascii.starts_with("abcdef"), "{ascii:?}");
// Either chrome: ASCII cuts at 5 cells and closes with `...`, unicode cuts at
// 6 and closes with `…`, and both are 8 cells. Asserting `"abcdef"` here made
// this test depend on another test's in-flight `ONIONWIRE_ASCII` mutation
// (the suite mutates env vars without a global lock), so it flaked.
assert!(ascii.starts_with("abcde"), "{ascii:?}");
assert_eq!(cell_width("名"), 2);
assert_eq!(cell_width("abc"), 3);
}
@ -1255,6 +1287,9 @@ fn osc52_copy_sequence_is_a_base64_clipboard_write() {
#[test]
fn slash_settings_is_the_menu() {
assert!(matches!(parse_cmd("/settings"), Some(SlashCmd::Settings)));
assert!(matches!(parse_cmd(" /settings "), Some(SlashCmd::Settings)));
assert!(matches!(
parse_cmd(" /settings "),
Some(SlashCmd::Settings)
));
assert!(parse_cmd("/settings now").is_none());
}