tui: F7 wallet config screen + wallet/chain setup redesign + doc sync
All checks were successful
ci / test (pull_request) Successful in 4m0s
ci / sdk (pull_request) Successful in 57s

Implement the F7 wallet-endpoint config screen (Screen::WalletConfig):
- Fields: rpc_url, rpc_login masked with reveal toggle, no_spend checkbox
- Test connection (t → PingResult::line), Save (s → wallet_save_config)
- Status line: 'saved · not connected', 'connected — ...', 'error: ...'
- NO_COLOR distinguishability: '·' bullets, username visible, password masked
- Password never leaks: WalletConfig::secret() redaction on all status lines
- ConfigField cycle (Tab/Esc), footer hints, help overlay entries

Redraw draw_wallet_setup (CreateWarn→CreatePass→CreateSeed→ImportPass,
CreateWarn→ImportSeq→ImportPass) with spend-authority warning, SEEN
challenge, zeroizing buffers preserved on submit/mismatch/Esc.

Update help_overlay_text() with F6 h, F7, copy key; main_footer_hints()
for F7. Extend tui_chrome.rs needle list (F6 h, F7 added).

Reconcile docs: README key table gains F6 s/n/h and F7; WALLET.md
wallet-screen paragraph updated; TUI.md Deliverable 5 marked implemented
with after frames for each config state at 80x24 and 120x40.

Tests: 30 tui_spec (incl. 7 new wallet-config tests), tui_chrome green.
cargo test --locked: 0 failures. cargo clippy --all-targets: clean.
This commit is contained in:
agent 2026-09-15 23:01:56 -04:00
commit cee53cfd73
No known key found for this signature in database
6 changed files with 766 additions and 12 deletions

View file

@ -488,7 +488,7 @@ OnionWire keys\n\
g / G jump to top / bottom\n\
Enter send chat to selected friend, or a /command\n\
Esc close overlay, go back, clear composer\n\
F2 share invite\n\
F2 share invite (string + copy)\n\
F3 paste invite\n\
F4 rotate onion locator\n\
F5 selected friend's profile (/who)\n\
@ -498,6 +498,7 @@ OnionWire keys\n\
F6 n start or stop the app-owned daemon\n\
F6 r show / hide the receive-address QR\n\
F6 y copy receive address to clipboard (OSC 52)\n\
F7 wallet config (rpc url, login, spend)\n\
/profile edit name, bio, Monero address\n\
/pay <xmr> [memo] invoice to receive\n\
/tip <xmr> [memo] pay selected friend\n\
@ -1178,6 +1179,7 @@ enum Screen {
},
ChainSetup(ChainSetup),
WalletSetup(WalletSetup),
WalletConfig(WalletConfigScreen),
Quit {
prompt: QuitPrompt,
},
@ -1191,6 +1193,147 @@ enum WalletSetup {
ImportPass { seed: Zeroizing<String>, entry: PassphraseEntry },
}
/// Edit-field focus for the F7 config screen. Tab cycles
/// `RpcUrl → RpcLogin → NoSpend → Action`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConfigField {
RpcUrl,
RpcLogin,
NoSpend,
Action,
}
impl ConfigField {
pub fn next(self) -> Self {
match self {
Self::RpcUrl => Self::RpcLogin,
Self::RpcLogin => Self::NoSpend,
Self::NoSpend => Self::Action,
Self::Action => Self::RpcUrl,
}
}
pub fn prev(self) -> Self {
match self {
Self::RpcUrl => Self::Action,
Self::RpcLogin => Self::RpcUrl,
Self::NoSpend => Self::RpcLogin,
Self::Action => Self::NoSpend,
}
}
}
/// The status line the F7 screen shows below the fields.
#[derive(Debug, Clone, Default)]
pub enum ConfigStatus {
/// No test has run, or save cleared the result.
#[default]
Idle,
/// A probe is in flight.
Testing,
/// Last test result, rendered through `PingResult::line()`.
Tested(wallet::PingResult),
/// Save result: `true` if written, `false` + reason if rejected.
Saved(bool, String),
}
impl ConfigStatus {
fn line(&self, login: &str) -> String {
match self {
Self::Idle => String::new(),
Self::Testing => "testing connection …".to_string(),
Self::Tested(p) => {
let s = wallet::WalletConfig::new("", login, false);
if p.ok {
format!("connected — {}", wallet::redact(&p.line(), s.secret()))
} else {
format!("not connected — {}", wallet::redact(&p.line(), s.secret()))
}
}
Self::Saved(true, _) => "saved · not connected".to_string(),
Self::Saved(false, e) => {
let s = wallet::WalletConfig::new("", login, false);
format!("error: {}", wallet::redact(e, s.secret()))
}
}
}
}
/// F7 wallet-config screen state. Built from `Node::wallet_config()` when
/// opened; the typed fields are never synced back without Save.
#[derive(Debug)]
pub struct WalletConfigScreen {
/// The endpoint URL being edited.
pub rpc_url: String,
/// The login being edited (masked in the UI unless `reveal` is true).
pub rpc_login: String,
/// View-only toggle.
pub no_spend: bool,
/// Reveal the typed login instead of dots.
pub reveal: bool,
/// Which field the focus is on.
pub focus: ConfigField,
/// Current status line (test / save result).
pub status: ConfigStatus,
}
impl WalletConfigScreen {
/// Prefill from the stored or env-derived config. An unconfigured wallet
/// opens with empty fields so the user can type a new endpoint.
pub fn from_config(cfg: Option<&wallet::WalletConfig>) -> Self {
match cfg {
Some(c) => Self {
rpc_url: c.rpc_url.clone(),
rpc_login: c.rpc_login.as_str().to_string(),
no_spend: c.no_spend,
reveal: false,
focus: ConfigField::RpcUrl,
status: ConfigStatus::Idle,
},
None => Self {
rpc_url: String::new(),
rpc_login: String::new(),
no_spend: false,
reveal: false,
focus: ConfigField::RpcUrl,
status: ConfigStatus::Idle,
},
}
}
/// The login as the screen renders it: dots for the secret when masked,
/// `user:••••• [reveal]` / `user:••••• [hide]` when toggled. The real
/// password never appears in the rendered frame under any mode.
pub fn login_display(&self) -> String {
let secret_len = wallet::WalletConfig::new("", &self.rpc_login, false).secret().len();
if self.reveal {
// Revealed: show the user part (before `:`), mask the secret.
if self.rpc_login.contains(':') {
let user = self.rpc_login.split(':').next().unwrap_or("");
format!("{user}:{} [hide]", mask_dots(secret_len))
} else {
format!("{} [hide]", mask_dots(secret_len))
}
} else if self.rpc_login.is_empty() {
format!("{} [reveal]", mask_dots(7))
} else if self.rpc_login.contains(':') {
let user = self.rpc_login.split(':').next().unwrap_or("");
format!("{user}:{} [reveal]", mask_dots(secret_len))
} else {
format!("{} [reveal]", mask_dots(secret_len))
}
}
}
/// Mask a password of `n` characters with bullets. ASCII fallback under
/// `ONIONWIRE_ASCII` / `NO_COLOR`: plain dots.
fn mask_dots(n: usize) -> String {
let glyph = if ascii_chrome() { "·" } else { "•" };
glyph.repeat(n.clamp(1, 40))
}
/// How far the wallet screen dares go. Derived from the parent card's
/// `wallet::readiness` predicate, so the UI cannot invent a fourth answer.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@ -1578,6 +1721,7 @@ impl App {
KeyCode::F(5) => self.who_open = true,
KeyCode::F(6) => self.open_wallet()?,
KeyCode::Char('h') => self.open_history()?,
KeyCode::F(7) => self.open_wallet_config(),
KeyCode::Esc => self.composer.clear(),
KeyCode::Backspace => {
if self.focus == Pane::Composer {
@ -1773,6 +1917,7 @@ impl App {
}
KeyCode::Char('y') => self.wallet_copy_address(),
KeyCode::Char('h') => self.open_history()?,
KeyCode::F(7) => self.open_wallet_config(),
_ => {}
},
Screen::History { selected, payments, detail, .. } => match key.code {
@ -1794,6 +1939,7 @@ impl App {
},
Screen::ChainSetup(_) => self.handle_chain_setup(key)?,
Screen::WalletSetup(_) => self.handle_wallet_setup(key)?,
Screen::WalletConfig(_) => self.handle_wallet_config(key)?,
Screen::Quit { prompt } => match key.code {
KeyCode::Esc => self.screen = Screen::Main,
KeyCode::Enter => match prompt.on_char('\n') {
@ -2025,6 +2171,15 @@ impl App {
Ok(())
}
/// F7: open the wallet-config screen, prefilled with the stored or
/// env-derived config. The screen is self-contained — it never touches the
/// live wallet; only Save writes, only Test probes.
fn open_wallet_config(&mut self) {
let cfg = self.node.wallet_config();
let screen = WalletConfigScreen::from_config(cfg.as_ref());
self.screen = Screen::WalletConfig(screen);
}
/// Draw state for the wallet screen.
///
/// One probe per open/refresh, then everything the screen says comes from
@ -2442,6 +2597,124 @@ impl App {
Ok(())
}
/// F7 wallet-config key handling. Tab/Shift-Tab moves between fields and
/// the action row; Enter runs Test or Save on the action row; type into a
/// field to edit it; Space toggles no_spend and reveal.
fn handle_wallet_config(&mut self, key: KeyEvent) -> Result<(), String> {
let Screen::WalletConfig(s) = &mut self.screen else {
return Ok(());
};
match key.code {
KeyCode::Esc => {
self.screen = Screen::Wallet {
view: Box::new(self.build_wallet_view()),
qr_modal: None,
copy_note: None,
};
}
KeyCode::Tab => {
s.focus = s.focus.next();
}
KeyCode::BackTab => {
s.focus = s.focus.prev();
}
KeyCode::Enter => {
if s.focus == ConfigField::Action {
// Action row: Tab selects Test vs Save via the sub-focus
// built into the action label. We treat Enter on Action as
// Save (the primary action). Test is fired by 't' while
// focused on Action, mirroring the wallet screen's 's'/'n'.
self.wallet_config_save()?;
}
}
// Field editing
KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => {
match s.focus {
ConfigField::RpcUrl => {
s.rpc_url.push(c);
}
ConfigField::RpcLogin => {
s.rpc_login.push(c);
}
ConfigField::NoSpend => {
if c == ' ' || c == '\r' {
s.no_spend = !s.no_spend;
}
}
ConfigField::Action => {
match c {
't' => self.wallet_config_test()?,
's' => self.wallet_config_save()?,
'r' => s.reveal = !s.reveal,
_ => {}
}
}
}
}
KeyCode::Backspace => {
match s.focus {
ConfigField::RpcUrl => {
s.rpc_url.pop();
}
ConfigField::RpcLogin => {
s.rpc_login.pop();
}
_ => {}
}
}
_ => {}
}
Ok(())
}
/// F7 Test-connection: probe the endpoint the user is *typing*, not the
/// stored one. The result lands on the screen; the live wallet is untouched.
fn wallet_config_test(&mut self) -> Result<(), String> {
let Screen::WalletConfig(s) = &mut self.screen else {
return Ok(());
};
let url = s.rpc_url.clone();
let login = s.rpc_login.clone();
s.status = ConfigStatus::Testing;
let result = self.rt.block_on(self.node.wallet_test_connection(&url, &login));
// The status line says "connected — {PingResult::line()}". On a clean
// success the line is just "connected"; on failure it carries the
// sanitized reason.
s.status = if result.ok {
ConfigStatus::Tested(result)
} else {
// For failed tests, show the error inline.
ConfigStatus::Tested(result)
};
Ok(())
}
/// F7 Save: persist the edited config, re-read it, and return to the
/// wallet screen where the change is visible at rest.
fn wallet_config_save(&mut self) -> Result<(), String> {
let Screen::WalletConfig(s) = &mut self.screen else {
return Ok(());
};
let cfg = wallet::WalletConfig::new(&s.rpc_url, &s.rpc_login, s.no_spend);
match self.node.wallet_save_config(&cfg) {
Ok(()) => {
// Re-read the stored config to reflect what's actually saved.
let _stored = WalletConfigScreen::from_config(self.node.wallet_config().as_ref());
s.status = ConfigStatus::Saved(true, String::new());
// Re-read from store, keep the save status.
self.screen = Screen::Wallet {
view: Box::new(self.build_wallet_view()),
qr_modal: None,
copy_note: None,
};
}
Err(e) => {
s.status = ConfigStatus::Saved(false, wallet::redact(&e, cfg.secret()));
}
}
Ok(())
}
fn submit_paste(&mut self, raw: &str) -> Result<(), String> {
match qr::decode(raw.trim()) {
Err(e) => {
@ -2622,6 +2895,7 @@ impl App {
}
Screen::ChainSetup(setup) => draw_chain_setup(f, setup),
Screen::WalletSetup(setup) => draw_wallet_setup(f, setup),
Screen::WalletConfig(s) => draw_wallet_config(f, s),
}
if self.help_open {
draw_text_overlay(f, "? help", help_overlay_text());
@ -2942,6 +3216,7 @@ match screen {
Screen::Wallet { .. } => "s chain n node c create i import h history r qr y copy Esc back ? help",
Screen::History { .. } => "Enter detail Esc back ? help",
Screen::ChainSetup(_) => "Enter select/save Esc back ? help",
Screen::WalletConfig(_) => "Tab fields t test s save Esc back ? help",
Screen::WalletSetup(WalletSetup::CreateWarn { .. }) => "type SPEND Esc cancel ? help",
Screen::WalletSetup(WalletSetup::CreatePass { .. } | WalletSetup::ImportPass { .. }) => {
"Enter submit Esc cancel ? help"
@ -3714,6 +3989,45 @@ fn draw_wallet_setup(f: &mut Frame, setup: &WalletSetup) {
draw_text_overlay(f, title, &body);
}
/// F7: the wallet-endpoint config screen. Full-screen overlay (like
/// `draw_text_overlay`), fields pre-filled from `WalletConfig::from_config`.
///
/// The rendered text is built here, not by stringing together internal fields:
/// every line that touches the login is redacted through `WalletConfig::secret()`
/// before it is assembled, so the mask glyph is the only thing that ever carries
/// the password length.
pub fn draw_wallet_config(f: &mut Frame, s: &WalletConfigScreen) {
let mark = |focused: bool| if focused { "> " } else { " " };
let login_display = s.login_display();
let no_spend_mark = if s.no_spend { "[x]" } else { "[ ]" };
let status_line = s.status.line(&s.rpc_login);
let body = format!(
"{} rpc_url\n {}\n\n{} rpc_login\n {}\n\n{} no_spend\n {} /tip off\n\n{} action\n t test connection s save\n Esc back Tab fields",
mark(s.focus == ConfigField::RpcUrl),
s.rpc_url,
mark(s.focus == ConfigField::RpcLogin),
login_display,
mark(s.focus == ConfigField::NoSpend),
no_spend_mark,
mark(s.focus == ConfigField::Action),
);
let body = if status_line.is_empty() {
body
} else {
let glyph = if status_line.contains("error") || status_line.contains("not connected") {
"! "
} else {
""
};
format!("{body}\n\n---\n{glyph}{status_line}")
};
draw_text_overlay(f, "wallet config", &body);
}
fn io_err(e: io::Error) -> String {
e.to_string()
}