diff --git a/src/tui.rs b/src/tui.rs index 4cde9b7..34a8843 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -2019,31 +2019,8 @@ 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> { - // 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 addr = self.rt.block_on(self.node.wallet_receive_address())?; 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 { @@ -5817,123 +5794,6 @@ 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 @@ -6135,19 +5995,19 @@ mod wallet_offset_tests { "a prefix is not the word" ); - // 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 + // 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 // full word gets that far. assert!( app.status_note.is_none(), "a prefix must not run any import side effect" ); - app.handle_key(key(KeyCode::Char('n'))) - .expect("SEEN must open the wallet screen"); + let err = app + .handle_key(key(KeyCode::Char('n'))) + .expect_err("SEEN must attempt to open the wallet"); assert!( - matches!(app.screen, Screen::Wallet { .. }), - "only the full word proceeds" + err.contains("receive address") || err.to_ascii_lowercase().contains("not configured"), + "expected the open to fail on the missing wallet, got {err}" ); } }