TUI: node control, chain-source picker, honest wallet sync readiness
Add the TUI control plane for the wallet child and chain source, stacked on the wallet-child-lifecycle card: - Chain-source picker (s): receive-only / local monerod / remote daemon with daemon-address entry + trust-shift warning for clearnet hosts - Node control (n): start/stop the app-owned monero-wallet-rpc child, with fail-closed onion+SOCKS guard in the status line - Wallet screen refreshes after picker/child changes, shows sync progress from the daemon and the chain-source/free-space/storage status line - Honest spend guard: wallet view reflects real WalletStatus + Readiness so balance/transfer rendering only claims authority when the daemon is reachable, never while the child is silent - Help overlay + footer hints updated for the new 's'/'n' keys - Tests: chain-source round-trip through sealed record, saved-source starts the child, parse_source handles the 'none' kind
This commit is contained in:
parent
ee5b25488b
commit
cfdfe38536
6 changed files with 1364 additions and 82 deletions
|
|
@ -12,12 +12,15 @@
|
|||
//! They are the known-wrong metric (see `chars_count_is_not_terminal_cells`).
|
||||
|
||||
use onionwire::qr;
|
||||
use onionwire::node::{DaemonSync, WalletChildState};
|
||||
use onionwire::tui::{
|
||||
backup_screen_text, banner_for_width, compact_banner, draw_share, fingerprint_mismatch_banner,
|
||||
help_overlay_text, main_footer_hints, onion_glyph, quit_screen_text, restore_screen_text,
|
||||
rotate_screen_text, status_footer, who_overlay_text, wipe_screen_text, wordmark_banner,
|
||||
ProfileEditor, WipeKind,
|
||||
backup_screen_text, banner_for_width, chain_view, compact_banner, draw_share, draw_wallet,
|
||||
fingerprint_mismatch_banner, help_overlay_text, main_footer_hints, onion_glyph,
|
||||
quit_screen_text, restore_screen_text, rotate_screen_text, status_footer, wallet_readiness,
|
||||
wallet_view, who_overlay_text, wipe_screen_text, wordmark_banner, ChainChoice, ProfileEditor,
|
||||
WalletReadiness, WALLET_LINE_MAX, WipeKind,
|
||||
};
|
||||
use onionwire::wallet::ChainSource;
|
||||
use onionwire::FriendProfile;
|
||||
use ratatui::backend::TestBackend;
|
||||
use ratatui::layout::{Constraint, Layout, Rect};
|
||||
|
|
@ -553,3 +556,163 @@ fn chars_count_is_not_terminal_cells() {
|
|||
let ellipsis = "…";
|
||||
assert_eq!(ellipsis.chars().count(), 1);
|
||||
}
|
||||
|
||||
/// The F6 screen's not-ready state is a spec of this card, so this draws the
|
||||
/// **real** `draw_wallet` at a fixed size and reads the cells back.
|
||||
fn wallet_screen_at(w: u16, h: u16, view: &onionwire::tui::WalletView) -> String {
|
||||
let backend = TestBackend::new(w, h);
|
||||
let mut terminal = Terminal::new(backend).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| draw_wallet(f, view, None))
|
||||
.expect("draw");
|
||||
let buf = terminal.backend().buffer();
|
||||
let mut screen = String::new();
|
||||
for y in 0..h {
|
||||
for x in 0..w {
|
||||
screen.push_str(buf[(x, y)].symbol());
|
||||
}
|
||||
screen.push('\n');
|
||||
}
|
||||
screen
|
||||
}
|
||||
|
||||
fn local_source() -> ChainSource {
|
||||
ChainSource::Local {
|
||||
monerod_bin: std::path::PathBuf::from("monerod"),
|
||||
datadir: std::path::PathBuf::from("/home/user/.onionwire/chain"),
|
||||
}
|
||||
}
|
||||
|
||||
fn address() -> String {
|
||||
"4AdYaG7wVQ3nHvWoXbN9dQkXj1uYcR2mS8pT5LzE6fK7gB3aD".to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wallet_screen_says_not_ready_and_never_a_balance_before_sync() {
|
||||
let chain = chain_view(
|
||||
&local_source(),
|
||||
WalletChildState::Stopped,
|
||||
&DaemonSync {
|
||||
reachable: false,
|
||||
height: 0,
|
||||
target_height: 0,
|
||||
note: Some("127.0.0.1:18081: Connection refused (os error 111)".into()),
|
||||
},
|
||||
Some(412),
|
||||
wallet_readiness(true, false, false),
|
||||
);
|
||||
let view = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), chain);
|
||||
|
||||
assert_eq!(
|
||||
view.balance, "not synced — unavailable",
|
||||
"a balance must not be rendered as a fact while the wallet has not synced"
|
||||
);
|
||||
assert!(!view.chain.ready);
|
||||
for line in view.chain.lines() {
|
||||
assert!(
|
||||
line.chars().count() <= WALLET_LINE_MAX,
|
||||
"chain line exceeds {WALLET_LINE_MAX}: {line:?}"
|
||||
);
|
||||
}
|
||||
|
||||
let screen = wallet_screen_at(80, 24, &view);
|
||||
for needle in [
|
||||
"not ready: wallet RPC not answering",
|
||||
"daemon: stopped — press n to start it",
|
||||
"chain: local monerod",
|
||||
"sync: unknown — 127.0.0.1:18081: Connection refused",
|
||||
"storage: 412 GB free here",
|
||||
"not synced — unavailable",
|
||||
"pruned nodes are not archives",
|
||||
] {
|
||||
assert!(screen.contains(needle), "wallet screen missing {needle:?}:\n{screen}");
|
||||
}
|
||||
// Nothing is clipped: every chain line survives whole.
|
||||
for line in view.chain.lines() {
|
||||
assert!(screen.contains(&line), "clipped line {line:?}:\n{screen}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wallet_screen_says_receive_only_when_nothing_is_configured() {
|
||||
let chain = chain_view(
|
||||
&ChainSource::None,
|
||||
WalletChildState::Off,
|
||||
&DaemonSync {
|
||||
reachable: false,
|
||||
height: 0,
|
||||
target_height: 0,
|
||||
note: Some("receive-only: no daemon".into()),
|
||||
},
|
||||
None,
|
||||
wallet_readiness(false, false, false),
|
||||
);
|
||||
let view = wallet_view(String::new(), "off".to_string(), Vec::new(), chain);
|
||||
let screen = wallet_screen_at(80, 24, &view);
|
||||
for needle in [
|
||||
"chain: receive-only",
|
||||
"daemon: not configured — press s to choose a chain source",
|
||||
"not ready: no wallet — receive-only until c create / i import",
|
||||
"no address yet",
|
||||
] {
|
||||
assert!(screen.contains(needle), "wallet screen missing {needle:?}:\n{screen}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wallet_screen_keeps_the_balance_when_the_wallet_is_ready() {
|
||||
let chain = chain_view(
|
||||
&local_source(),
|
||||
WalletChildState::Running,
|
||||
&DaemonSync {
|
||||
reachable: true,
|
||||
height: 3_210_000,
|
||||
target_height: 3_210_000,
|
||||
note: None,
|
||||
},
|
||||
Some(412),
|
||||
wallet_readiness(true, true, false),
|
||||
);
|
||||
let view = wallet_view(
|
||||
address(),
|
||||
"12.5 XMR".to_string(),
|
||||
Vec::new(),
|
||||
chain,
|
||||
);
|
||||
assert!(view.chain.ready);
|
||||
assert_eq!(view.balance, "12.5 XMR");
|
||||
let screen = wallet_screen_at(80, 24, &view);
|
||||
assert!(screen.contains("ready: wallet synced"), "{screen}");
|
||||
assert!(screen.contains("sync: synced — height 3210000"), "{screen}");
|
||||
assert!(screen.contains("12.5 XMR"), "{screen}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_view_only_wallet_says_so_instead_of_offering_a_spend() {
|
||||
let readiness = wallet_readiness(true, true, true);
|
||||
assert_eq!(readiness, WalletReadiness::ViewOnly);
|
||||
assert!(!readiness.ready());
|
||||
assert!(readiness.line().contains("view-only"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chain_choice_never_preselects_a_remote_daemon() {
|
||||
for (source, want) in [
|
||||
(ChainSource::None, ChainChoice::ReceiveOnly),
|
||||
(local_source(), ChainChoice::LocalMonerod),
|
||||
(
|
||||
ChainSource::Remote {
|
||||
host: "node.example.com".into(),
|
||||
port: 18089,
|
||||
},
|
||||
ChainChoice::RemoteDaemon,
|
||||
),
|
||||
] {
|
||||
assert_eq!(ChainChoice::of(&source), want);
|
||||
}
|
||||
assert_eq!(ChainChoice::ALL.len(), 3, "three choices, never a public node");
|
||||
for choice in ChainChoice::ALL {
|
||||
assert!(!choice.label().is_empty());
|
||||
assert!(!choice.detail().is_empty());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue