tui: F7 wallet setup — RPC endpoint and chain source on screen
All checks were successful
android-ci / android (pull_request) Successful in 10m33s
ci / test (pull_request) Successful in 6m53s
ci / sdk (pull_request) Successful in 1m33s
ci / fuzz (pull_request) Successful in 5m4s

`wallet::NOT_CONFIGURED_MSG` has always said "open F7 to set it up" and there
was no F7. This is that screen.

- `FunctionKey::Setup` on `F7`, live on Main, the settings menu and peer
  payments, same invariant `F9` follows.
- `Screen::WalletSetupConfig` carries `WalletSetupConfigState`: a snapshot of
  plain data taken when the screen opens, never a handle onto `Node`.
- Rows: the wallet RPC endpoint and its login (never rendered back — the row
  says `hidden · set`, `Debug` redacts it), the view-only toggle, and a chain
  picker over all four `ChainSource` cases with their own fields.
- `Node::set_remote_daemon` / `set_local_monerod` / `set_receive_only`, so the
  TUI can reach what only the Android API could, plus `F6`'s in-process source.
- An untouched chain row is not written, so an F7 save cannot silently undo the
  in-process choice; picking a remote daemon says who is trusted in the same
  frame, one line, lowercase.
- `Ctrl-T` tests the endpoint and shows the sanitized `PingResult::line()`.
  Saving never dials. A rejected form writes nothing — the node validates.
- Docs that claimed there is no F7 (`docs/TUI.md`, `docs/WALLET.md`) now
  describe the screen; the settings menu's `endpoint` row names the key.
This commit is contained in:
agent 2026-09-26 23:18:46 -04:00
commit a48d40bc4e
No known key found for this signature in database
4 changed files with 1335 additions and 22 deletions

View file

@ -26,12 +26,13 @@ ASCII chrome.
| `WalletSelect` | `F6` `w` | Saved wallets, pick one or create one | | `WalletSelect` | `F6` `w` | Saved wallets, pick one or create one |
| `WalletSetup` | `F6` `c` / `i`, or `/wallet create` / `import` | Spend warning, seed, optional seed-offset passphrase, import | | `WalletSetup` | `F6` `c` / `i`, or `/wallet create` / `import` | Spend warning, seed, optional seed-offset passphrase, import |
| `WalletsSettings` | `F9` or `/settings` | Discovery menu (does not replace F-keys) | | `WalletsSettings` | `F9` or `/settings` | Discovery menu (does not replace F-keys) |
| `WalletSetupConfig` | `F7` | Wallet RPC endpoint and chain source, editable |
| `PeerPayments` | F9 then `p` | Peer-scoped `/pay` / `/tip` history | | `PeerPayments` | F9 then `p` | Peer-scoped `/pay` / `/tip` history |
| `Quit` | `Ctrl-Q` | Type `CLEAR` or `QUIT` | | `Quit` | `Ctrl-Q` | Type `CLEAR` or `QUIT` |
Help (`?`) is an overlay, not a screen. `/who` / `F5` is an overlay on Main. Help (`?`) is an overlay, not a screen. `/who` / `F5` is an overlay on Main.
There is **no `F7`**. Function keys that fire from Main, the settings menu, and Function keys that fire from Main, the settings menu, and
peer-payments are: peer-payments are:
| Key | `FunctionKey` | Action | | Key | `FunctionKey` | Action |
@ -41,11 +42,13 @@ peer-payments are:
| `F4` | Rotate | Onion locator | | `F4` | Rotate | Onion locator |
| `F5` | Who | Selected friend's profile | | `F5` | Who | Selected friend's profile |
| `F6` | Wallet | Wallet screen | | `F6` | Wallet | Wallet screen |
| `F7` | Setup | Wallet RPC endpoint and chain source |
| `F8` | RotatePrekey | Prekey hard cut | | `F8` | RotatePrekey | Prekey hard cut |
| `F9` | OpenMenu | Wallets & settings | | `F9` | OpenMenu | Wallets & settings |
`F9` is live on Main, the settings menu, and peer-payments so a printed shortcut `F9` is live on Main, the settings menu, and peer-payments so a printed shortcut
never no-ops there. Other screens handle their own keys (Esc back, typed never no-ops there, and `F7` joins it for the same reason: `/settings` points at
the setup screen. Other screens handle their own keys (Esc back, typed
confirms). confirms).
## Main ## Main
@ -53,16 +56,21 @@ confirms).
Focus starts on the composer. Footer hints (`main_footer_hints`): Focus starts on the composer. Footer hints (`main_footer_hints`):
``` ```
Tab F2 F3 F4 F5 F6 F9 ? help Ctrl-Q Tab F2 F3 F4 F5 F6 F7 F9 ? help Ctrl-Q
``` ```
Pane-specific (`pane_footer_hints`): Pane-specific (`pane_footer_hints`):
| Pane | Hint | | Pane | Hint |
|---|---| |---|---|
| Roster | `j k select F3 add F6 wallet F9 settings ? help` | | Roster | `j k F3 add F6 wallet F7 setup F9 ? help` |
| Chat | `j k scroll g G ends F4 rotate F9 settings ? help` | | Chat | `j k g G ends F4 rotate F7 setup F9 ? help` |
| Composer | `Enter send / commands F9 settings ? help` | | Composer | `Enter send / commands F7 setup F9 ? help` |
The status line is drawn from the focused pane's hint, and the compactor drops
tokens from the front until the line fits, so a key that only appears in
`main_footer_hints` never reaches an 80-column terminal. `F7` is therefore named
in both, and the `F9` beside it is left bare so the whole hint still fits at 80.
| Key | Action | | Key | Action |
|---|---| |---|---|
@ -168,6 +176,45 @@ stored identity and locator are catalogue columns, not session state: a locator
rotates (`F4`) and identity is the roster key the node already holds, so the rotates (`F4`) and identity is the roster key the node already holds, so the
live header keeps reading them from the node. live header keeps reading them from the node.
## Wallet setup (`F7`)
Footer: `Esc back Enter save Ctrl-T test` (plus the status line's own `? help`).
The compactor drops tokens from the front, and at 80 columns the status line
leaves about 25 cells, so the tail is what the default terminal shows. `Tab` and
`?` are universal; `Ctrl-U` is named on the login row it clears.
Live from Main, the `F9` settings menu, and peer payments; the menu's `endpoint`
row names `F7` as the key that edits it. Body is `WalletSetupConfigState`, a
snapshot taken when the screen opens — the render path never reads the store.
Two things live here: the wallet RPC endpoint, and the chain source.
| Row | Kind | Notes |
|---|---|---|
| `url` | text | the wallet RPC endpoint |
| `login` | text | `user:pass`. Never rendered back: the row reads `hidden · set` or `(none)` |
| `view-only` | toggle | `no_spend`; `/tip` is refused before any dial |
| `chain` | picker | `space` cycles receive-only, local node, remote daemon, in-process |
| `daemon` | text | `host:port`, for the remote daemon |
| `monerod` | text | the binary this box spawns for a local node |
| `prune` | toggle | local and in-process sources |
`Enter` saves and answers on the status row: `saved · not dialled — ctrl-t tests`
`the endpoint`, or the node's own refusal in its own words. The endpoint is
validated by `Node::wallet_save_config` — loopback host, login required — and a
rejected form is rejected **before** it is written: nothing in the sealed record
moves and a running wallet is not re-dialled. `Ctrl-T` dials the endpoint and
answers with the sanitized `PingResult` line (never the password). `Ctrl-U`
clears the focused field, which is how a hidden login gets replaced.
The chain row is written only when it was changed. An untouched row leaves
whatever `F6`'s `1`/`2`/`3` picker stored, so opening `F7` to fix a port cannot
silently undo the in-process choice. Picking a remote daemon says so in the same
frame — `a daemon you do not run sees this wallet's chain traffic` — because that
is the pick that moves chain trust off this box. The address must parse as
`host:port` first.
Esc is the single exit and wipes the login buffer (`Zeroizing<String>`).
## Wallets & settings (`F9` / `/settings`) ## Wallets & settings (`F9` / `/settings`)
Discovery layer, not a replacement. Function keys stay live on this screen. Discovery layer, not a replacement. Function keys stay live on this screen.
@ -180,14 +227,14 @@ Rows name the shortcut they sit beside (`F6 c`, `F6 i`, `F6 r`, `F6 s/x`,
- `p` opens peer payment history for the selected friend (`Node::list_payments`). - `p` opens peer payment history for the selected friend (`Node::list_payments`).
- Esc back to Main. - Esc back to Main.
The menu **shows** endpoint state; it does not edit a stored RPC URL. The error The menu **shows** endpoint state; it does not edit it. The `endpoint` row names
copy for an unconfigured wallet still says “open F7” (`src/wallet.rs`); that `F7`, which is the key that opens `WalletSetupConfig` and the key the “open F7”
key does not exist. Set `ONIONWIRE_WALLET_RPC` or use `F6` create/import and copy in `src/wallet.rs` now points at — that error is no longer advice for a key
the child. that does not exist.
Chain source (binaries, remote host) is stored via `Node::set_wallet_child_config`. Chain source is stored via `Node::set_wallet_child_config`. `F6` keys
The desktop TUI's in-process picker is `F6` keys `1`/`2`/`3`. There is no `1`/`2`/`3` set the in-process source; `F7` sets any of the four, plus the
on-screen editor for an external RPC URL or a remote daemon host. external RPC URL and a remote daemon host.
## Peer payments (`F9` then `p`) ## Peer payments (`F9` then `p`)

View file

@ -207,10 +207,15 @@ Boot precedence: **stored config → env → disabled**. Stored config that cann
be used (non-loopback, `.onion`, missing login) is reported and falls back to be used (non-loopback, `.onion`, missing login) is reported and falls back to
env rather than dialling the bad endpoint. env rather than dialling the bad endpoint.
`Store::save_wallet_config` / `Node::wallet_save_config` exist. **No TUI screen `Store::save_wallet_config` / `Node::wallet_save_config` exist, and the `F7`
writes them.** There is no `F7`. The not-configured refusal still says screen (`WalletSetupConfig`) writes them: the endpoint, its login, and the chain
source. Nothing else does — `F6` and `F9` show state, the env vars are the
headless path. The not-configured refusal says
`wallet not configured — open F7 to set it up, or set ONIONWIRE_WALLET_RPC` `wallet not configured — open F7 to set it up, or set ONIONWIRE_WALLET_RPC`
(`src/wallet.rs`). Live surfaces: `F6`, `F9`, or the env vars. (`src/wallet.rs`), and that key is real.
A save validated by `Node::wallet_save_config` (loopback host, login required)
re-points the wallet without a restart; a rejected form writes nothing.
`/pay` and `/tip` run `wallet_readiness` before send: `/pay` and `/tip` run `wallet_readiness` before send:

View file

@ -669,6 +669,49 @@ impl Node {
self.set_wallet_child_config(&cfg) self.set_wallet_child_config(&cfg)
} }
/// Point the wallet child at a chain daemon the user runs elsewhere.
/// Same shape as [`Self::set_in_process_cuprate`]: read-modify-write on the
/// stored settings, an empty `wallet_rpc_bin` filled in, and validation
/// before anything is written. A `.onion` host needs no special case here —
/// the child pulls in the SOCKS proxy for it (`ChainSource::is_onion`).
pub fn set_remote_daemon(&self, host: &str, port: u16) -> Result<(), String> {
let mut cfg = self.wallet_child_config();
if cfg.wallet_rpc_bin.as_os_str().is_empty() {
cfg.wallet_rpc_bin = PathBuf::from("monero-wallet-rpc");
}
cfg.source = ChainSource::Remote {
host: host.trim().to_string(),
port,
};
self.set_wallet_child_config(&cfg)
}
/// Spawn a local `monerod`. Datadirs are split exactly as they are for the
/// in-process daemon so a pruned store cannot mix with a full one.
pub fn set_local_monerod(&self, monerod_bin: &Path, prune: bool) -> Result<(), String> {
let mut cfg = self.wallet_child_config();
if cfg.wallet_rpc_bin.as_os_str().is_empty() {
cfg.wallet_rpc_bin = PathBuf::from("monero-wallet-rpc");
}
cfg.source = ChainSource::Local {
monerod_bin: monerod_bin.to_path_buf(),
datadir: self
.home
.join("chain")
.join(if prune { "mainnet-pruned" } else { "mainnet-full" }),
prune,
};
self.set_wallet_child_config(&cfg)
}
/// Back to zero: no wallet child, no daemon, no spend. The way out of a
/// misconfigured chain source.
pub fn set_receive_only(&self) -> Result<(), String> {
let mut cfg = self.wallet_child_config();
cfg.source = ChainSource::None;
self.set_wallet_child_config(&cfg)
}
/// Start the app-owned wallet child, point this node's wallet at it, and /// Start the app-owned wallet child, point this node's wallet at it, and
/// **open its wallet file**. /// **open its wallet file**.
/// ///
@ -3585,6 +3628,182 @@ pub(crate) mod tests {
); );
} }
/// The F7 screen's three chain-source choices each round-trip through the
/// sealed record, and `receive-only` is the way back to zero.
#[tokio::test]
async fn the_setup_screen_persists_each_chain_source() {
let dir = tempfile::tempdir().unwrap();
let home = dir.path().join("child");
let node = offline_node(&home, Arc::new(NoDial));
assert_eq!(
node.wallet_child_config().source,
ChainSource::None,
"a fresh install is receive-only"
);
node.set_remote_daemon("127.0.0.1", 18089)
.expect("remote daemon");
let remote = node.wallet_child_config();
assert_eq!(
remote.source,
ChainSource::Remote {
host: "127.0.0.1".into(),
port: 18089,
}
);
assert!(!remote.source.is_onion());
assert_eq!(
remote.wallet_rpc_bin,
PathBuf::from("monero-wallet-rpc"),
"an empty binary is filled in, like the in-process source"
);
node.set_remote_daemon("peer.onion", 18089)
.expect("onion daemon");
assert!(
node.wallet_child_config().source.is_onion(),
"a .onion host is the source's own SOCKS case, not a special one"
);
node.set_local_monerod(Path::new("/opt/monerod"), true)
.expect("local node");
assert_eq!(
node.wallet_child_config().source,
ChainSource::Local {
monerod_bin: PathBuf::from("/opt/monerod"),
datadir: home.join("chain").join("mainnet-pruned"),
prune: true,
}
);
node.set_receive_only().expect("receive-only");
assert_eq!(node.wallet_child_config().source, ChainSource::None);
// The last write is what a restart sees.
node.set_local_monerod(Path::new("/opt/monerod"), false)
.expect("local node");
drop(node);
let node = offline_node(&home, Arc::new(NoDial));
assert_eq!(
node.wallet_child_config().source,
ChainSource::Local {
monerod_bin: PathBuf::from("/opt/monerod"),
datadir: home.join("chain").join("mainnet-full"),
prune: false,
},
"the source outlives the process"
);
}
/// A chain source the user typed wrong is rejected before it is written, so
/// a bad form never points the child at nothing.
#[tokio::test]
async fn a_rejected_setup_chain_source_is_not_persisted() {
let dir = tempfile::tempdir().unwrap();
let node = offline_node(&dir.path().join("child"), Arc::new(NoDial));
node.set_remote_daemon("127.0.0.1", 18089)
.expect("remote daemon");
let saved = node.wallet_child_config();
let err = node
.set_remote_daemon(" ", 18089)
.expect_err("an empty host is refused");
assert!(err.contains("daemon host required"), "{err}");
let err = node
.set_remote_daemon("127.0.0.1", 0)
.expect_err("port 0 is refused");
assert!(err.contains("daemon port required"), "{err}");
let err = node
.set_local_monerod(Path::new(""), false)
.expect_err("an empty binary path is refused");
assert!(err.contains("monerod path required"), "{err}");
assert_eq!(
node.wallet_child_config(),
saved,
"a rejected source leaves the stored one alone"
);
}
/// The F7 screen's save round-trips through the sealed record, and a save
/// can never lock the wallet out of itself: the file passphrase the screen
/// does not carry is preserved.
#[tokio::test]
async fn a_screen_save_round_trips_and_keeps_the_wallet_passphrase() {
let dir = tempfile::tempdir().unwrap();
let node = offline_node(&dir.path().join("child"), Arc::new(NoDial));
assert!(
node.wallet_config().is_none(),
"a fresh install has stored nothing"
);
node.wallet_save_config(&WalletConfig::new(
"http://127.0.0.1:18083/json_rpc",
"ow:hunter2",
false,
))
.expect("save");
let read = node.wallet_config().expect("the save is readable");
assert_eq!(read.rpc_url, "http://127.0.0.1:18083/json_rpc");
assert_eq!(read.rpc_login.as_str(), "ow:hunter2");
assert!(!read.no_spend);
assert_eq!(read.wallet_passphrase.as_str(), "");
assert!(
node.wallet_status().configured(),
"the live snapshot follows the save"
);
// The file passphrase is sealed by the open path, not by this screen.
node.seal_wallet_passphrase("wallet-file-pass")
.expect("seal");
assert_eq!(
node.wallet_config().expect("stored").wallet_passphrase.as_str(),
"wallet-file-pass"
);
// A screen save (which never holds the file passphrase) keeps the stored
// one instead of blanking it — a save can never lock the wallet out of
// itself. A passphrase a caller hands `wallet_save_config` is ignored
// for the same reason: the file's passphrase is not the screen's.
let mut screen_save =
WalletConfig::new("http://127.0.0.1:18083/json_rpc", "ow:hunter2", true);
screen_save.wallet_passphrase = Zeroizing::new("not-the-files".to_string());
node.wallet_save_config(&screen_save).expect("resave");
let read = node.wallet_config().expect("the resave is readable");
assert!(read.no_spend, "the view-only toggle reached the store");
assert_eq!(read.wallet_passphrase.as_str(), "wallet-file-pass");
}
/// A rejected form leaves the stored config exactly as it was. The node is
/// the validator — the screen does not reimplement it.
#[tokio::test]
async fn a_rejected_wallet_config_is_not_persisted() {
let dir = tempfile::tempdir().unwrap();
let node = offline_node(&dir.path().join("child"), Arc::new(NoDial));
node.wallet_save_config(&WalletConfig::new(
"http://127.0.0.1:18083/json_rpc",
"ow:hunter2",
false,
))
.expect("save");
let before = node.wallet_config().expect("stored");
for bad in [
WalletConfig::new("", "ow:hunter2", false),
WalletConfig::new("http://192.0.2.10:18083/json_rpc", "ow:hunter2", false),
WalletConfig::new("http://127.0.0.1:18083/json_rpc", "", false),
] {
let err = node
.wallet_save_config(&bad)
.expect_err("a bad form is refused");
assert!(!err.is_empty());
assert_eq!(
node.wallet_config().expect("stored"),
before,
"the stored config is intact"
);
}
}
/// `shutdown` stops the processes the app owns: an exit must not orphan a /// `shutdown` stops the processes the app owns: an exit must not orphan a
/// spend-capable wallet RPC behind a loopback socket. /// spend-capable wallet RPC behind a loopback socket.
#[tokio::test] #[tokio::test]

1054
src/tui.rs

File diff suppressed because it is too large Load diff