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
642
src/tui.rs
642
src/tui.rs
|
|
@ -11,12 +11,12 @@ use ratatui::widgets::{Block, Borders, Clear, List, ListItem, ListState, Paragra
|
|||
use ratatui::{DefaultTerminal, Frame};
|
||||
use zeroize::{Zeroize, Zeroizing};
|
||||
|
||||
use crate::node::Node;
|
||||
use crate::node::{DaemonSync, Node, WalletChildState};
|
||||
use crate::outbox::DEFAULT_MAX_ATTEMPTS;
|
||||
use crate::qr::{self, QrPayload};
|
||||
use crate::sanitize;
|
||||
use crate::store::{Friend, FriendProfile, Message, OutboxEntry, OutboxStatus};
|
||||
use crate::wallet;
|
||||
use crate::wallet::{self, ChainSource, Readiness};
|
||||
|
||||
const C_ACCENT: Color = Color::Rgb(232, 165, 75);
|
||||
const C_TEXT: Color = Color::Rgb(196, 214, 176);
|
||||
|
|
@ -454,7 +454,9 @@ OnionWire keys\n\
|
|||
F3 paste invite\n\
|
||||
F4 rotate onion locator\n\
|
||||
F5 selected friend's profile (/who)\n\
|
||||
F6 wallet (receive QR, create/import)\n\
|
||||
F6 wallet (receive address, chain source)\n\
|
||||
F6 s chain source: receive-only / local / remote\n\
|
||||
F6 n start or stop the app-owned daemon\n\
|
||||
/profile edit name, bio, Monero address\n\
|
||||
/pay <xmr> [memo] invoice to receive\n\
|
||||
/tip <xmr> [memo] pay selected friend\n\
|
||||
|
|
@ -1123,11 +1125,10 @@ enum Screen {
|
|||
entry: PassphraseEntry,
|
||||
},
|
||||
Wallet {
|
||||
receive_addr: String,
|
||||
balance: String,
|
||||
transfers: Vec<wallet::TransferRow>,
|
||||
view: WalletView,
|
||||
qr_modal: Option<QrModal>,
|
||||
},
|
||||
ChainSetup(ChainSetup),
|
||||
WalletSetup(WalletSetup),
|
||||
Quit {
|
||||
prompt: QuitPrompt,
|
||||
|
|
@ -1142,6 +1143,284 @@ enum WalletSetup {
|
|||
ImportPass { seed: Zeroizing<String>, entry: PassphraseEntry },
|
||||
}
|
||||
|
||||
/// 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)]
|
||||
pub enum WalletReadiness {
|
||||
/// Configured, answered, and spend-capable: balance is authoritative.
|
||||
Ready,
|
||||
/// No wallet file / no RPC endpoint at all. Receive-only still works.
|
||||
NotConfigured,
|
||||
/// Configured but the RPC has not answered (child stopped, bad login).
|
||||
NotConnected,
|
||||
/// Answers, but `ONIONWIRE_WALLET_NO_SPEND=1`: balance is real, spend is not.
|
||||
ViewOnly,
|
||||
}
|
||||
|
||||
/// `wallet::readiness` for the wallet screen: it asks "can this wallet spend?",
|
||||
/// which is what a balance implies.
|
||||
pub fn wallet_readiness(configured: bool, connected: bool, no_spend: bool) -> WalletReadiness {
|
||||
match wallet::readiness(configured, connected, no_spend, true) {
|
||||
Readiness::Ready => WalletReadiness::Ready,
|
||||
Readiness::NotConfigured => WalletReadiness::NotConfigured,
|
||||
Readiness::NotConnected => WalletReadiness::NotConnected,
|
||||
Readiness::NoSpend => WalletReadiness::ViewOnly,
|
||||
}
|
||||
}
|
||||
|
||||
impl WalletReadiness {
|
||||
/// Whether the balance may be shown as a fact.
|
||||
pub fn ready(self) -> bool {
|
||||
matches!(self, Self::Ready)
|
||||
}
|
||||
|
||||
/// The line the wallet screen prints. While this is not the ready line, the
|
||||
/// balance below it is not an offer.
|
||||
pub fn line(self) -> &'static str {
|
||||
match self {
|
||||
Self::Ready => "ready: wallet synced — spend and receipt verification available",
|
||||
Self::NotConfigured => "not ready: no wallet — receive-only until c create / i import",
|
||||
Self::NotConnected => "not ready: wallet RPC not answering — balance is not authoritative",
|
||||
Self::ViewOnly => "view-only wallet: spend is refused locally, before any dial",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Lines that must fit the wallet body at 80 columns (the body is inset by a
|
||||
/// border: 78 usable, 76 with slack).
|
||||
pub const WALLET_LINE_MAX: usize = 76;
|
||||
|
||||
/// The chain half of the wallet screen: what the user chose, whether the child
|
||||
/// is up, how far the daemon is, and whether the wallet can be trusted to show
|
||||
/// a balance yet.
|
||||
pub struct ChainView {
|
||||
pub source_line: String,
|
||||
pub child_line: String,
|
||||
pub sync_line: String,
|
||||
pub storage_line: String,
|
||||
pub status_line: String,
|
||||
/// `WalletReadiness::Ready` — the balance is authoritative only then.
|
||||
pub ready: bool,
|
||||
}
|
||||
|
||||
impl ChainView {
|
||||
/// Every line this block renders, in draw order. The render test asserts
|
||||
/// these fit; the draw prints exactly them.
|
||||
pub fn lines(&self) -> Vec<String> {
|
||||
[
|
||||
&self.source_line,
|
||||
&self.child_line,
|
||||
&self.sync_line,
|
||||
&self.storage_line,
|
||||
&self.status_line,
|
||||
]
|
||||
.iter()
|
||||
.flat_map(|l| l.lines())
|
||||
.map(str::to_string)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// A pruned node is a real trade-off and the screen says so instead of implying
|
||||
/// an archive.
|
||||
pub const PRUNED_NOTE: &str = "pruned nodes are not archives: a deep seed restore can degrade. once this wallet has scanned, its own cache is the history";
|
||||
|
||||
/// Why `.onion` chain traffic cannot start here yet, in plain words. The raw
|
||||
/// child error names an argv; the user needs the missing piece.
|
||||
pub const ONION_NO_SOCKS_MSG: &str =
|
||||
"a remote .onion daemon needs a local SOCKS listener.\nthis build does not have one yet — pick a local monerod,\nor a clearnet/loopback daemon you run yourself.";
|
||||
|
||||
/// The three choices the picker offers, in order. A public node is never one of
|
||||
/// them and a remote daemon is never preselected.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ChainChoice {
|
||||
ReceiveOnly,
|
||||
LocalMonerod,
|
||||
RemoteDaemon,
|
||||
}
|
||||
|
||||
impl ChainChoice {
|
||||
pub const ALL: [ChainChoice; 3] = [Self::ReceiveOnly, Self::LocalMonerod, Self::RemoteDaemon];
|
||||
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::ReceiveOnly => "receive-only (no daemon)",
|
||||
Self::LocalMonerod => "spawn a local monerod",
|
||||
Self::RemoteDaemon => "enter a daemon address",
|
||||
}
|
||||
}
|
||||
|
||||
/// One line under the label, so the choice is not a mystery.
|
||||
pub fn detail(self) -> &'static str {
|
||||
match self {
|
||||
Self::ReceiveOnly => "chain traffic stays off this device entirely",
|
||||
Self::LocalMonerod => "the app owns monerod; chain stays on this device",
|
||||
Self::RemoteDaemon => "someone else's daemon: they see your addresses",
|
||||
}
|
||||
}
|
||||
|
||||
/// Which choice the stored source corresponds to. A stored source is shown
|
||||
/// as the current pick, never as a preselected remote.
|
||||
pub fn of(source: &ChainSource) -> Self {
|
||||
match source {
|
||||
ChainSource::None => Self::ReceiveOnly,
|
||||
ChainSource::Local { .. } => Self::LocalMonerod,
|
||||
ChainSource::Remote { .. } => Self::RemoteDaemon,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum ChainSetup {
|
||||
Choose {
|
||||
index: usize,
|
||||
},
|
||||
RemoteAddr {
|
||||
buf: String,
|
||||
err: Option<String>,
|
||||
},
|
||||
/// The trust shift, shown before anything is saved.
|
||||
RemoteWarn {
|
||||
host: String,
|
||||
port: u16,
|
||||
onion: bool,
|
||||
},
|
||||
}
|
||||
|
||||
/// What the F6 wallet screen draws. Built through [`wallet_view`] so the
|
||||
/// not-ready rules are testable without a live node.
|
||||
pub struct WalletView {
|
||||
pub receive_addr: String,
|
||||
pub balance: String,
|
||||
pub transfers: Vec<wallet::TransferRow>,
|
||||
pub chain: ChainView,
|
||||
}
|
||||
|
||||
/// Assemble the wallet screen, applying the one rule that matters: while the
|
||||
/// wallet is not ready the balance is **not** rendered as a fact.
|
||||
pub fn wallet_view(
|
||||
receive_addr: String,
|
||||
balance: String,
|
||||
transfers: Vec<wallet::TransferRow>,
|
||||
chain: ChainView,
|
||||
) -> WalletView {
|
||||
if chain.ready {
|
||||
WalletView {
|
||||
receive_addr,
|
||||
balance,
|
||||
transfers,
|
||||
chain,
|
||||
}
|
||||
} else {
|
||||
WalletView {
|
||||
receive_addr,
|
||||
balance: "not synced — unavailable".to_string(),
|
||||
transfers: Vec::new(),
|
||||
chain,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pure builder for the chain block: every honest-status rule lives here.
|
||||
pub fn chain_view(
|
||||
source: &ChainSource,
|
||||
child: WalletChildState,
|
||||
sync: &DaemonSync,
|
||||
free_gb: Option<u64>,
|
||||
readiness: WalletReadiness,
|
||||
) -> ChainView {
|
||||
let source_line = match source {
|
||||
ChainSource::None => "chain: receive-only — no daemon, no chain traffic".to_string(),
|
||||
ChainSource::Local {
|
||||
monerod_bin,
|
||||
datadir,
|
||||
} => format!(
|
||||
"chain: local monerod ({}) — chain in {}",
|
||||
monerod_bin.display(),
|
||||
datadir.display()
|
||||
),
|
||||
ChainSource::Remote { host, port } => format!("chain: remote daemon {host}:{port}"),
|
||||
};
|
||||
let child_line = match child {
|
||||
WalletChildState::Off => "daemon: not configured — press s to choose a chain source",
|
||||
WalletChildState::Stopped => "daemon: stopped — press n to start it",
|
||||
WalletChildState::Running => "daemon: running (child owned by this app)",
|
||||
}
|
||||
.to_string();
|
||||
let sync_line = if sync.reachable {
|
||||
if sync.synced() {
|
||||
format!("sync: synced — height {}", sync.height)
|
||||
} else {
|
||||
format!("sync: syncing — {}/{}", sync.height, sync.target_height)
|
||||
}
|
||||
} else {
|
||||
format!(
|
||||
"sync: unknown — {}",
|
||||
sync.note.as_deref().unwrap_or("no daemon")
|
||||
)
|
||||
};
|
||||
let storage_line = match (source, free_gb) {
|
||||
(ChainSource::Local { .. }, Some(gb)) => format!(
|
||||
"storage: {gb} GB free here — pruned mainnet wants ~50-60 GB, a full node ~200 GB"
|
||||
),
|
||||
(ChainSource::Local { .. }, None) => "storage: could not read free space".to_string(),
|
||||
(ChainSource::Remote { .. }, _) => {
|
||||
"storage: on the daemon operator's disk, not yours".to_string()
|
||||
}
|
||||
(ChainSource::None, _) => "storage: nothing stored on this device".to_string(),
|
||||
};
|
||||
ChainView {
|
||||
source_line: truncate_chars(&source_line, WALLET_LINE_MAX),
|
||||
child_line: truncate_chars(&child_line, WALLET_LINE_MAX),
|
||||
sync_line: truncate_chars(&sync_line, WALLET_LINE_MAX),
|
||||
storage_line: truncate_chars(&storage_line, WALLET_LINE_MAX),
|
||||
status_line: readiness.line().to_string(),
|
||||
ready: readiness.ready(),
|
||||
}
|
||||
}
|
||||
|
||||
/// `.onion` chain traffic needs the SOCKS listener this build does not have
|
||||
/// yet. Checked before anything is dialled or spawned.
|
||||
pub fn is_onion_host(host: &str) -> bool {
|
||||
host.trim().to_ascii_lowercase().ends_with(".onion")
|
||||
}
|
||||
|
||||
/// `host:port` from the picker's address field.
|
||||
///
|
||||
/// A `.onion`, a loopback host, and a clearnet host are all accepted — clearnet
|
||||
/// only because the user typed it here. There is no default port: picking one
|
||||
/// would be us choosing a daemon for them.
|
||||
pub fn parse_daemon_addr(raw: &str) -> Result<(String, u16), String> {
|
||||
let s = raw.trim();
|
||||
if s.is_empty() {
|
||||
return Err("enter host:port".into());
|
||||
}
|
||||
if s.chars().any(char::is_whitespace) {
|
||||
return Err("no spaces in host:port".into());
|
||||
}
|
||||
let (host, port) = s
|
||||
.rsplit_once(':')
|
||||
.ok_or_else(|| "missing :port — write host:port".to_string())?;
|
||||
let host = host.trim();
|
||||
if host.is_empty() {
|
||||
return Err("missing host — write host:port".into());
|
||||
}
|
||||
if host.contains('/') {
|
||||
return Err("no path — host:port only".into());
|
||||
}
|
||||
let port: u16 = port
|
||||
.trim()
|
||||
.parse()
|
||||
.map_err(|_| "port must be 1-65535".to_string())?;
|
||||
if port == 0 {
|
||||
return Err("port must be 1-65535".into());
|
||||
}
|
||||
Ok((host.to_string(), port))
|
||||
}
|
||||
|
||||
/// The budget for the daemon `get_info` probe behind the sync line. Short on
|
||||
/// purpose: a dead daemon must show as unknown, not freeze the screen.
|
||||
pub const CHAIN_SYNC_BUDGET: Duration = Duration::from_secs(2);
|
||||
|
||||
impl App {
|
||||
fn new(node: Arc<Node>, rt: tokio::runtime::Handle) -> Result<Self, String> {
|
||||
let friends = node.list_friends()?;
|
||||
|
|
@ -1425,6 +1704,8 @@ impl App {
|
|||
Screen::Wallet { .. } => match key.code {
|
||||
KeyCode::Esc => self.screen = Screen::Main,
|
||||
KeyCode::Char('r') | KeyCode::Enter => self.wallet_toggle_qr(),
|
||||
KeyCode::Char('s') => self.open_chain_setup(),
|
||||
KeyCode::Char('n') => self.toggle_wallet_child(),
|
||||
KeyCode::Char('c') => {
|
||||
self.screen = Screen::WalletSetup(WalletSetup::CreateWarn {
|
||||
typed: String::new(),
|
||||
|
|
@ -1437,6 +1718,7 @@ impl App {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
Screen::ChainSetup(_) => self.handle_chain_setup(key)?,
|
||||
Screen::WalletSetup(_) => self.handle_wallet_setup(key)?,
|
||||
Screen::Quit { prompt } => match key.code {
|
||||
KeyCode::Esc => self.screen = Screen::Main,
|
||||
|
|
@ -1642,27 +1924,217 @@ impl App {
|
|||
}
|
||||
|
||||
fn open_wallet(&mut self) -> Result<(), String> {
|
||||
let addr = self.rt.block_on(self.node.wallet_receive_address())?;
|
||||
let balance = self.rt.block_on(self.node.wallet_balance());
|
||||
let transfers = self.rt.block_on(self.node.wallet_recent_transfers(8)).unwrap_or_default();
|
||||
self.screen = Screen::Wallet {
|
||||
receive_addr: addr,
|
||||
balance,
|
||||
transfers,
|
||||
view: self.build_wallet_view(),
|
||||
qr_modal: None,
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Draw state for the wallet screen.
|
||||
///
|
||||
/// One probe per open/refresh, then everything the screen says comes from
|
||||
/// that answer: a balance rendered while the RPC is silent is the lie this
|
||||
/// screen must not tell. Not being configured is a state to *show* (F6 must
|
||||
/// open either way), not an error to bail out of.
|
||||
fn build_wallet_view(&self) -> WalletView {
|
||||
let status = self.rt.block_on(self.node.wallet_refresh());
|
||||
let no_spend = self
|
||||
.node
|
||||
.wallet_config()
|
||||
.map(|c| c.no_spend)
|
||||
.unwrap_or(false);
|
||||
let readiness = wallet_readiness(status.configured, status.connected, no_spend);
|
||||
let source = self.node.wallet_chain_source();
|
||||
let child = self.node.wallet_child_state();
|
||||
let sync = self
|
||||
.rt
|
||||
.block_on(self.node.wallet_chain_sync(CHAIN_SYNC_BUDGET));
|
||||
let chain = chain_view(
|
||||
&source,
|
||||
child,
|
||||
&sync,
|
||||
self.node.wallet_chain_free_gb(),
|
||||
readiness,
|
||||
);
|
||||
let receive_addr = self
|
||||
.rt
|
||||
.block_on(self.node.wallet_receive_address())
|
||||
.unwrap_or_default();
|
||||
let balance = self.rt.block_on(self.node.wallet_balance());
|
||||
let transfers = self
|
||||
.rt
|
||||
.block_on(self.node.wallet_recent_transfers(8))
|
||||
.unwrap_or_default();
|
||||
wallet_view(receive_addr, balance, transfers, chain)
|
||||
}
|
||||
|
||||
/// Re-read the wallet screen after something changed what it shows.
|
||||
fn refresh_wallet(&mut self) {
|
||||
let view = self.build_wallet_view();
|
||||
if let Screen::Wallet { view: slot, .. } = &mut self.screen {
|
||||
*slot = view;
|
||||
}
|
||||
}
|
||||
|
||||
/// `s`: pick the chain source, with the stored choice shown as current.
|
||||
fn open_chain_setup(&mut self) {
|
||||
let current = ChainChoice::of(&self.node.wallet_chain_source());
|
||||
let index = ChainChoice::ALL
|
||||
.iter()
|
||||
.position(|c| *c == current)
|
||||
.unwrap_or(0);
|
||||
self.screen = Screen::ChainSetup(ChainSetup::Choose { index });
|
||||
}
|
||||
|
||||
/// `n`: start or stop the app-owned child.
|
||||
///
|
||||
/// A failure here is a normal thing to learn ("monerod is not on PATH"), so
|
||||
/// it lands on the screen as a note, never as a fatal error that closes the
|
||||
/// app.
|
||||
fn toggle_wallet_child(&mut self) {
|
||||
if let ChainSource::Remote { host, .. } = self.node.wallet_chain_source()
|
||||
&& is_onion_host(&host)
|
||||
{
|
||||
// Say the missing piece in plain words, before any spawn attempt
|
||||
// turns into a raw argv error.
|
||||
self.status_note = Some(ONION_NO_SOCKS_MSG.replace('\n', " "));
|
||||
self.refresh_wallet();
|
||||
return;
|
||||
}
|
||||
let result = match self.node.wallet_child_state() {
|
||||
WalletChildState::Running => self.node.wallet_child_stop(),
|
||||
_ => self.node.wallet_child_start(),
|
||||
};
|
||||
self.status_note = Some(match result {
|
||||
Ok(()) => match self.node.wallet_child_state() {
|
||||
WalletChildState::Running => "wallet child started".to_string(),
|
||||
_ => "wallet child stopped".to_string(),
|
||||
},
|
||||
Err(e) => format!("wallet child: {e}"),
|
||||
});
|
||||
self.refresh_wallet();
|
||||
}
|
||||
|
||||
/// Chain-source picker keys. Kept as one state machine so the picker cannot
|
||||
/// leave the wallet screen in a half-open state.
|
||||
fn handle_chain_setup(&mut self, key: KeyEvent) -> Result<(), String> {
|
||||
let mut pick = None;
|
||||
let mut warn = None;
|
||||
let mut save = false;
|
||||
let mut back = false;
|
||||
{
|
||||
let Screen::ChainSetup(setup) = &mut self.screen else {
|
||||
return Ok(());
|
||||
};
|
||||
match setup {
|
||||
ChainSetup::Choose { index } => match key.code {
|
||||
KeyCode::Esc => back = true,
|
||||
KeyCode::Up | KeyCode::Char('k') => *index = index.saturating_sub(1),
|
||||
KeyCode::Down | KeyCode::Char('j') => {
|
||||
*index = (*index + 1).min(ChainChoice::ALL.len() - 1)
|
||||
}
|
||||
KeyCode::Enter => pick = Some(ChainChoice::ALL[*index]),
|
||||
_ => {}
|
||||
},
|
||||
ChainSetup::RemoteAddr { buf, err } => match key.code {
|
||||
KeyCode::Esc => back = true,
|
||||
KeyCode::Backspace => {
|
||||
buf.pop();
|
||||
*err = None;
|
||||
}
|
||||
KeyCode::Enter => match parse_daemon_addr(buf) {
|
||||
Ok((host, port)) => {
|
||||
warn = Some((host, port));
|
||||
}
|
||||
Err(e) => *err = Some(e),
|
||||
},
|
||||
KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
buf.push(c);
|
||||
*err = None;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
ChainSetup::RemoteWarn { .. } => match key.code {
|
||||
KeyCode::Esc => back = true,
|
||||
KeyCode::Enter => save = true,
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
}
|
||||
if let Some(choice) = pick {
|
||||
match choice {
|
||||
ChainChoice::RemoteDaemon => {
|
||||
self.screen = Screen::ChainSetup(ChainSetup::RemoteAddr {
|
||||
buf: String::new(),
|
||||
err: None,
|
||||
});
|
||||
}
|
||||
ChainChoice::ReceiveOnly => self.apply_chain_source(ChainSource::None, None),
|
||||
ChainChoice::LocalMonerod => {
|
||||
let source = self.node.default_local_chain_source();
|
||||
self.apply_chain_source(source, None);
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if let Some((host, port)) = warn {
|
||||
let onion = is_onion_host(&host);
|
||||
self.screen = Screen::ChainSetup(ChainSetup::RemoteWarn {
|
||||
host,
|
||||
port,
|
||||
onion,
|
||||
});
|
||||
return Ok(());
|
||||
}
|
||||
if save {
|
||||
let Screen::ChainSetup(ChainSetup::RemoteWarn { host, port, .. }) = &self.screen else {
|
||||
return Ok(());
|
||||
};
|
||||
let source = ChainSource::Remote {
|
||||
host: host.clone(),
|
||||
port: *port,
|
||||
};
|
||||
let note = if is_onion_host(host) {
|
||||
Some("saved — starting it needs a local SOCKS listener (not wired yet)".to_string())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.apply_chain_source(source, note);
|
||||
return Ok(());
|
||||
}
|
||||
if back {
|
||||
self.screen = Screen::Wallet {
|
||||
view: self.build_wallet_view(),
|
||||
qr_modal: None,
|
||||
};
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Persist a pick and return to the wallet screen, where the choice is
|
||||
/// visible at rest (AC 4). A save that fails says so instead of pretending.
|
||||
fn apply_chain_source(&mut self, source: ChainSource, note: Option<String>) {
|
||||
self.status_note = Some(match self.node.wallet_set_chain_source(&source) {
|
||||
Ok(()) => note.unwrap_or_else(|| "chain source saved".to_string()),
|
||||
Err(e) => format!("chain source not saved: {e}"),
|
||||
});
|
||||
self.screen = Screen::Wallet {
|
||||
view: self.build_wallet_view(),
|
||||
qr_modal: None,
|
||||
};
|
||||
}
|
||||
|
||||
fn wallet_toggle_qr(&mut self) {
|
||||
let Screen::Wallet {
|
||||
ref mut qr_modal,
|
||||
ref receive_addr,
|
||||
ref view,
|
||||
..
|
||||
} = self.screen
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let receive_addr = &view.receive_addr;
|
||||
if let Some(modal) = qr_modal {
|
||||
*qr_modal = if modal.closed {
|
||||
qr_modal.take()
|
||||
|
|
@ -2019,9 +2491,8 @@ impl App {
|
|||
draw_passphrase(f, *kind, entry.first().is_some(), entry.buf())
|
||||
}
|
||||
Screen::Quit { prompt } => draw_quit(f, prompt.typed()),
|
||||
Screen::Wallet { receive_addr, balance, transfers, qr_modal } => {
|
||||
draw_wallet(f, receive_addr, balance, transfers, qr_modal.as_ref())
|
||||
}
|
||||
Screen::Wallet { view, qr_modal } => draw_wallet(f, view, qr_modal.as_ref()),
|
||||
Screen::ChainSetup(setup) => draw_chain_setup(f, setup),
|
||||
Screen::WalletSetup(setup) => draw_wallet_setup(f, setup),
|
||||
}
|
||||
if self.help_open {
|
||||
|
|
@ -2340,7 +2811,8 @@ match screen {
|
|||
BackupKind::Restore => "type RESTORE Esc cancel ? help",
|
||||
},
|
||||
Screen::Passphrase { .. } => "Enter submit Esc cancel ? help",
|
||||
Screen::Wallet { .. } => "c create i import r qr Esc back ? help",
|
||||
Screen::Wallet { .. } => "s chain n node c create i import r qr Esc back ? help",
|
||||
Screen::ChainSetup(_) => "Enter select/save Esc back ? help",
|
||||
Screen::WalletSetup(WalletSetup::CreateWarn { .. }) => "type SPEND Esc cancel ? help",
|
||||
Screen::WalletSetup(WalletSetup::CreatePass { .. } | WalletSetup::ImportPass { .. }) => {
|
||||
"Enter submit Esc cancel ? help"
|
||||
|
|
@ -2583,21 +3055,21 @@ fn to_hex(bytes: &[u8]) -> String {
|
|||
bytes.iter().map(|b| format!("{b:02x}")).collect()
|
||||
}
|
||||
|
||||
/// The `monero:` QR popup over the wallet screen. `pub` (fields private) because
|
||||
/// [`draw_wallet`] takes one: the render spec draws the real screen.
|
||||
#[derive(Clone, Debug)]
|
||||
struct QrModal {
|
||||
pub struct QrModal {
|
||||
closed: bool,
|
||||
matrix_rows: Vec<String>,
|
||||
#[allow(dead_code)]
|
||||
uri: String,
|
||||
}
|
||||
|
||||
fn draw_wallet(
|
||||
f: &mut Frame,
|
||||
receive_addr: &str,
|
||||
balance: &str,
|
||||
transfers: &[wallet::TransferRow],
|
||||
modal: Option<&QrModal>,
|
||||
) {
|
||||
/// The F6 wallet screen.
|
||||
///
|
||||
/// `pub` on purpose: the not-ready render is a spec of this card, so the test
|
||||
/// draws this for real at a fixed size rather than a stand-in.
|
||||
pub fn draw_wallet(f: &mut Frame, view: &WalletView, modal: Option<&QrModal>) {
|
||||
let area = f.area();
|
||||
if let Some(m) = modal {
|
||||
// Clear behind the popup so the body does not bleed through.
|
||||
|
|
@ -2642,9 +3114,7 @@ fn draw_wallet(
|
|||
|
||||
let cols = Layout::vertical([
|
||||
Constraint::Length(2),
|
||||
Constraint::Min(4),
|
||||
Constraint::Length(2),
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(6),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.split(area);
|
||||
|
|
@ -2656,44 +3126,110 @@ fn draw_wallet(
|
|||
cols[0],
|
||||
);
|
||||
|
||||
let addr_line = if receive_addr.is_empty() {
|
||||
"no address".into()
|
||||
let addr_line = if view.receive_addr.is_empty() {
|
||||
"no address yet — /profile xmr, or create a wallet".to_string()
|
||||
} else {
|
||||
receive_addr.to_string()
|
||||
view.receive_addr.clone()
|
||||
};
|
||||
let body = format!(
|
||||
"address
|
||||
{addr_line}
|
||||
|
||||
balance
|
||||
{balance}
|
||||
|
||||
recent transfers
|
||||
"
|
||||
);
|
||||
let mut lines: Vec<String> = body
|
||||
.lines()
|
||||
.map(str::to_string)
|
||||
.collect();
|
||||
if transfers.is_empty() {
|
||||
lines.push(" (none)".into());
|
||||
let mut lines: Vec<String> = vec![
|
||||
format!("address {addr_line}"),
|
||||
format!("balance {}", view.balance),
|
||||
String::new(),
|
||||
"chain".to_string(),
|
||||
];
|
||||
lines.extend(view.chain.lines());
|
||||
lines.push(PRUNED_NOTE.to_string());
|
||||
lines.push(String::new());
|
||||
lines.push("recent transfers".to_string());
|
||||
if view.transfers.is_empty() {
|
||||
lines.push(" (none shown)".to_string());
|
||||
} else {
|
||||
for t in transfers.iter().take(5) {
|
||||
for t in view.transfers.iter().take(4) {
|
||||
let xmr = crate::pay::atomic_to_xmr_str(&t.amount);
|
||||
lines.push(format!(" {} {} XMR", t.txid.chars().take(16).collect::<String>(), xmr));
|
||||
lines.push(format!(
|
||||
" {} {} XMR",
|
||||
t.txid.chars().take(16).collect::<String>(),
|
||||
xmr
|
||||
));
|
||||
}
|
||||
}
|
||||
let help = "c create i import r toggle qr Esc back";
|
||||
lines.push("".into());
|
||||
f.render_widget(
|
||||
Paragraph::new(lines.join("\n"))
|
||||
.style(style_text())
|
||||
.wrap(Wrap { trim: false })
|
||||
.block(apply_chrome_borders(Block::default()).border_style(style_border())),
|
||||
cols[2],
|
||||
cols[1],
|
||||
);
|
||||
|
||||
f.render_widget(Paragraph::new(help).style(style_dim()), cols[3]);
|
||||
let help = "s chain n start/stop c create i import r qr";
|
||||
f.render_widget(Paragraph::new(help).style(style_dim()), cols[2]);
|
||||
}
|
||||
|
||||
/// The chain-source picker and the remote-daemon trust shift, before anything
|
||||
/// is saved.
|
||||
fn draw_chain_setup(f: &mut Frame, setup: &ChainSetup) {
|
||||
let (title, body) = match setup {
|
||||
ChainSetup::Choose { index } => {
|
||||
let mut lines = vec![
|
||||
"where should the chain come from?".to_string(),
|
||||
String::new(),
|
||||
];
|
||||
for (i, choice) in ChainChoice::ALL.iter().enumerate() {
|
||||
let mark = if i == *index { ">" } else { " " };
|
||||
lines.push(format!("{mark} {}", choice.label()));
|
||||
lines.push(format!(" {}", choice.detail()));
|
||||
}
|
||||
lines.push(String::new());
|
||||
lines.push("receive-only needs no wallet file and no daemon.".into());
|
||||
lines.push("spend always needs the create/import flow and".into());
|
||||
lines.push("its SPEND warning — there is no shortcut key.".into());
|
||||
lines.push(String::new());
|
||||
lines.push("Up/Down choose Enter select Esc back".into());
|
||||
("chain source", lines.join("\n"))
|
||||
}
|
||||
ChainSetup::RemoteAddr { buf, err } => {
|
||||
let mut lines = vec![
|
||||
"daemon address, as host:port".to_string(),
|
||||
" e.g. 127.0.0.1:18081 or yournode.onion:18089".to_string(),
|
||||
String::new(),
|
||||
format!("> {buf}"),
|
||||
String::new(),
|
||||
];
|
||||
if let Some(e) = err {
|
||||
lines.push(e.clone());
|
||||
} else {
|
||||
lines.push("Enter continues Esc goes back".into());
|
||||
}
|
||||
("enter daemon address", lines.join("\n"))
|
||||
}
|
||||
ChainSetup::RemoteWarn {
|
||||
host,
|
||||
port,
|
||||
onion,
|
||||
} => {
|
||||
let mut lines = vec![
|
||||
format!("use {host}:{port} for chain traffic?"),
|
||||
String::new(),
|
||||
"the daemon operator sees your addresses during sync,".into(),
|
||||
"and every spend. a remote daemon is untrusted: this".into(),
|
||||
"app never passes --trusted-daemon.".into(),
|
||||
String::new(),
|
||||
];
|
||||
if *onion {
|
||||
lines.push("this is a .onion host, so Tor would hide the transport.".into());
|
||||
lines.push("it still does not hide your addresses from the operator.".into());
|
||||
lines.push(String::new());
|
||||
lines.extend(ONION_NO_SOCKS_MSG.lines().map(str::to_string));
|
||||
} else {
|
||||
lines.push("this is a clearnet host: your ISP can also see that".into());
|
||||
lines.push("this device talks to a Monero node, and which one.".into());
|
||||
}
|
||||
lines.push(String::new());
|
||||
lines.push("Enter saves it Esc cancels".into());
|
||||
("trust shift", lines.join("\n"))
|
||||
}
|
||||
};
|
||||
draw_text_overlay(f, title, &body);
|
||||
}
|
||||
|
||||
fn draw_wallet_setup(f: &mut Frame, setup: &WalletSetup) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue