diff --git a/src/tui.rs b/src/tui.rs index 93f94f6..4cde9b7 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -1380,16 +1380,14 @@ fn function_key_for(screen: &Screen, code: KeyCode) -> Option { impl App { fn new(node: Arc, rt: tokio::runtime::Handle) -> Result { let friends = node.list_friends()?; - // A fresh install has no wallet to pick and nothing to warn about yet, - // so it starts on the main view. The spend-authority warning is not - // weakened by this: every path where a user commits to creating or - // restoring a wallet (`/wallet create`, F6 `c`, the list's create row) - // still routes into `WalletSetup::CreateWarn`. An install that already - // has wallets starts on the list, so a restart lands on the wallets it - // remembers. A catalogue that cannot be read is the screen's own error - // state (the create row still works there). + // First run is the create flow, not an empty list to pick from; an + // install that already has wallets starts on the list, so a restart + // lands on the wallets it remembers. A catalogue that cannot be read is + // the screen's own error state (the create row still works there). let screen = match node.list_wallets() { - Ok(rows) if rows.is_empty() => Screen::Main, + Ok(rows) if rows.is_empty() => Screen::WalletSetup(WalletSetup::CreateWarn { + typed: String::new(), + }), Ok(rows) => Screen::WalletSelect { state: WalletSelectState::from_rows(wallet_rows(rows)), }, @@ -5689,90 +5687,18 @@ mod wallet_store_tests { .collect::>() } - fn key(code: KeyCode) -> KeyEvent { - KeyEvent::new(code, KeyModifiers::NONE) - } - - /// The frame the real `App::draw` path puts on a terminal of this size. - fn frame_on(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(); - let mut drawn = String::new(); - for y in 0..buf.area.height { - for x in 0..buf.area.width { - drawn.push_str(buf[(x, y)].symbol()); - } - drawn.push('\n'); - } - drawn - } - - /// The first frame on the standard 80x24 terminal. - fn first_frame(app: &App) -> String { - frame_on(app, 80, 24) - } - - /// Whitespace-collapsed copy of some drawn text, so a sentence the renderer - /// wrapped across lines still reads as the one string that produced it. - fn flattened(text: &str) -> String { - text.split_whitespace().collect::>().join(" ") - } - - /// 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 - /// the second half reads the first frame the app actually renders. + /// Nothing remembered means there is no list to choose from: the first run + /// goes straight to the existing creation flow. #[test] - fn a_fresh_install_starts_on_main_not_the_spend_warning() { + fn an_install_with_no_wallet_starts_on_the_create_flow() { let dir = tempfile::tempdir().unwrap(); let (app, _rt) = app(&dir.path().join("home"), &[]); - assert!( - matches!(app.screen, Screen::Main), - "a first run must start on the main view" - ); - - let frame = first_frame(&app); - assert!( - !flattened(&frame).contains(&flattened(wallet::SPEND_AUTHORITY_WARNING)), - "the spend-authority warning must not be on the first frame:\n{frame}" - ); - } - - /// 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. - #[test] - fn the_create_flow_is_still_reachable_and_still_warns() { - let dir = tempfile::tempdir().unwrap(); - let (mut app, _rt) = app(&dir.path().join("home"), &[]); - assert!(matches!(app.screen, Screen::Main)); - - for c in "/wallet create".chars() { - app.handle_key(key(KeyCode::Char(c))).expect("typed key"); - } - app.handle_key(key(KeyCode::Enter)).expect("enter"); - assert!( matches!( app.screen, Screen::WalletSetup(WalletSetup::CreateWarn { .. }) ), - "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); - assert!( - flattened(&narrow).contains("trust."), - "the create flow must warn on the standard frame:\n{narrow}" - ); - let wide = frame_on(&app, 200, 60); - assert!( - flattened(&wide).contains(&flattened(wallet::SPEND_AUTHORITY_WARNING)), - "the spend-authority warning must be drawn on the create flow:\n{wide}" + "a first run must start on the create flow" ); } @@ -5865,10 +5791,7 @@ mod wallet_store_tests { let dir = tempfile::tempdir().unwrap(); let home = dir.path().join("home"); let (mut app, _rt) = app(&home, &[]); - assert!( - matches!(app.screen, Screen::Main), - "a fresh install starts on the main view" - ); + assert!(matches!(app.screen, Screen::WalletSetup(_))); assert!( app.node.list_wallets().expect("list wallets").is_empty(), "nothing to list yet"