Merge branch 'onionwire/t_6aa61cf8-onionwire-tui-a-fresh-install-must-not-o' into onionwire/t_bc0e7ddc-onionwire-docs-readme-and-the-payment-pl
Some checks failed
ci / test (pull_request) Failing after 44s
ci / sdk (pull_request) Successful in 1m17s
ci / fuzz (pull_request) Successful in 5m6s
android-ci / android (pull_request) Has been cancelled

This commit is contained in:
sirius 2026-09-27 18:11:53 +00:00
commit 4b48840d1a
2 changed files with 1276 additions and 32 deletions

1079
docs/tui-wallet-ux-review.md Normal file

File diff suppressed because it is too large Load diff

View file

@ -2324,8 +2324,31 @@ impl App {
Ok(())
}
/// What `F6` says on an install it cannot name a receive address for. It
/// points at this screen's own create/import keys, which exist today, rather
/// than at the in-TUI setup screen (a sibling card's work that may not have
/// landed yet): the note has to be true on every install that renders it.
const WALLET_SETUP_NOTE: &str =
"no wallet configured · c create or i import, or set ONIONWIRE_WALLET_RPC";
fn open_wallet(&mut self) -> Result<(), String> {
let addr = self.rt.block_on(self.node.wallet_receive_address())?;
// An install with no wallet is a normal state on this screen, not a
// fatal one: `F9` already degrades the same call to an empty address.
// Propagating the `Err` here ran out of `App::run` and out of `main`, so
// pressing `F6` killed the process.
let addr = match self.rt.block_on(self.node.wallet_receive_address()) {
Ok(addr) => addr,
Err(_) => {
self.status_note = Some(if self.node.wallet_status().configured {
// Configured but the call failed: the endpoint is what is
// wrong, not the absence of a wallet.
wallet::NOT_CONNECTED_MSG.to_string()
} else {
Self::WALLET_SETUP_NOTE.to_string()
});
String::new()
}
};
let balance = self.rt.block_on(self.node.wallet_balance());
let transfers = self.rt.block_on(self.node.wallet_recent_transfers(8)).unwrap_or_default();
self.screen = Screen::Wallet {
@ -4159,10 +4182,13 @@ fn draw_passphrase(f: &mut Frame, kind: BackupKind, second: bool, buf: &str) {
/// tail. Every modal goes through this one, so a popup can never punch through
/// the chrome underneath it and can never be wider than the frame.
///
/// Width always keeps a one-cell margin on each side. Height keeps the margin
/// only when the frame can afford it: a 22-line body on a 24-row terminal needs
/// the rows more than it needs symmetry, and the scroll below still lands the
/// last line on screen.
/// Width always keeps a one-cell margin on each side. Height is the body's
/// **wrapped** row count plus the border rows, not its logical line count: one
/// long sentence is three rows on an 80-column terminal, and sizing from the
/// line count used to leave the popup 4 rows tall and scroll the head of that
/// sentence away (`SPEND_AUTHORITY_WARNING`, 184 chars on one line). The frame
/// still caps the height, and only a body that cannot fit the frame at all
/// scrolls — to its tail, so the closing instruction is what stays on screen.
pub fn draw_text_overlay(f: &mut Frame, title: &str, text: &str) {
let area = f.area();
let wanted_w = text
@ -4171,9 +4197,21 @@ pub fn draw_text_overlay(f: &mut Frame, title: &str, text: &str) {
.max()
.unwrap_or(40)
.saturating_add(4);
let wanted_h = text.lines().count() as u16 + 2;
let max_w = area.width.saturating_sub(2).max(10);
let width = (wanted_w as u16).clamp(10, max_w.max(10)).min(area.width);
let inner_w = width.saturating_sub(2).max(1);
let wrapped: u16 = text
.lines()
.map(|l| {
let n = cell_width(l) as u16;
if n == 0 {
1
} else {
n.div_ceil(inner_w)
}
})
.sum();
let wanted_h = wrapped.saturating_add(2);
let height = if wanted_h >= area.height.saturating_sub(1) {
area.height
} else {
@ -4187,19 +4225,7 @@ pub fn draw_text_overlay(f: &mut Frame, title: &str, text: &str) {
};
f.render_widget(Clear, area);
f.render_widget(Clear, popup);
let inner_w = popup.width.saturating_sub(2).max(1);
let inner_h = popup.height.saturating_sub(2);
let wrapped: u16 = text
.lines()
.map(|l| {
let n = cell_width(l) as u16;
if n == 0 {
1
} else {
n.div_ceil(inner_w)
}
})
.sum();
let scroll = wrapped.saturating_sub(inner_h);
f.render_widget(
Paragraph::new(text)
@ -6201,6 +6227,19 @@ mod wallet_store_tests {
text.split_whitespace().collect::<Vec<_>>().join(" ")
}
/// The drawn frame with the popup's box-drawing cells blanked out: the side
/// borders sit between a wrapped sentence's two rows and are chrome, not
/// copy. Without this, a warning split over two rows reads as
/// `…do not <border> trust.` and no whole-sentence assertion can pass.
fn unframed(text: &str) -> String {
text.chars()
.map(|c| match c {
'\u{2502}' | '\u{250c}' | '\u{2510}' | '\u{2514}' | '\u{2518}' | '\u{2500}' => ' ',
other => other,
})
.collect()
}
/// Nothing remembered means nothing to warn about: a first run opens on the
/// main view, not on the create flow's spend-authority warning. Asserting
/// the screen alone would pass with the warning merely drawn behind Main, so
@ -6222,8 +6261,11 @@ mod wallet_store_tests {
}
/// Moving the entry point did not weaken the warning: `/wallet create` on a
/// fresh install still lands on `CreateWarn`, and the frame really carries
/// the spend-authority copy.
/// fresh install still lands on `CreateWarn`, and the standard 80x24 frame
/// carries the *whole* spend-authority sentence — the popup grows to the
/// body's wrapped rows instead of scrolling the head of it off screen. The
/// whole-sentence assertion used to need a 200x60 frame because of that
/// scroll; it belongs on the standard terminal.
#[test]
fn the_create_flow_is_still_reachable_and_still_warns() {
let dir = tempfile::tempdir().unwrap();
@ -6242,13 +6284,19 @@ mod wallet_store_tests {
),
"the create command must still warn before anything is created"
);
// The overlay is taller than its body and scrolls to its tail, so the
// 80x24 frame carries only the warning's closing words; the whole
// sentence needs a frame wide enough to hold it on one row.
let narrow = first_frame(&app);
// Dumped for `cargo test --lib tui:: -- --nocapture`; this frame is the
// evidence that the whole warning, not just its tail, is on screen.
println!("{narrow}");
let copy = flattened(&unframed(&narrow));
assert!(
flattened(&narrow).contains("trust."),
"the create flow must warn on the standard frame:\n{narrow}"
copy.contains(&flattened(wallet::SPEND_AUTHORITY_WARNING)),
"the spend-authority warning must be readable on the standard 80x24 \
frame, not just its tail:\n{narrow}"
);
assert!(
copy.contains("Type SPEND to confirm"),
"the confirmation prompt must be on screen with the warning:\n{narrow}"
);
let wide = frame_on(&app, 200, 60);
assert!(
@ -6375,6 +6423,123 @@ mod wallet_store_tests {
);
assert_eq!(app.status_note.as_deref(), Some("opened wallet fresh"));
}
fn key(code: KeyCode) -> KeyEvent {
KeyEvent::new(code, KeyModifiers::NONE)
}
/// 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))
.expect("test terminal");
term.draw(|f| app.draw(f)).expect("draw");
let buf = term.backend().buffer().clone();
let mut out = String::new();
for y in 0..buf.area.height {
for x in 0..buf.area.width {
out.push_str(buf[(x, y)].symbol());
}
out.push('\n');
}
out
}
/// `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.
#[test]
fn f6_on_a_bare_install_opens_the_wallet_screen_instead_of_exiting() {
let dir = tempfile::tempdir().unwrap();
let (mut app, _rt) = app(&dir.path().join("home"), &[]);
// A first run opens on the create flow; the key in the bug report is
// pressed from the main view (`Esc` leaves the create prompt, and is
// harmless once a fresh install starts on `Main` itself).
app.handle_key(key(KeyCode::Esc))
.expect("leave the create flow");
assert!(matches!(app.screen, Screen::Main));
app.handle_key(key(KeyCode::F(6)))
.expect("F6 must not fail on an install with no wallet");
let Screen::Wallet { receive_addr, .. } = &app.screen else {
panic!("F6 must open the wallet screen");
};
assert!(
receive_addr.is_empty(),
"the field must be empty, not the error text: {receive_addr:?}"
);
assert!(
app.status_note
.as_deref()
.is_some_and(|n| n.contains("no wallet configured")),
"the screen must name the way forward: {:?}",
app.status_note
);
}
/// The frame the user actually gets. The node's error string never reaches
/// 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.
#[test]
fn f6_on_a_bare_install_never_draws_the_error_and_states_the_way_forward() {
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");
app.handle_key(key(KeyCode::F(6))).expect("F6");
let wallet_frame = frame_text(&app);
assert!(
wallet_frame.contains("wallet") && wallet_frame.contains("Esc back"),
"the F6 screen must be what is on screen: {wallet_frame}"
);
assert!(
!wallet_frame.contains("no receive address"),
"the node's error must not reach the screen: {wallet_frame}"
);
app.handle_key(key(KeyCode::Esc)).expect("back to main");
assert!(matches!(app.screen, Screen::Main));
let main_frame = frame_text(&app);
assert!(
main_frame.contains("no wallet configured"),
"the note must be rendered, not only stored: {main_frame}"
);
}
/// The control: when the node can name an address, `F6` fills the screen
/// with it exactly as before — no note, no empty field.
#[test]
fn f6_on_an_install_with_a_wallet_still_fills_the_receive_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");
assert!(matches!(app.screen, Screen::Main));
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);
assert!(
app.status_note.is_none(),
"an address is no reason to warn: {:?}",
app.status_note
);
}
}
/// The optional seed-offset step sits between the pasted seed and the wallet-file
@ -6576,19 +6741,19 @@ mod wallet_offset_tests {
"a prefix is not the word"
);
// The fourth letter is the one that proceeds: it opens the wallet, and
// this install has none, so the open is what fails. Nothing before the
// The fourth letter is the one that proceeds: it opens the wallet. This
// install has none, so the screen opens address-less — the open itself
// must not fail (the same degradation `F6` needs). Nothing before the
// full word gets that far.
assert!(
app.status_note.is_none(),
"a prefix must not run any import side effect"
);
let err = app
.handle_key(key(KeyCode::Char('n')))
.expect_err("SEEN must attempt to open the wallet");
app.handle_key(key(KeyCode::Char('n')))
.expect("SEEN must open the wallet screen");
assert!(
err.contains("receive address") || err.to_ascii_lowercase().contains("not configured"),
"expected the open to fail on the missing wallet, got {err}"
matches!(app.screen, Screen::Wallet { .. }),
"only the full word proceeds"
);
}
}