tui: F7 becomes the node-setup screen, and F6 goes back to being the wallet
All checks were successful
ci / test (pull_request) Successful in 7m20s
ci / sdk (pull_request) Successful in 1m45s
android-ci / android (pull_request) Successful in 13m36s
ci / fuzz (pull_request) Successful in 5m29s

The chain source was reachable from three places and configured from none of
them properly: `F6`'s inline `1`/`2`/`3` picker wrote only the in-process
choice, the `F9` menu showed the state and named keys that edited it, and
`Node::set_local_monerod` / `set_remote_daemon` / `set_receive_only` — the only
way to point the app at a Monero node — had **no TUI caller at all** (Kotlin
only). `wallet::NOT_CONFIGURED_MSG` told users to "open F7" and there was no F7.

F7 (`WalletSetupConfig`) is now the one screen that sets up the node:

- The `datadir` row is new and editable. `Node::set_local_monerod_at` takes the
  path; `set_local_monerod` delegates with the derived default, so an existing
  install keeps the store it already has. An empty datadir is refused rather
  than silently replaced — a store that moved unasked looks like a vanished
  chain and resyncs somewhere the user did not choose.
- The `network` row is new: it carries the Cuprate mainnet/testnet choice that
  `F6`'s `1`/`2`/`3` used to own, so deleting those keys loses nothing. Mainnet
  reads `unvalidated` before it is picked.
- A `NODE` section shows the live `Node::wallet_child_status` line (state, chain
  source, `sync h/t`, last error) and the last save/test answer. It is the
  node's answer, never the draft above it, and `Ctrl-R` re-reads it.
- `Ctrl-S` saves and starts the child (the daemon, and `monerod` for a local
  source); `Ctrl-X` stops it. Both go through the same `Node::start_wallet_child`
  / `stop_wallet_child` the app's own lifecycle uses, so a start that lands on a
  wallet with no stored passphrase still reaches the unlock prompt.

F6 loses the chain picker and the `s`/`x`/`p` child keys — it is the wallet
again (receive, balance, transfers, create/import) — and its footer points at
`F7 node`. The `F9` menu's `child`/`sync` rows now name `F7 ctrl-s/x` and
`F7 ctrl-r` instead of keys that no longer exist on F6. `set_cuprate_chain` and
the `p` probe handler are deleted rather than left dead.

The node's own keys are named in the body, on the section they act on: at 80
columns the footer has room for one group and the status line already spends
half the width, which is the same reason the login row names `Ctrl-U`.

Tests: six new cases in `src/tui.rs`'s `wallet_setup_config_tests` drive the real
key path and the real node — the typed datadir reaching `ChainSource::Local`, an
empty one being refused with nothing written, the live row on open, `Ctrl-S`
saving then reporting the node's own refusal, the in-process network pick
reaching the store, and F6 no longer owning keys it does not handle.
`tests/tui_spec.rs`'s menu-key check now asserts the F7 keys; the F6 keys it
asserted before no longer work.
This commit is contained in:
agent 2026-09-27 20:06:51 -04:00
commit 5cdfbacf10
No known key found for this signature in database
6 changed files with 509 additions and 106 deletions

View file

@ -200,15 +200,19 @@ payload can contain `?`).
| `F3` | Paste a friend's invite |
| `F4` | Rotate **onion** (locator only) |
| `F5` | Selected friend's profile (`/who`) |
| `F6` | Wallet (receive QR, create/import, child, chain source) |
| `F6` | Wallet (receive QR, balance, transfers, create/import) |
| `F7` | Node & wallet setup (wallet RPC endpoint, chain source, start/stop, live node state) |
| `F8` | Rotate **prekey** (hard cut: every friend re-pastes the invite) |
| `F9` | Wallets & settings menu (`/settings`) |
| Enter | Send chat to the selected friend, or run a `/command` |
| `Esc` | Close overlay / back to Main / clear composer |
| `Ctrl-Q` | Quit: type `CLEAR`+Enter to wipe history, `QUIT`+Enter to leave it, Esc to stay |
There is **no `F7`**. The not-configured wallet error still says “open F7”; the
live screens are `F6` (wallet) and `F9` (settings). Full map: [docs/TUI.md](docs/TUI.md).
`F7` is where the Monero side is set up: the wallet RPC endpoint and login, the
chain source (receive-only, a local `monerod`, a remote daemon, or the in-process
Cuprate node), the chain datadir, and `Ctrl-S`/`Ctrl-X` to start and stop it. It
is also what the “open F7” wallet error points at. Full map:
[docs/TUI.md](docs/TUI.md).
Composer `/commands` (`src/tui.rs` `parse_cmd`): `/wipe`, `/wipe-all`, `/profile`,
`/who`, `/pay <xmr> [memo]`, `/tip <xmr> [memo]`, `/backup /path`, `/restore /path`,
@ -425,7 +429,7 @@ Do not run `cargo publish`; `publish = false`.
| Blank / broken TUI | Real terminal emulator, not `nohup` / systemd without a TTY. |
| Two chats, same laptop | Separate `ONIONWIRE_HOME` per process. |
| Friend cannot find you after F4 | Expected if they were offline. They F3-paste the new invite. |
| Wallet error says “open F7” | There is no F7. Use `F6` / `F9`, or set `ONIONWIRE_WALLET_RPC`. |
| Wallet error says “open F7” | `F7` is the node & wallet setup screen: set the RPC endpoint there, or set `ONIONWIRE_WALLET_RPC`. |
## Not in v1

View file

@ -22,11 +22,11 @@ ASCII chrome.
| `Wipe` | `/wipe` or `/wipe-all` | Type `WIPE` or `WIPEALL` |
| `Profile` | `/profile` | Edit name, bio, optional Monero address |
| `ConfirmKeys` / `Passphrase` | `/backup`, `/restore` | Type `BACKUP`/`RESTORE`, then passphrase |
| `Wallet` | `F6` | Receive QR, balance, transfers, child, chain source |
| `Wallet` | `F6` | Receive QR, balance, transfers |
| `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 |
| `WalletsSettings` | `F9` or `/settings` | Discovery menu (does not replace F-keys) |
| `WalletSetupConfig` | `F7` | Wallet RPC endpoint and chain source, editable |
| `WalletSetupConfig` | `F7` | Node & wallet setup: RPC endpoint, chain source, start/stop, live node state |
| `PeerPayments` | F9 then `p` | Peer-scoped `/pay` / `/tip` history |
| `Quit` | `Ctrl-Q` | Type `CLEAR` or `QUIT` |
@ -42,7 +42,7 @@ peer-payments are:
| `F4` | Rotate | Onion locator |
| `F5` | Who | Selected friend's profile |
| `F6` | Wallet | Wallet screen |
| `F7` | Setup | Wallet RPC endpoint and chain source |
| `F7` | Setup | Node & wallet setup: RPC endpoint, chain source, start/stop |
| `F8` | RotatePrekey | Prekey hard cut |
| `F9` | OpenMenu | Wallets & settings |
@ -115,10 +115,14 @@ in both, and the `F9` beside it is left bare so the whole hint still fits at 80.
## Wallet (`F6`)
The wallet, not the node: receive, balance, transfers, and create/import. Chain
and node configuration is `F7` (`Configures the wallet RPC endpoint and the
chain source`), named in the footer so the key is findable from here.
Footer:
```
c create i import r qr w wallets s/x child 1 pruned 2 full 3 testnet Esc back ? help
c create i import r qr w wallets F7 node Esc back ? help
```
| Key | Effect |
@ -127,14 +131,14 @@ c create i import r qr w wallets s/x child 1 pruned 2 full 3 testnet Esc
| `w` | Saved wallets (`WalletSelect`) |
| `c` | Create wallet (`SPEND` then seed once, type `SEEN`) |
| `i` | Import 25-word seed |
| `s` | Start app-owned wallet child |
| `x` | Stop child (idempotent) |
| `p` | Probe child (RPC answering? chain at tip?) |
| `1` | In-process Cuprate **mainnet pruned** (unvalidated) |
| `2` | In-process Cuprate **mainnet full** (unvalidated) |
| `3` | In-process Cuprate **testnet** |
| `F7` | Node & wallet setup (`WalletSetupConfig`) |
| Esc | Back to Main |
The child's state and the chain source are shown here (and on `F9`), but they are
**set** on `F7`: the start/stop/probe keys and the `1`/`2`/`3` in-process picker
that used to live on this screen are gone, so there is one place that configures
the chain.
The chain line for an in-process source always carries
`testnet only — mainnet is unvalidated` (`cuprate::TESTNET_ONLY`). Starting
Cuprate needs `--features cuprate-daemon`; without it, start fails with that
@ -176,17 +180,19 @@ 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
live header keeps reading them from the node.
## Wallet setup (`F7`)
## 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.
`?` are universal; the node's own keys (`ctrl-s`, `ctrl-x`, `ctrl-r`) and
`Ctrl-U` are named in the body, on the row they act on.
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.
This is the only screen that sets up the chain: the wallet RPC endpoint, and the
node that serves it.
| Row | Kind | Notes |
|---|---|---|
@ -196,30 +202,44 @@ Two things live here: the wallet RPC endpoint, and the chain source.
| `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 |
| `datadir` | text | where the chain is stored. Prefilled with the path already in use; an empty one is refused rather than silently defaulted |
| `prune` | toggle | local and in-process sources |
| `network` | picker | in-process source: `space` cycles mainnet (`unvalidated`) and testnet |
`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.
Under them, a `NODE` section: the live `Node::wallet_child_status` line (state,
chain source, `sync h/t` once a daemon reports numbers, the last error) and the
last save/test answer. The live row is the node's answer, never the draft above
it, and it is re-read by `Ctrl-R`.
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.
`Enter` saves and answers on the status row: `saved · not dialled yet — ctrl-s
starts it, 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.
`Ctrl-S` saves and then starts the wallet child — the daemon and, for a local
source, `monerod` — so the setup screen is also the key that brings the node up.
A start that lands on a wallet file with no stored passphrase moves the app to
the unlock prompt. `Ctrl-X` stops the child. Both go through the same
`Node::start_wallet_child` / `stop_wallet_child` the app's own lifecycle uses.
The chain row is written only when it was changed. An untouched row leaves the
stored source alone, so opening `F7` to fix a port cannot silently undo an
in-process Cuprate choice or move a chain datadir. 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`)
Discovery layer, not a replacement. Function keys stay live on this screen.
Rows name the shortcut they sit beside (`F6 c`, `F6 i`, `F6 r`, `F6 s/x`,
`F6 p`, `/profile`, `/backup`, `/wipe`, …).
Rows name the shortcut they sit beside (`F6 c`, `F6 i`, `F6 r`, `/profile`,
`/backup`, `/wipe`, …).
- **No credentials** on this screen. Login, seed, and passphrase are never
passed into the menu snapshot.
@ -232,9 +252,10 @@ The menu **shows** endpoint state; it does not edit it. The `endpoint` row names
copy in `src/wallet.rs` now points at — that error is no longer advice for a key
that does not exist.
Chain source is stored via `Node::set_wallet_child_config`. `F6` keys
`1`/`2`/`3` set the in-process source; `F7` sets any of the four, plus the
external RPC URL and a remote daemon host.
Chain source is stored via `Node::set_wallet_child_config`. `F7` is the one
screen that sets any of the four sources — receive-only, a local `monerod`, a
remote daemon, or the in-process Cuprate node — along with the external RPC URL
and the chain datadir.
## Peer payments (`F9` then `p`)

View file

@ -89,14 +89,17 @@ The child is stopped rather than left answering `-13`, and the status reports
(`open_wallet_with_passphrase`, or the TUI/Android prompt) and it is remembered.
Nothing spawns the child at boot. `Node::start_wallet_child` is the only start
path. The desktop TUI drives it from `F6`:
path. The desktop TUI drives it from `F7` (`Ctrl-S` / `Ctrl-X`), which is also
the screen that picks the chain source:
| Key | Effect |
|---|---|
| `s` | Start the child, then probe it once. A child whose wallet file needs a passphrase opens the passphrase prompt instead of leaving every read at `-13`. |
| `x` | Stop it (idempotent). |
| `p` | Probe: is wallet RPC answering, is the chain at the tip? |
| `1` / `2` / `3` | Store in-process Cuprate as mainnet-pruned / mainnet-full / testnet. |
| `Ctrl-S` | Save the form, then start the child and probe it once. A child whose wallet file needs a passphrase opens the passphrase prompt instead of leaving every read at `-13`. |
| `Ctrl-X` | Stop it (idempotent). |
| `Ctrl-R` | Re-read the live node line (`off` / `connecting` / `syncing` / `ready` / `exited`). |
| `Enter` | Save the endpoint and chain source without dialling or starting anything. |
| `chain` row + `space` | Receive-only / local `monerod` / remote daemon / in-process Cuprate. |
| `network` row + `space` | In-process network: mainnet (unvalidated) or testnet. |
State shown: `off` / `connecting` / `syncing` / `ready` / `exited`, plus a
chain-source label, plus `wallet locked` while a catalogue wallet is configured
@ -149,9 +152,10 @@ cargo build --release --features cuprate-daemon
`this build has no in-process chain daemon — rebuild with --features cuprate-daemon`.
- **Pre-production.** Cuprate's own user book says do not use `cuprated` for
serious purposes. RPC parity is incomplete (`docs/cuprate-launch-spike.md`).
- **Mainnet is unvalidated.** The TUI can store mainnet-pruned (`F6` `1`) or
mainnet-full (`F6` `2`) or testnet (`F6` `3`). Every in-process surface still
prints `testnet only — mainnet is unvalidated` (`cuprate::TESTNET_ONLY`).
- **Mainnet is unvalidated.** The TUI stores the in-process network on `F7`'s
`network` row (mainnet or testnet) and the store's shape on its `prune` row.
Every in-process surface still prints `testnet only — mainnet is unvalidated`
(`cuprate::TESTNET_ONLY`).
Cross-compiled is not device-proven. Pointing a mainnet wallet at it is not
something this build claims to do.
- **No Tor on the chain path.** Cuprate's `arti` feature is off (arti-client
@ -208,9 +212,10 @@ be used (non-loopback, `.onion`, missing login) is reported and falls back to
env rather than dialling the bad endpoint.
`Store::save_wallet_config` / `Node::wallet_save_config` exist, and the `F7`
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
screen (`WalletSetupConfig`) writes them: the endpoint, its login, the chain
source, and (for a local node) its datadir and network. It is also the only
screen that starts and stops the child (`Ctrl-S` / `Ctrl-X`). `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`
(`src/wallet.rs`), and that key is real.

View file

@ -689,16 +689,42 @@ impl Node {
/// 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 datadir = self.local_chain_datadir(prune);
self.set_local_monerod_at(monerod_bin, &datadir, prune)
}
/// The chain datadir a local node uses when the user did not name one.
/// Split by prune mode exactly as it always was, so an existing install
/// keeps the store it already has.
pub fn local_chain_datadir(&self, prune: bool) -> PathBuf {
self.home
.join("chain")
.join(if prune { "mainnet-pruned" } else { "mainnet-full" })
}
/// [`Self::set_local_monerod`], with the chain datadir spelled out — the
/// shape the F7 screen saves when the user typed one.
///
/// An empty datadir is refused rather than silently replaced with the
/// default: a store that moved without the user saying so looks exactly
/// like a chain that vanished, and a silent rewrite would resync the whole
/// chain into a directory they did not choose.
pub fn set_local_monerod_at(
&self,
monerod_bin: &Path,
datadir: &Path,
prune: bool,
) -> Result<(), String> {
if datadir.as_os_str().is_empty() {
return Err("chain datadir required for a local node".into());
}
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" }),
datadir: datadir.to_path_buf(),
prune,
};
self.set_wallet_child_config(&cfg)

View file

@ -1384,7 +1384,7 @@ impl SetupSource {
Self::ReceiveOnly => "receive-only · no chain, no spend",
Self::Local => "local node · this box spawns monerod",
Self::Remote => "remote daemon · one you run elsewhere",
Self::InProcess => "in-process node · set on F6",
Self::InProcess => "in-process node · cuprate in this app",
}
}
}
@ -1396,8 +1396,10 @@ const SETUP_ROW_NO_SPEND: usize = 2;
const SETUP_ROW_CHAIN: usize = 3;
const SETUP_ROW_DAEMON: usize = 4;
const SETUP_ROW_MONEROD: usize = 5;
const SETUP_ROW_PRUNE: usize = 6;
const SETUP_ROWS: usize = 7;
const SETUP_ROW_DATADIR: usize = 6;
const SETUP_ROW_PRUNE: usize = 7;
const SETUP_ROW_NETWORK: usize = 8;
const SETUP_ROWS: usize = 9;
/// The F7 screen's draft: plain data taken once when the screen opens
/// (`Node::wallet_config` plus `Node::wallet_child_config`), never a handle onto
@ -1416,6 +1418,10 @@ pub struct WalletSetupConfigState {
/// `host:port` for the remote daemon.
daemon: String,
monerod_bin: String,
/// Chain datadir for a local node (spawned `monerod` or in-process Cuprate).
/// Prefilled with the path the node already uses, so a save that leaves it
/// alone keeps the chain where it is.
datadir: String,
prune: bool,
/// The chain row was changed on this screen. An untouched row is not
/// written, so an in-process Cuprate source survives an F7 save.
@ -1423,6 +1429,10 @@ pub struct WalletSetupConfigState {
cuprate_network: ChainNetwork,
/// The last save / test answer, display-ready, never a secret.
note: Option<String>,
/// The live node/child line, refreshed on open and by `Ctrl-R`. This is the
/// answer to "did the node I just configured come up?" — taken from
/// `Node::wallet_child_status`, never inferred from the draft above.
status: Option<String>,
}
/// `Debug` is written by hand and redacts the login. Nothing in the app prints
@ -1445,10 +1455,12 @@ impl std::fmt::Debug for WalletSetupConfigState {
.field("source", &self.source)
.field("daemon", &self.daemon)
.field("monerod_bin", &self.monerod_bin)
.field("datadir", &self.datadir)
.field("prune", &self.prune)
.field("chain_touched", &self.chain_touched)
.field("cuprate_network", &self.cuprate_network)
.field("note", &self.note)
.field("status", &self.status)
.finish()
}
}
@ -1471,26 +1483,38 @@ impl WalletSetupConfigState {
source: SetupSource::ReceiveOnly,
daemon: format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}"),
monerod_bin: "monerod".to_string(),
// The default a save would use if the user never types one; a stored
// local/in-process source overwrites it below with its real path.
datadir: node.local_chain_datadir(false).display().to_string(),
prune: false,
chain_touched: false,
cuprate_network: ChainNetwork::Mainnet,
note: None,
status: None,
};
match &child.source {
ChainSource::None => {}
ChainSource::Local {
monerod_bin, prune, ..
monerod_bin,
datadir,
prune,
} => {
state.source = SetupSource::Local;
state.monerod_bin = monerod_bin.display().to_string();
state.datadir = datadir.display().to_string();
state.prune = *prune;
}
ChainSource::Remote { host, port } => {
state.source = SetupSource::Remote;
state.daemon = format!("{host}:{port}");
}
ChainSource::InProcessCuprate { network, prune, .. } => {
ChainSource::InProcessCuprate {
datadir,
network,
prune,
} => {
state.source = SetupSource::InProcess;
state.datadir = datadir.display().to_string();
state.prune = *prune;
state.cuprate_network = *network;
}
@ -1498,6 +1522,18 @@ impl WalletSetupConfigState {
state
}
/// Read the live node/child line into the screen. Called on open and by
/// `Ctrl-R`, so what the status row shows is what the node answered, never
/// what the draft above it claims.
pub fn refresh_status(&mut self, node: &Node) {
let line = node.wallet_child_status().line();
self.status = Some(if line.is_empty() {
"node not configured · pick a chain source and ctrl-s".to_string()
} else {
format!("node {line}")
});
}
/// The one secret in this state goes away with the screen, on purpose.
fn close(&mut self) {
self.rpc_login.zeroize();
@ -1522,6 +1558,7 @@ impl WalletSetupConfigState {
SETUP_ROW_LOGIN => self.rpc_login.push(c),
SETUP_ROW_DAEMON => self.daemon.push(c),
SETUP_ROW_MONEROD => self.monerod_bin.push(c),
SETUP_ROW_DATADIR => self.datadir.push(c),
_ => {}
}
}
@ -1532,6 +1569,7 @@ impl WalletSetupConfigState {
SETUP_ROW_LOGIN => self.rpc_login.pop(),
SETUP_ROW_DAEMON => self.daemon.pop(),
SETUP_ROW_MONEROD => self.monerod_bin.pop(),
SETUP_ROW_DATADIR => self.datadir.pop(),
_ => None,
};
}
@ -1544,6 +1582,7 @@ impl WalletSetupConfigState {
SETUP_ROW_LOGIN => self.rpc_login.zeroize(),
SETUP_ROW_DAEMON => self.daemon.clear(),
SETUP_ROW_MONEROD => self.monerod_bin.clear(),
SETUP_ROW_DATADIR => self.datadir.clear(),
_ => {}
}
}
@ -1559,10 +1598,20 @@ impl WalletSetupConfigState {
self.prune = !self.prune;
self.chain_touched = true;
}
// The in-process node's network, which F6's `1`/`2`/`3` used to own:
// moving the chain picker here must not lose the choice.
SETUP_ROW_NETWORK => {
self.cuprate_network = match self.cuprate_network {
ChainNetwork::Mainnet => ChainNetwork::Testnet,
ChainNetwork::Testnet => ChainNetwork::Mainnet,
};
self.chain_touched = true;
}
SETUP_ROW_URL => self.rpc_url.push(' '),
SETUP_ROW_LOGIN => self.rpc_login.push(' '),
SETUP_ROW_DAEMON => self.daemon.push(' '),
SETUP_ROW_MONEROD => self.monerod_bin.push(' '),
SETUP_ROW_DATADIR => self.datadir.push(' '),
_ => {}
}
}
@ -1577,17 +1626,24 @@ impl WalletSetupConfigState {
}
let chain = match self.source {
SetupSource::ReceiveOnly => node.set_receive_only(),
SetupSource::Local => node.set_local_monerod(Path::new(&self.monerod_bin), self.prune),
SetupSource::Local => node.set_local_monerod_at(
Path::new(&self.monerod_bin),
Path::new(&self.datadir),
self.prune,
),
SetupSource::Remote => match parse_daemon_addr(&self.daemon) {
Some((host, port)) => node.set_remote_daemon(&host, port),
None => return "not saved · daemon address must be host:port".to_string(),
},
// Untouched: leave whatever F6 stored, including nothing.
// Untouched: leave whatever held it before, including the in-process
// choice F6 used to own, rather than silently rewriting its datadir.
SetupSource::InProcess if !self.chain_touched => Ok(()),
SetupSource::InProcess => node.set_in_process_cuprate(self.cuprate_network, self.prune),
};
match chain {
Ok(()) => "saved · not dialled — ctrl-t tests the endpoint".to_string(),
Ok(()) => {
"saved · not dialled yet — ctrl-s starts it, ctrl-t tests the endpoint".to_string()
}
Err(e) => format!("wallet config saved · chain source: {e}"),
}
}
@ -1624,6 +1680,16 @@ impl WalletSetupConfigState {
}
}
/// The in-process node's network row. Mainnet says it is unvalidated in the
/// same words `cuprate::TESTNET_ONLY` uses, because that is the fact a user
/// picking it needs.
fn network_display(&self) -> &'static str {
match self.cuprate_network {
ChainNetwork::Mainnet => "mainnet · unvalidated",
ChainNetwork::Testnet => "testnet",
}
}
fn status_display(&self) -> String {
self.note
.clone()
@ -2038,12 +2104,8 @@ impl App {
// `w` is the wallet list: the F6 screen is about the wallet you
// are on, and this is how you get off it.
KeyCode::Char('w') => self.open_wallet_select(),
KeyCode::Char('s') => self.wallet_child_start(),
KeyCode::Char('x') => self.wallet_child_stop(),
KeyCode::Char('p') => self.wallet_child_probe(),
KeyCode::Char('1') => self.set_cuprate_chain(ChainNetwork::Mainnet, true),
KeyCode::Char('2') => self.set_cuprate_chain(ChainNetwork::Mainnet, false),
KeyCode::Char('3') => self.set_cuprate_chain(ChainNetwork::Testnet, false),
// The node's own keys (start/stop/probe, chain source) are F7's.
// F6 is the wallet: receive, balance, transfers, create/import.
KeyCode::Char('c') => {
self.screen = Screen::WalletSetup(WalletSetup::CreateWarn {
typed: String::new(),
@ -2663,33 +2725,18 @@ impl App {
});
}
/// Key `p`: one probe of the running child — is its RPC answering, and is
/// the chain at the tip? The only thing that can report `ready`.
fn wallet_child_probe(&mut self) {
self.status_note = Some(self.wallet_child_note());
}
fn set_cuprate_chain(&mut self, network: ChainNetwork, prune: bool) {
self.status_note = Some(match self.node.set_in_process_cuprate(network, prune) {
Ok(()) => format!(
"chain source: {}",
self.node.wallet_child_config().source.label()
),
Err(e) => format!("chain source: {e}"),
});
}
/// F7: open the setup screen with the stored (or env-derived) values as the
/// draft. Nothing is read from the store while the screen is open.
fn open_setup_config(&mut self) {
self.screen = Screen::WalletSetupConfig {
state: WalletSetupConfigState::from_node(&self.node),
};
let mut state = WalletSetupConfigState::from_node(&self.node);
state.refresh_status(&self.node);
self.screen = Screen::WalletSetupConfig { state };
}
/// Keys on the F7 screen: `Tab` moves, `Enter` saves, `Ctrl-T` tests the
/// endpoint, `Ctrl-U` clears the focused field, `Esc` leaves and wipes the
/// login buffer.
/// wallet RPC endpoint, `Ctrl-S` saves and starts the node/wallet child,
/// `Ctrl-X` stops it, `Ctrl-R` re-reads the live node line, `Ctrl-U` clears
/// the focused field, `Esc` leaves and wipes the login buffer.
fn handle_wallet_setup_config(&mut self, key: KeyEvent) {
if key.code == KeyCode::Esc {
if let Screen::WalletSetupConfig { state } = &mut self.screen {
@ -2707,6 +2754,28 @@ impl App {
state.note = Some(note);
return;
}
// Start/stop go through `App`'s own child helpers so this screen and the
// wallet screen that used to own them cannot drift: same start, same
// passphrase prompt, same status line.
if ctrl && key.code == KeyCode::Char('s') {
let Screen::WalletSetupConfig { state } = &mut self.screen else {
return;
};
let note = state.save(&self.node);
state.note = Some(note);
self.wallet_child_start();
self.refresh_setup_status();
return;
}
if ctrl && key.code == KeyCode::Char('x') {
self.wallet_child_stop();
self.refresh_setup_status();
return;
}
if ctrl && key.code == KeyCode::Char('r') {
self.refresh_setup_status();
return;
}
let Screen::WalletSetupConfig { state } = &mut self.screen else {
return;
};
@ -2725,6 +2794,15 @@ impl App {
}
}
/// Re-read the live node line into the F7 screen, if it is still the screen
/// on show. A start that needed a passphrase has already moved the app to
/// the unlock prompt, and this must not drag it back.
fn refresh_setup_status(&mut self) {
if let Screen::WalletSetupConfig { state } = &mut self.screen {
state.refresh_status(&self.node);
}
}
/// The child status line, or the copy that names what is missing.
fn wallet_child_note(&mut self) -> String {
let line = self.rt.block_on(self.node.wallet_child_refresh()).line();
@ -3913,7 +3991,7 @@ match screen {
},
Screen::Passphrase { .. } => "Enter submit Esc cancel ? help",
Screen::Wallet { .. } => {
"c create i import r qr w wallets s/x child 1 pruned 2 full 3 testnet Esc back ? help"
"c create i import r qr w wallets F7 node Esc back ? help"
}
Screen::WalletSetup(WalletSetup::CreateWarn { .. }) => "type SPEND Esc cancel ? help",
Screen::WalletSetup(WalletSetup::CreatePass { .. } | WalletSetup::UnlockPass { .. }) => {
@ -4427,8 +4505,8 @@ fn menu_groups(s: &WalletMenuState) -> (Vec<MenuRow>, Vec<MenuRow>) {
// `F7` is the key that edits this row, so the row names it: the menu is
// the discovery layer, and the endpoint is the one thing only F7 writes.
MenuRow::new("endpoint", endpoint_value, "F7", endpoint_tone),
MenuRow::new("child", child_value, "F6 s/x", MenuTone::Normal),
MenuRow::new("sync", sync_value, "F6 p", sync_tone),
MenuRow::new("child", child_value, "F7 ctrl-s/x", MenuTone::Normal),
MenuRow::new("sync", sync_value, "F7 ctrl-r", sync_tone),
MenuRow::new(
"receive",
if receive_empty {
@ -4751,6 +4829,13 @@ pub fn wallet_setup_config_lines(width: u16, s: &WalletSetupConfigState) -> Vec<
"monerod",
&s.monerod_bin,
));
out.push(setup_row_line(
w,
s,
SETUP_ROW_DATADIR,
"datadir",
&s.datadir,
));
out.push(setup_row_line(
w,
s,
@ -4758,9 +4843,38 @@ pub fn wallet_setup_config_lines(width: u16, s: &WalletSetupConfigState) -> Vec<
"prune",
s.prune_display(),
));
out.push(setup_row_line(
w,
s,
SETUP_ROW_NETWORK,
"network",
&format!("{} (space changes)", s.network_display()),
));
out.push(Line::default());
out.push(menu_section_line(w, "NODE"));
// What the node answered, not what the draft claims: the row is filled from
// `Node::wallet_child_status` and says so when nothing is configured yet.
out.push(Line::from(
Span::raw(fit_cells(&format!("status {}", s.status_display()), w)).style(style_dim()),
Span::raw(fit_cells(
s.status
.as_deref()
.unwrap_or("node unknown — ctrl-r re-reads the live state"),
w,
))
.style(style_dim()),
));
// The node's own keys are named here, on the section they act on, for the
// same reason the login row names `ctrl-u`: at 80 columns the footer has
// room for one group and the status line already spends half the width.
out.push(Line::from(
Span::raw(fit_cells(
"keys ctrl-s save + start ctrl-x stop ctrl-r re-read",
w,
))
.style(style_dim()),
));
out.push(Line::from(
Span::raw(fit_cells(&format!("last {}", s.status_display()), w)).style(style_dim()),
));
out
}
@ -5910,7 +6024,7 @@ balance
lines.push(format!(" {} {} XMR", t.txid.chars().take(16).collect::<String>(), xmr));
}
}
let help = "s start child x stop child p probe c create i import r qr Esc back";
let help = "c create i import r qr w wallets F7 node Esc back";
lines.push("".into());
f.render_widget(
Paragraph::new(lines.join("\n"))
@ -6229,12 +6343,6 @@ mod wallet_store_tests {
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::<Vec<_>>().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
@ -6410,10 +6518,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 {
@ -7412,4 +7516,245 @@ mod wallet_setup_config_tests {
assert_eq!(after, before, "a rejected form wrote something");
assert!(after.no_spend, "the stored view-only flag is untouched");
}
/// `Tab` from wherever the form is focused until `row` has it. The tests
/// below drive the real key path, not the state directly.
fn focus_row(app: &mut App, row: usize) {
let mut guard = 0;
while state_of(app).field != row {
app.handle_key(key(KeyCode::Tab)).expect("tab");
guard += 1;
assert!(guard <= SETUP_ROWS, "row {row} is unreachable by Tab");
}
}
/// Pick the `chain` row's source by cycling it with `space`.
fn pick_source(app: &mut App, want: SetupSource) {
focus_row(app, SETUP_ROW_CHAIN);
for _ in 0..4 {
if state_of(app).source == want {
return;
}
app.handle_key(key(KeyCode::Char(' '))).expect("space");
}
panic!("the picker never reached {want:?}");
}
/// The point of the datadir row: a local node goes where the user says, not
/// where the default was. This is the node-setup path the app lacked —
/// `set_local_monerod` was reachable only from Kotlin.
#[test]
fn a_local_node_saves_the_datadir_the_user_typed() {
let dir = tempfile::tempdir().unwrap();
let home = dir.path().join("home");
let (mut app, _rt) = app(&home);
app.handle_key(key(KeyCode::F(7))).expect("F7");
fill_endpoint(&mut app);
pick_source(&mut app, SetupSource::Local);
focus_row(&mut app, SETUP_ROW_MONEROD);
for _ in 0.."monerod".len() {
app.handle_key(key(KeyCode::Backspace)).expect("backspace");
}
type_str(&mut app, "/opt/monero/monerod");
let typed = home.join("chain-tank");
focus_row(&mut app, SETUP_ROW_DATADIR);
app.handle_key(KeyEvent::new(KeyCode::Char('u'), KeyModifiers::CONTROL))
.expect("ctrl-u");
type_str(&mut app, typed.to_str().expect("utf8 path"));
app.handle_key(key(KeyCode::Enter)).expect("enter");
assert!(
state_of(&app)
.note
.as_deref()
.expect("a status line")
.starts_with("saved"),
"the save must land: {:?}",
state_of(&app).note
);
match &app.node.wallet_child_config().source {
ChainSource::Local {
monerod_bin,
datadir,
prune,
} => {
assert_eq!(monerod_bin.to_str(), Some("/opt/monero/monerod"));
assert_eq!(
datadir, &typed,
"the node must store its chain where the user said"
);
assert!(!prune);
}
other => panic!("expected a local node, got {other:?}"),
}
}
/// An empty datadir is refused rather than silently replaced with the
/// default: a store that moved without being asked looks like a vanished
/// chain, and the resync lands somewhere the user did not choose.
#[test]
fn an_empty_datadir_is_refused_and_the_source_is_not_written() {
let dir = tempfile::tempdir().unwrap();
let (mut app, _rt) = app(&dir.path().join("home"));
app.handle_key(key(KeyCode::F(7))).expect("F7");
fill_endpoint(&mut app);
pick_source(&mut app, SetupSource::Local);
focus_row(&mut app, SETUP_ROW_DATADIR);
app.handle_key(KeyEvent::new(KeyCode::Char('u'), KeyModifiers::CONTROL))
.expect("ctrl-u");
app.handle_key(key(KeyCode::Enter)).expect("enter");
let note = state_of(&app).note.as_deref().expect("a status line");
assert!(
note.contains("datadir required"),
"the refusal must name the missing field: {note}"
);
assert_eq!(
app.node.wallet_child_config().source,
ChainSource::None,
"a refused chain source must not be stored"
);
}
/// The row answers with what the node says, not with what the draft above it
/// claims: on a fresh install that is "nothing configured yet".
#[test]
fn the_node_row_shows_the_live_state_on_open() {
let dir = tempfile::tempdir().unwrap();
let (mut app, _rt) = app(&dir.path().join("home"));
app.handle_key(key(KeyCode::F(7))).expect("F7");
let status = state_of(&app)
.status
.as_deref()
.expect("the screen reads the node on open");
assert!(
status.starts_with("node"),
"the live row must be the node's answer: {status}"
);
let body = wallet_setup_config_text(78, state_of(&app));
assert!(
body.contains("not configured"),
"an unconfigured install must say so, not print a blank row:\n{body}"
);
// The node's keys are discoverable from the body: at 80 columns the
// footer has no room for them.
for needle in ["ctrl-s save + start", "ctrl-x stop", "ctrl-r re-read"] {
assert!(
body.contains(needle),
"{needle:?} must be named on the screen that uses it:\n{body}"
);
}
}
/// `Ctrl-S` is the key that actually brings the node up: it saves the form
/// and then asks the node to start. With no chain source the start refuses
/// in the node's own words and the screen stays put.
#[test]
fn ctrl_s_saves_then_reports_the_nodes_own_refusal() {
let dir = tempfile::tempdir().unwrap();
let (mut app, _rt) = app(&dir.path().join("home"));
app.handle_key(key(KeyCode::F(7))).expect("F7");
fill_endpoint(&mut app);
app.handle_key(KeyEvent::new(KeyCode::Char('s'), KeyModifiers::CONTROL))
.expect("ctrl-s");
assert!(
state_of(&app)
.note
.as_deref()
.expect("a status line")
.starts_with("saved"),
"ctrl-s must save first: {:?}",
state_of(&app).note
);
assert_eq!(
app.node
.wallet_config()
.expect("the endpoint saved")
.rpc_url,
URL
);
let note = app.status_note.as_deref().expect("the start reported");
assert!(
note.contains("receive-only"),
"a receive-only install must be told why nothing started: {note}"
);
assert!(
matches!(app.screen, Screen::WalletSetupConfig { .. }),
"a start that needs no passphrase must leave the user on F7"
);
}
/// F6's `1`/`2`/`3` keys were also the only way to pick the in-process node's
/// network. That choice moved here with the picker instead of being lost.
#[test]
fn the_in_process_network_is_still_selectable() {
let dir = tempfile::tempdir().unwrap();
let (mut app, _rt) = app(&dir.path().join("home"));
app.handle_key(key(KeyCode::F(7))).expect("F7");
fill_endpoint(&mut app);
pick_source(&mut app, SetupSource::InProcess);
assert_eq!(state_of(&app).cuprate_network, ChainNetwork::Mainnet);
focus_row(&mut app, SETUP_ROW_NETWORK);
let body = wallet_setup_config_text(78, state_of(&app));
assert!(
body.contains("unvalidated"),
"mainnet must say it is unvalidated before it is picked:\n{body}"
);
app.handle_key(key(KeyCode::Char(' '))).expect("space");
assert_eq!(state_of(&app).cuprate_network, ChainNetwork::Testnet);
app.handle_key(key(KeyCode::Enter)).expect("enter");
match &app.node.wallet_child_config().source {
ChainSource::InProcessCuprate { network, .. } => assert_eq!(
*network,
ChainNetwork::Testnet,
"the network pick must reach the stored source"
),
other => panic!("expected an in-process source, got {other:?}"),
}
}
/// F6 is the wallet again: the chain picker and the child's start/stop keys
/// moved to F7, so pressing them there changes nothing and the store is not
/// touched behind the user's back.
#[test]
fn f6_no_longer_owns_the_chain_picker_or_the_child_keys() {
let dir = tempfile::tempdir().unwrap();
let (mut app, _rt) = app(&dir.path().join("home"));
app.handle_key(key(KeyCode::F(6))).expect("F6");
assert!(matches!(app.screen, Screen::Wallet { .. }));
for c in ['s', 'x', 'p', '1', '2', '3'] {
app.handle_key(key(KeyCode::Char(c))).expect("key");
assert!(
matches!(app.screen, Screen::Wallet { .. }),
"`{c}` must not leave the wallet screen"
);
}
assert_eq!(
app.node.wallet_child_config().source,
ChainSource::None,
"keys F6 no longer owns must not write a chain source"
);
// And the footer no longer advertises them.
let footer = footer_hints(&app.screen);
assert!(
footer.contains("F7 node"),
"F6 must point at F7 for the node: {footer}"
);
assert!(
!footer.contains("1 pruned") && !footer.contains("s/x child"),
"F6 must not still advertise the keys it lost: {footer}"
);
}
}

View file

@ -1030,11 +1030,13 @@ fn wallets_settings_menu_lists_both_groups_and_every_key() {
);
}
// Every actionable row names the key or command that fires it, including the
// F6 wallet screen's own keys, so the menu teaches the shortcuts it sits
// beside instead of hiding them.
// keys that now live on F7, so the menu teaches the shortcuts it sits beside
// instead of hiding them. A row must never name a key that no longer works:
// `F6 s/x` and `F6 p` moved to `F7 ctrl-s/x` and `F7 ctrl-r` with the node
// screen, and naming the dead keys here is how they would keep looking live.
for key in [
"F6 s/x",
"F6 p",
"F7 ctrl-s/x",
"F7 ctrl-r",
"c copy F6 r",
"F6 c",
"F6 i",