From 3bec3bffbf83a7d75ce1d3599618d542a692359c Mon Sep 17 00:00:00 2001 From: agent Date: Sat, 26 Sep 2026 23:30:10 -0400 Subject: [PATCH] tui: the F6 wallet screen draws its body in the slot that has the height --- src/tui.rs | 152 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 143 insertions(+), 9 deletions(-) diff --git a/src/tui.rs b/src/tui.rs index 4cde9b7..2fefad8 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -5347,10 +5347,12 @@ fn draw_wallet( return; } + // The body needs the height, so it is the `Min` slot: it used to sit in a + // `Length(2)` slot of its own below this one, where the block's two borders + // ate both rows and the tall slot above stayed blank. let cols = Layout::vertical([ Constraint::Length(2), Constraint::Min(4), - Constraint::Length(2), Constraint::Length(3), Constraint::Length(1), ]) @@ -5400,10 +5402,10 @@ balance .style(style_text()) .wrap(Wrap { trim: false }) .block(apply_chrome_borders(Block::default()).border_style(style_border())), - cols[2], + cols[1], ); - f.render_widget(Paragraph::new(help).style(style_dim()), cols[3]); + f.render_widget(Paragraph::new(help).style(style_dim()), cols[2]); } fn draw_wallet_setup(f: &mut Frame, setup: &WalletSetup) { @@ -5825,7 +5827,13 @@ mod wallet_store_tests { /// What the real render path puts on an 80x24 terminal — `App::draw`, not a /// stand-in widget. fn frame_text(app: &App) -> String { - let mut term = ratatui::Terminal::new(ratatui::backend::TestBackend::new(80, 24)) + frame_at(app, 80, 24) + } + + /// The same real render path on any terminal size, so a screen that clips on + /// the standard frame is also checked where there is room to spare. + fn frame_at(app: &App, width: u16, height: u16) -> String { + let mut term = ratatui::Terminal::new(ratatui::backend::TestBackend::new(width, height)) .expect("test terminal"); term.draw(|f| app.draw(f)).expect("draw"); let buf = term.backend().buffer().clone(); @@ -5839,6 +5847,32 @@ mod wallet_store_tests { out } + /// Whitespace-collapsed copy of the frame with its pane borders dropped, so a + /// sentence the renderer wrapped across rows still reads as the one string + /// that produced it (a border glyph between two rows would split it). + fn flattened(frame: &str) -> String { + frame + .chars() + .filter(|c| !BORDER_GLYPHS.contains(c)) + .collect::() + .split_whitespace() + .collect::>() + .join(" ") + } + + /// The frame with its borders and its line breaks dropped and nothing else + /// touched: a value the renderer hard-wrapped (an address wider than the + /// pane) reads as the one string again. Whitespace cannot be collapsed here, + /// because that is what would re-split the wrapped value. + fn unwrapped(frame: &str) -> String { + frame + .chars() + .filter(|c| *c != '\n' && !BORDER_GLYPHS.contains(c)) + .collect() + } + + const BORDER_GLYPHS: [char; 6] = ['│', '┌', '┐', '└', '┘', '─']; + /// `F6` on an install with no wallet is a normal state, not a fatal one: the /// address call fails there by design. Propagating that `Err` ran out of /// `App::run` and out of `main`, so pressing the key killed the process. @@ -5876,11 +5910,9 @@ mod wallet_store_tests { /// it, and the note is rendered on the status line of the main view — which /// is where this screen's footer lives. /// - /// Not asserted here: the wallet screen's own body (`address` / `balance` / - /// `recent transfers`). `draw_wallet` renders that paragraph into a - /// `Constraint::Length(2)` slot whose borders consume both rows, so the body - /// is clipped away on every install, empty or not — a pre-existing defect - /// filed as its own card, outside this change's scope. + /// The wallet screen's own body (`address` / `balance` / `recent transfers`) + /// is pinned by the frame tests below, which used to show that body clipped + /// away on every install. #[test] fn f6_on_a_bare_install_never_draws_the_error_and_states_the_way_forward() { let dir = tempfile::tempdir().unwrap(); @@ -5934,6 +5966,108 @@ mod wallet_store_tests { app.status_note ); } + + /// The wallet screen's body is the point of the screen, and it used to be + /// clipped away on every install: `draw_wallet` rendered the paragraph into + /// a `Constraint::Length(2)` slot whose two borders ate both rows, leaving + /// the `Min(4)` slot above it blank. On a bare install the address line must + /// read `no address` — and must not be replaced by the node's refusal text. + #[test] + fn the_wallet_screen_draws_its_body_on_a_bare_install() { + let dir = tempfile::tempdir().unwrap(); + let (mut app, _rt) = app(&dir.path().join("home"), &[]); + app.handle_key(key(KeyCode::Esc)) + .expect("leave the create flow"); + // The same refusal `F6` swallows into a status note; it is an operator + // message for the endpoint, not the body of the screen. + let refusal = app + .rt + .block_on(app.node.wallet_receive_address()) + .expect_err("an install with no wallet has no receive address"); + app.handle_key(key(KeyCode::F(6))).expect("F6"); + + for (width, height) in [(80, 24), (120, 40), (200, 60)] { + let frame = frame_at(&app, width, height); + let flat = flattened(&frame); + for needle in [ + "address", + "no address", + "balance", + "recent transfers", + "(none)", + "Esc back", + ] { + assert!( + flat.contains(needle), + "the wallet body is missing {needle:?} at {width}x{height}:\n{frame}" + ); + } + assert!( + !flat.contains(&flattened(&refusal)), + "the node's refusal must not stand in for the body at {width}x{height}:\n{frame}" + ); + } + } + + /// A configured install: the address the node hands over is what the screen + /// shows, on the standard frame and on a wide one. The address is longer than + /// 80 columns, so the standard case also pins that its wrap is not a loss. + #[test] + fn the_wallet_screen_shows_the_filled_address() { + let dir = tempfile::tempdir().unwrap(); + let (mut app, _rt) = app(&dir.path().join("home"), &[("onionwire", "lance")]); + // Same documented mainnet standard address `tests/wallet.rs` uses. + let addr = "4AdUndXHHZ6cfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYTRj5UzqtReoS44qo9mtmXCqY45DJ852K5Jv2684Rge"; + app.node + .set_self_profile("", "", addr) + .expect("set profile"); + app.handle_key(key(KeyCode::Esc)).expect("leave the list"); + app.handle_key(key(KeyCode::F(6))).expect("F6"); + + let Screen::Wallet { receive_addr, .. } = &app.screen else { + panic!("F6 must open the wallet screen"); + }; + assert_eq!(receive_addr, addr); + + for (width, height) in [(80, 24), (200, 60)] { + let frame = frame_at(&app, width, height); + let flat = flattened(&frame); + assert!( + unwrapped(&frame).contains(addr), + "the receive address must be on screen at {width}x{height}:\n{frame}" + ); + assert!( + flat.contains("recent transfers"), + "the body must run to the transfers section at {width}x{height}:\n{frame}" + ); + assert!( + frame.contains("Esc back"), + "the help line must survive the taller body at {width}x{height}:\n{frame}" + ); + } + } + + /// An empty list is a fact the screen states, not a section it drops: the + /// transfers heading and its `(none)` row used to be off screen entirely. + #[test] + fn an_empty_transfer_list_still_names_recent_transfers() { + let dir = tempfile::tempdir().unwrap(); + let (mut app, _rt) = app(&dir.path().join("home"), &[("onionwire", "lance")]); + app.screen = Screen::Wallet { + receive_addr: "4AdUndXHHZ6cfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYTRj5UzqtReoS44qo9mtmXCqY45DJ852K5Jv2684Rge".into(), + balance: "0.000000000000".into(), + transfers: Vec::new(), + qr_modal: None, + }; + + for (width, height) in [(80, 24), (120, 40)] { + let frame = frame_at(&app, width, height); + assert!( + flattened(&frame).contains("recent transfers (none)"), + "an empty history must still be named at {width}x{height}:\n{frame}" + ); + } + } } /// The optional seed-offset step sits between the pasted seed and the wallet-file -- 2.52.0