tui: read the wallet list from the store and load the chosen wallet #144

Merged
sirius merged 2 commits from wt/t_895853ad into wt/t_511023b6 2026-09-21 18:40:13 +00:00
Owner

Joins the three wallet pieces that already existed but were never wired together: the catalogue in the encrypted store (#141, wt/t_64c9ba3c), the create/import path that remembers a wallet (#143, wt/t_511023b6), and the selection screen (#142, wt/t_14ac0a3f). Closes the card criterion "selecting a wallet loads it, creating one persists and appears in the list, and the app remembers wallets across restarts".

Base/stacking. Base is wt/t_511023b6 because this needs #141's store API and #143's Node::wallet_create/Node::list_wallets: neither is on main yet. The branch also carries d96de1d, a -x cherry-pick of #142's 99a4ab6, because the screen has to exist to be wired; when #142 lands on main that commit becomes redundant and should drop out of a rebase onto main. Retarget this PR to main after #141, #143 and #142 merge, in that order.

What changes

  • App::open_wallet_select (src/tui.rs) now builds its rows from Node::list_wallets() at the moment the screen opens, through a new wallet_rows mapping: name (NULL label to empty, rendered as (unlabelled)), identity_pubkey hex ([u8; 32], not a String), onion_locator passthrough (empty is the - placeholder, not an error), created_at as unix seconds. A failed read is WalletSelectState::error(why).
  • Nothing is cached from startup: F6 w re-reads, so a wallet created or imported in this session is offered the next time the screen opens without a restart.
  • App::choose_wallet resolves WalletChoice::Open(index) against the catalogue as it is now and loads the row at that position. The index is a position, never a store id or an identity key (two records may share one); a list that changed under the screen is reported instead of opening the wrong wallet. + create new wallet still starts the existing create flow (WalletSetup::CreateWarn).
  • New Node::open_wallet(filename) (src/node.rs) is the load step: it refuses a file the catalogue does not hold, re-points the sealed wallet-child record with a read-modify-write (set_wallet_child_config, so the generated RPC creds survive), and restarts a running child onto the new file. An idle child takes the change on its next start_wallet_child.
  • App::new starts on WalletSelect when the catalogue is non-empty and on the create flow when it is empty. A catalogue that cannot be read starts on the screen's own error state, where the create row still works.
  • SELECT_UNAVAILABLE and its comment are deleted with the state they described, and docs/TUI.md's "Saved wallets" section now describes the wired behaviour and the start screen.

What deliberately did not change

  • The stored identity_pubkey / onion_locator are not pushed into the session. They are catalogue columns recorded at creation: an onion is a locator that rotates (F4) and may be stale or empty, and identity is the roster key the node already holds. The live header keeps reading them from the node, per #141's own contract comment.
  • No F9 menu row for F6 w. It is a nice-to-have from #142, and the menu's row list is pinned by tests/tui_spec.rs (menu_has_..., the endpoint/child/sync/receive/balance/payments/create/import assertion), which this card's scope does not include.
  • No SDK change: Node::open_wallet is additive and UniFFI signatures are untouched, so crates/onionwire-sdk is unaffected.

Evidence

  • cargo test --locked: 35 suites, 0 failures (81 in the lib target).
  • cargo clippy --locked --all-targets -- -D warnings: clean.
  • rustfmt --edition 2024 --check src/tui.rs and src/node.rs: same inherited hunk counts as the base (16 and 2), so no new formatting churn.
  • New tests: node::tests::open_wallet_points_the_child_at_the_chosen_file_and_keeps_the_creds (chosen file, creds kept, choice survives a reopen) and node::tests::open_wallet_refuses_a_file_the_catalogue_does_not_hold; tui::wallet_store_tests (5) over a real store-backed, Tor-free node: start screen both ways, catalogue-to-row mapping, row index over a shared identity key, the create row, and a wallet recorded after startup appearing on the next open.
  • RED first: both open_wallet call sites failed E0599 no method named open_wallet before the method was added.

Test-only additions to src/node.rs that a reviewer should know about: the offline node harness (offline_node, NoDial, PASS) is now pub(crate) and two #[cfg(test)] helpers (test_record_wallet, test_node_with_wallets) were added, because tests/*.rs cannot build a Node (every public constructor bootstraps Tor) and the app-level tests need a real store-backed node. The TUI test helper enters a Tokio runtime before building it — the unbootstrapped Arti client panics TorClient could not get an asynchronous runtime without one.

Joins the three wallet pieces that already existed but were never wired together: the catalogue in the encrypted store (#141, `wt/t_64c9ba3c`), the create/import path that remembers a wallet (#143, `wt/t_511023b6`), and the selection screen (#142, `wt/t_14ac0a3f`). Closes the card criterion "selecting a wallet loads it, creating one persists and appears in the list, and the app remembers wallets across restarts". **Base/stacking.** Base is `wt/t_511023b6` because this needs #141's store API and #143's `Node::wallet_create`/`Node::list_wallets`: neither is on `main` yet. The branch also carries `d96de1d`, a `-x` cherry-pick of #142's `99a4ab6`, because the screen has to exist to be wired; when #142 lands on `main` that commit becomes redundant and should drop out of a rebase onto `main`. Retarget this PR to `main` after #141, #143 and #142 merge, in that order. ## What changes - `App::open_wallet_select` (`src/tui.rs`) now builds its rows from `Node::list_wallets()` at the moment the screen opens, through a new `wallet_rows` mapping: `name` (`NULL` label to empty, rendered as `(unlabelled)`), `identity_pubkey` hex (`[u8; 32]`, not a `String`), `onion_locator` passthrough (empty is the `-` placeholder, not an error), `created_at` as unix seconds. A failed read is `WalletSelectState::error(why)`. - Nothing is cached from startup: `F6 w` re-reads, so a wallet created or imported in this session is offered the next time the screen opens without a restart. - `App::choose_wallet` resolves `WalletChoice::Open(index)` against the catalogue as it is now and loads the row at that position. The index is a position, never a store id or an identity key (two records may share one); a list that changed under the screen is reported instead of opening the wrong wallet. `+ create new wallet` still starts the existing create flow (`WalletSetup::CreateWarn`). - New `Node::open_wallet(filename)` (`src/node.rs`) is the load step: it refuses a file the catalogue does not hold, re-points the sealed wallet-child record with a read-modify-write (`set_wallet_child_config`, so the generated RPC creds survive), and restarts a running child onto the new file. An idle child takes the change on its next `start_wallet_child`. - `App::new` starts on `WalletSelect` when the catalogue is non-empty and on the create flow when it is empty. A catalogue that cannot be read starts on the screen's own error state, where the create row still works. - `SELECT_UNAVAILABLE` and its comment are deleted with the state they described, and `docs/TUI.md`'s "Saved wallets" section now describes the wired behaviour and the start screen. ## What deliberately did not change - The stored `identity_pubkey` / `onion_locator` are **not** pushed into the session. They are catalogue columns recorded at creation: an onion is a locator that rotates (`F4`) and may be stale or empty, and identity is the roster key the node already holds. The live header keeps reading them from the node, per #141's own contract comment. - No `F9` menu row for `F6 w`. It is a nice-to-have from #142, and the menu's row list is pinned by `tests/tui_spec.rs` (`menu_has_...`, the `endpoint/child/sync/receive/balance/payments/create/import` assertion), which this card's scope does not include. - No SDK change: `Node::open_wallet` is additive and UniFFI signatures are untouched, so `crates/onionwire-sdk` is unaffected. ## Evidence - `cargo test --locked`: 35 suites, 0 failures (81 in the lib target). - `cargo clippy --locked --all-targets -- -D warnings`: clean. - `rustfmt --edition 2024 --check src/tui.rs` and `src/node.rs`: same inherited hunk counts as the base (16 and 2), so no new formatting churn. - New tests: `node::tests::open_wallet_points_the_child_at_the_chosen_file_and_keeps_the_creds` (chosen file, creds kept, choice survives a reopen) and `node::tests::open_wallet_refuses_a_file_the_catalogue_does_not_hold`; `tui::wallet_store_tests` (5) over a real store-backed, Tor-free node: start screen both ways, catalogue-to-row mapping, row index over a shared identity key, the create row, and a wallet recorded after startup appearing on the next open. - RED first: both `open_wallet` call sites failed `E0599 no method named open_wallet` before the method was added. Test-only additions to `src/node.rs` that a reviewer should know about: the offline node harness (`offline_node`, `NoDial`, `PASS`) is now `pub(crate)` and two `#[cfg(test)]` helpers (`test_record_wallet`, `test_node_with_wallets`) were added, because `tests/*.rs` cannot build a `Node` (every public constructor bootstraps Tor) and the app-level tests need a real store-backed node. The TUI test helper enters a Tokio runtime before building it — the unbootstrapped Arti client panics `TorClient could not get an asynchronous runtime` without one.
Screen::WalletSelect: a table of saved wallets — name, identity prefix,
locator prefix, creation day — the selected row's full identity and locator
under it, and a `+ create new wallet` row as the last item. j/k or arrows
move, Enter takes the choice, Esc back. Empty, failed and in-flight reads
each get their own copy; a wallet with a NULL label, no published locator or
no usable timestamp reads `(unlabelled)` / `-` / `unknown` rather than blank.

Presentation only. Rows are plain display data (WalletRow) built by the
caller; the render path never reads the store, and the selection is by row
index because two records may share an identity key. Loading a chosen record
into the session is the wallet-store integration step, so the F6 `w` entry
opens the screen on its unavailable state until that accessor lands, and the
create row works today either way.

Evidence: tests/tui_select.rs (16 tests) drives the real draw path through
TestBackend at 80x24, 120x40 and 200x60, pins the dumped frame's footer to
status_footer_phased(..., wallet_select_footer_hint()), asserts exactly one
focus marker, a cell-width line budget from 20 to 200 columns, the window
disclosure with the create row always visible, hostile labels (ESC/BEL/C1/
bidi/newline/tab) and the crate-local UTC date formatter.

(cherry picked from commit 99a4ab640e)
tui: read the wallet list from the store and load the chosen wallet
All checks were successful
ci / test (pull_request) Successful in 6m14s
android-ci / android (pull_request) Successful in 12m16s
ci / sdk (pull_request) Successful in 1m30s
ci / fuzz (pull_request) Successful in 4m50s
8986724848
The selection screen shipped as presentation only: `F6 w` opened its
unavailable state, the rows were never read, and Enter on a wallet said
switching was not wired up. The catalogue, the create path and the screen
all existed; nothing joined them.

- `App::open_wallet_select` builds its rows from `Node::list_wallets` at
  the moment the screen opens (never cached from startup), and a failed
  read is the screen's own error state rather than "no saved wallets".
- `App::choose_wallet` resolves `WalletChoice::Open(index)` against the
  catalogue as it is now — the index is a position, and two saved wallets
  may share an identity key — then loads it. `+ create new wallet` still
  starts the existing create flow.
- `Node::open_wallet(filename)` is the load: it refuses a file the
  catalogue does not hold, re-points the sealed wallet-child record with a
  read-modify-write (the generated RPC creds survive), and restarts a
  running child onto the new file. An idle child takes the change on its
  next start.
- `App::new` starts on the selection screen when the catalogue is
  non-empty and on the create flow when it is empty, so a restart lands on
  the wallets it remembers and a first run has no dead empty list.
- The stored identity/locator stay catalogue columns: a locator rotates
  (F4) and identity is the roster key the node already holds, so the live
  header keeps reading them from the node.
- `SELECT_UNAVAILABLE` is gone with the state it described; docs/TUI.md
  now describes the wired behaviour.

Tests (both new): `Node::open_wallet` over an offline node — the chosen
file, the creds kept across the read-modify-write, the choice surviving a
reopen, and a non-catalogue file refused; and the app path in src/tui.rs
over a real store-backed node — start screen both ways, catalogue mapping,
row index over a shared identity, the create row, and a wallet recorded
after startup appearing the next time the list opens.
sirius merged commit eacaae7ad6 into wt/t_511023b6 2026-09-21 18:40:13 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!144
No description provided.