tui: send screen readiness guard + view-only badge + no-address refusal
Send screen now carries WalletReadiness and no_spend fields, populated from Node::wallet_readiness at form open. The confirm line reflects: - readiness refusal (NOT_CONFIGURED_MSG / NOT_CONNECTED_MSG / VIEW_ONLY_MSG) - friend has no address (NO_ADDRESS_MSG) - no recipient - amount invalid - ready (Enter) Spend badge 'view-only — /tip off' shown on both /tip and /pay when the wallet is no-spend. send_form_confirm_enabled() gates Enter dispatch. Tests: 10 new tests for readiness states, amount errors, badge visibility, and width fit at all readiness states.
This commit is contained in:
parent
cee53cfd73
commit
b3052b8277
2 changed files with 876 additions and 42 deletions
|
|
@ -5,12 +5,15 @@ use onionwire::Message;
|
|||
use onionwire::outbox::{OutboxEntry, OutboxStatus};
|
||||
use onionwire::qr;
|
||||
use onionwire::Payment;
|
||||
use onionwire::wallet;
|
||||
use onionwire::tui::{
|
||||
ConfigField, ConfigStatus, OutboxSummary, WalletConfigScreen, alert_line, ascii_chrome,
|
||||
chat_with_delivery, delivery_tag, draw_chat, draw_history, draw_share, draw_text_overlay,
|
||||
empty_friend_chat_text, help_overlay_text, history_detail, history_row_text, is_onion_host,
|
||||
main_footer_hints, main_header_line, parse_daemon_addr, paste_screen_text, retry_in_text,
|
||||
roster_col_width, short_send_reason, status_footer, wrap_invite,
|
||||
ConfigField, ConfigStatus, NO_ADDRESS_MSG, OutboxSummary, SendForm, SendPane, VIEW_ONLY_BADGE,
|
||||
WalletConfigScreen, WalletReadiness, alert_line, ascii_chrome, chat_with_delivery, delivery_tag,
|
||||
draw_chat, draw_history, draw_send, draw_share, draw_text_overlay, empty_friend_chat_text,
|
||||
help_overlay_text, history_detail, history_row_text, is_onion_host, main_footer_hints,
|
||||
main_header_line, parse_daemon_addr, paste_screen_text, retry_in_text, roster_col_width,
|
||||
send_footer_hints, send_form_confirm_enabled, send_form_ready, send_form_resolved,
|
||||
short_send_reason, status_footer, wrap_invite,
|
||||
};
|
||||
use onionwire::wallet::PingResult;
|
||||
use ratatui::Frame;
|
||||
|
|
@ -227,6 +230,33 @@ fn dump_spec_frames() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dump_send_frames() {
|
||||
for (w, h) in [(80u16, 24u16), (120, 40)] {
|
||||
let form = SendForm {
|
||||
friend_fp: "AB:CD:EF:01:23:45".to_string(),
|
||||
friend_petname: Some("alice".to_string()),
|
||||
friend_xmr: "4AaaaaBBBBccccDDDDEeee".to_string(),
|
||||
is_tip: true,
|
||||
amount: "0.001".to_string(),
|
||||
memo: "coffee".to_string(),
|
||||
amount_err: None,
|
||||
focused: SendPane::Confirm,
|
||||
readiness: WalletReadiness::Ready,
|
||||
no_spend: false,
|
||||
friend_no_address: false,
|
||||
};
|
||||
let hints = send_footer_hints();
|
||||
let backend = TestBackend::new(w, h);
|
||||
let mut terminal = Terminal::new(backend).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| draw_send(f, &form, hints))
|
||||
.expect("draw");
|
||||
println!("===== AFTER send {w}x{h} =====");
|
||||
print!("{}", screen_from(terminal.backend().buffer(), w, h));
|
||||
}
|
||||
}
|
||||
|
||||
fn sample_invite() -> String {
|
||||
let sk = [7u8; 32];
|
||||
qr::encode(&sk, ONION, &[1u8; 32]).expect("encode")
|
||||
|
|
@ -1350,3 +1380,419 @@ fn wallet_config_focus_cycles_through_fields() {
|
|||
assert_eq!(ConfigField::NoSpend.prev(), ConfigField::RpcLogin);
|
||||
assert_eq!(ConfigField::Action.prev(), ConfigField::NoSpend);
|
||||
}
|
||||
|
||||
// Send / tip flow screen (card C5)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const SEND_FP: &str = "abcdef0123456789deadbeefcafebabe";
|
||||
const SEND_ADDR: &str = "4A1234567890abcdef4A1234567890abcdef4A1234567890abcdef4A12345678";
|
||||
|
||||
fn friend_form() -> SendForm {
|
||||
SendForm {
|
||||
friend_fp: SEND_FP.to_string(),
|
||||
friend_petname: Some("alice".to_string()),
|
||||
friend_xmr: SEND_ADDR.to_string(),
|
||||
is_tip: false,
|
||||
amount: "0.01".to_string(),
|
||||
memo: String::new(),
|
||||
amount_err: None,
|
||||
focused: SendPane::Recipient,
|
||||
readiness: WalletReadiness::Ready,
|
||||
no_spend: false,
|
||||
friend_no_address: false,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_form_resolved_accepts_valid_xmr_amount() {
|
||||
let form = friend_form();
|
||||
assert_eq!(send_form_resolved(&form), Ok("10000000000".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_form_resolved_rejects_empty_amount() {
|
||||
let mut form = friend_form();
|
||||
form.amount = String::new();
|
||||
assert!(
|
||||
send_form_resolved(&form).is_err(),
|
||||
"empty amount should fail"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_form_ready_requires_friend_and_valid_amount() {
|
||||
let form = friend_form();
|
||||
assert!(
|
||||
send_form_ready(&form),
|
||||
"ready: friend present + valid amount + 0.01 atomic"
|
||||
);
|
||||
|
||||
let mut no_friend = form.clone();
|
||||
no_friend.friend_fp.clear();
|
||||
no_friend.friend_xmr.clear();
|
||||
assert!(
|
||||
!send_form_ready(&no_friend),
|
||||
"missing friend must not be ready"
|
||||
);
|
||||
|
||||
let mut bad = form.clone();
|
||||
bad.amount = String::new();
|
||||
assert!(
|
||||
!send_form_ready(&bad),
|
||||
"empty amount must not be ready"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_form_ready_for_tip_path() {
|
||||
let mut form = friend_form();
|
||||
form.is_tip = true;
|
||||
form.focused = SendPane::Confirm;
|
||||
assert!(send_form_ready(&form), "tip path with tip=true should still resolve");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_screen_fits_80x24_and_shows_fields() {
|
||||
let form = friend_form();
|
||||
let hints = send_footer_hints();
|
||||
assert!(hints.contains("Enter confirm"));
|
||||
assert!(hints.contains("Esc back"));
|
||||
|
||||
for (w, h) in [(80u16, 24u16), (120, 40)] {
|
||||
let backend = TestBackend::new(w, h);
|
||||
let mut terminal = Terminal::new(backend).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| draw_send(f, &form, hints))
|
||||
.expect("draw");
|
||||
let screen = screen_from(terminal.backend().buffer(), w, h);
|
||||
for line in screen.lines() {
|
||||
assert!(
|
||||
line.chars().count() <= w as usize,
|
||||
"line wider than {w} at {w}x{h}: {line:?}"
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
screen.contains("request invoice") || screen.contains("pay friend"),
|
||||
"send screen missing title at {w}x{h}\n{screen}"
|
||||
);
|
||||
assert!(
|
||||
screen.contains("to alice"),
|
||||
"send screen missing recipient at {w}x{h}\n{screen}"
|
||||
);
|
||||
assert!(
|
||||
screen.contains("amount"),
|
||||
"send screen missing amount field at {w}x{h}\n{screen}"
|
||||
);
|
||||
assert!(
|
||||
screen.contains("0.01"),
|
||||
"send screen missing amount value at {w}x{h}\n{screen}"
|
||||
);
|
||||
assert!(
|
||||
screen.contains("memo"),
|
||||
"send screen missing memo field at {w}x{h}\n{screen}"
|
||||
);
|
||||
assert!(
|
||||
screen.contains(&form.friend_xmr),
|
||||
"send screen missing xmr address at {w}x{h}\n{screen}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_screen_shows_amount_error() {
|
||||
let mut form = friend_form();
|
||||
form.amount = "xyz".to_string();
|
||||
form.amount_err = Some("invalid XMR amount".to_string());
|
||||
form.focused = SendPane::Amount;
|
||||
let hints = send_footer_hints();
|
||||
|
||||
let backend = TestBackend::new(80, 24);
|
||||
let mut terminal = Terminal::new(backend).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| draw_send(f, &form, hints))
|
||||
.expect("draw");
|
||||
let screen = screen_from(terminal.backend().buffer(), 80, 24);
|
||||
assert!(
|
||||
screen.contains("invalid XMR amount"),
|
||||
"error not shown
|
||||
{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_screen_shows_confirm_when_ready() {
|
||||
let mut form = friend_form();
|
||||
form.focused = SendPane::Confirm;
|
||||
let hints = send_footer_hints();
|
||||
|
||||
let backend = TestBackend::new(80, 24);
|
||||
let mut terminal = Terminal::new(backend).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| draw_send(f, &form, hints))
|
||||
.expect("draw");
|
||||
let screen = screen_from(terminal.backend().buffer(), 80, 24);
|
||||
assert!(
|
||||
screen.contains("ready"),
|
||||
"confirm row should show ready state
|
||||
{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_screen_disabled_when_no_friend() {
|
||||
let mut form = friend_form();
|
||||
form.friend_fp.clear();
|
||||
form.friend_xmr.clear();
|
||||
form.friend_petname = None;
|
||||
form.focused = SendPane::Confirm;
|
||||
let hints = send_footer_hints();
|
||||
|
||||
let backend = TestBackend::new(80, 24);
|
||||
let mut terminal = Terminal::new(backend).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| draw_send(f, &form, hints))
|
||||
.expect("draw");
|
||||
let screen = screen_from(terminal.backend().buffer(), 80, 24);
|
||||
assert!(
|
||||
screen.contains("no recipient"),
|
||||
"disabled state should show 'no recipient'\n{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
// --- Readiness guard: the send screen must refuse with the exact contract strings.
|
||||
|
||||
fn not_configured_form(is_tip: bool) -> SendForm {
|
||||
let mut form = friend_form();
|
||||
form.is_tip = is_tip;
|
||||
form.readiness = WalletReadiness::NotConfigured;
|
||||
form
|
||||
}
|
||||
|
||||
fn view_only_form(is_tip: bool) -> SendForm {
|
||||
let mut form = friend_form();
|
||||
form.is_tip = is_tip;
|
||||
form.no_spend = true;
|
||||
// /pay on view-only is allowed by the readiness guard; only /tip is blocked.
|
||||
form.readiness = if is_tip {
|
||||
WalletReadiness::ViewOnly
|
||||
} else {
|
||||
WalletReadiness::Ready
|
||||
};
|
||||
form
|
||||
}
|
||||
|
||||
fn not_connected_form(is_tip: bool) -> SendForm {
|
||||
let mut form = friend_form();
|
||||
form.is_tip = is_tip;
|
||||
form.readiness = WalletReadiness::NotConnected;
|
||||
form
|
||||
}
|
||||
|
||||
fn no_address_form() -> SendForm {
|
||||
let mut form = friend_form();
|
||||
form.friend_no_address = true;
|
||||
form
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_form_confirm_disabled_when_not_configured() {
|
||||
let form = not_configured_form(true);
|
||||
assert!(
|
||||
!send_form_confirm_enabled(&form),
|
||||
"not-configured must block confirm"
|
||||
);
|
||||
let screen = draw_send_screen(&form);
|
||||
assert!(
|
||||
screen.contains("wallet not configured"),
|
||||
"screen must show not-configured refusal\n{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_form_confirm_disabled_when_view_only_tip() {
|
||||
let form = view_only_form(true);
|
||||
assert!(
|
||||
!send_form_confirm_enabled(&form),
|
||||
"view-only must block /tip confirm"
|
||||
);
|
||||
let screen = draw_send_screen(&form);
|
||||
assert!(
|
||||
screen.contains("view-only/no-spend mode"),
|
||||
"screen must show VIEW_ONLY_MSG\n{screen}"
|
||||
);
|
||||
assert!(
|
||||
screen.contains(VIEW_ONLY_BADGE),
|
||||
"screen must show spend badge\n{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_form_confirm_disabled_when_view_only_pay() {
|
||||
// /pay on view-only is allowed (invoice), but the badge still shows.
|
||||
// Runtime: open_send with is_tip=false returns WalletReadiness::Ready
|
||||
// for a no-spend wallet (pay is fine on view-only).
|
||||
let form = view_only_form(false);
|
||||
assert!(
|
||||
send_form_confirm_enabled(&form),
|
||||
"/pay on view-only should still confirm"
|
||||
);
|
||||
let screen = draw_send_screen(&form);
|
||||
// Badge shows on /pay too — view-only is a real mode.
|
||||
assert!(
|
||||
screen.contains(VIEW_ONLY_BADGE),
|
||||
"view-only badge should show even for /pay\n{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_form_confirm_disabled_when_not_connected() {
|
||||
let form = not_connected_form(true);
|
||||
assert!(
|
||||
!send_form_confirm_enabled(&form),
|
||||
"not-connected must block confirm"
|
||||
);
|
||||
let screen = draw_send_screen(&form);
|
||||
assert!(
|
||||
screen.contains(wallet::NOT_CONNECTED_MSG),
|
||||
"screen must show NOT_CONNECTED_MSG\n{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_form_confirm_disabled_when_friend_has_no_address() {
|
||||
let form = no_address_form();
|
||||
assert!(
|
||||
!send_form_confirm_enabled(&form),
|
||||
"no-address friend must block confirm"
|
||||
);
|
||||
let screen = draw_send_screen(&form);
|
||||
assert!(
|
||||
screen.contains(NO_ADDRESS_MSG),
|
||||
"screen must show NO_ADDRESS_MSG\n{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_screen_shows_amount_must_be_positive() {
|
||||
let mut form = friend_form();
|
||||
form.amount = String::new();
|
||||
form.amount_err = Some("amount must be > 0".to_string());
|
||||
form.focused = SendPane::Amount;
|
||||
let screen = draw_send_screen(&form);
|
||||
assert!(
|
||||
screen.contains("amount must be > 0"),
|
||||
"zero/empty amount error not shown\n{screen}"
|
||||
);
|
||||
assert!(
|
||||
!send_form_confirm_enabled(&form),
|
||||
"empty amount must not confirm"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_screen_shows_invalid_amount_error() {
|
||||
let mut form = friend_form();
|
||||
form.amount = "abc".to_string();
|
||||
form.amount_err = Some("invalid XMR amount".to_string());
|
||||
form.focused = SendPane::Amount;
|
||||
let screen = draw_send_screen(&form);
|
||||
assert!(
|
||||
screen.contains("invalid XMR amount"),
|
||||
"amount parse error not shown\n{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_screen_shows_negative_amount_error() {
|
||||
let mut form = friend_form();
|
||||
form.amount = "-1.0".to_string();
|
||||
form.amount_err = Some("invalid XMR amount".to_string());
|
||||
form.focused = SendPane::Amount;
|
||||
let screen = draw_send_screen(&form);
|
||||
assert!(
|
||||
screen.contains("invalid XMR amount"),
|
||||
"negative amount error not shown\n{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_screen_fits_80x24_at_all_readiness_states() {
|
||||
let hints = send_footer_hints();
|
||||
for readiness in [
|
||||
WalletReadiness::Ready,
|
||||
WalletReadiness::NotConfigured,
|
||||
WalletReadiness::NotConnected,
|
||||
WalletReadiness::ViewOnly,
|
||||
] {
|
||||
let mut form = friend_form();
|
||||
form.readiness = readiness;
|
||||
for (w, h) in [(80u16, 24u16), (120, 40)] {
|
||||
let backend = TestBackend::new(w, h);
|
||||
let mut terminal = Terminal::new(backend).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| draw_send(f, &form, hints))
|
||||
.expect("draw");
|
||||
let screen = screen_from(terminal.backend().buffer(), w, h);
|
||||
for line in screen.lines() {
|
||||
assert!(
|
||||
line.chars().count() <= w as usize,
|
||||
"line wider than {w} at {w}x{h} readiness={readiness:?}: {line:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_send_screen(form: &SendForm) -> String {
|
||||
let hints = send_footer_hints();
|
||||
let backend = TestBackend::new(80, 24);
|
||||
let mut terminal = Terminal::new(backend).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| draw_send(f, form, hints))
|
||||
.expect("draw");
|
||||
screen_from(terminal.backend().buffer(), 80, 24)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dump_send_refusal_frames() {
|
||||
let hints = send_footer_hints();
|
||||
let cases = [
|
||||
("empty form 80x24", {
|
||||
let mut f = friend_form();
|
||||
f.amount.clear();
|
||||
f.amount_err = Some("amount must be > 0".to_string());
|
||||
f.focused = SendPane::Amount;
|
||||
f
|
||||
}),
|
||||
("view-only tip refusal", {
|
||||
let mut f = friend_form();
|
||||
f.is_tip = true;
|
||||
f.no_spend = true;
|
||||
f.readiness = WalletReadiness::ViewOnly;
|
||||
f
|
||||
}),
|
||||
("not-configured refusal", {
|
||||
let mut f = friend_form();
|
||||
f.readiness = WalletReadiness::NotConfigured;
|
||||
f
|
||||
}),
|
||||
("not-connected refusal", {
|
||||
let mut f = friend_form();
|
||||
f.readiness = WalletReadiness::NotConnected;
|
||||
f
|
||||
}),
|
||||
("no-address friend", {
|
||||
let mut f = friend_form();
|
||||
f.friend_no_address = true;
|
||||
f
|
||||
}),
|
||||
];
|
||||
for (label, form) in cases {
|
||||
let backend = TestBackend::new(80, 24);
|
||||
let mut terminal = Terminal::new(backend).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| draw_send(f, &form, hints))
|
||||
.expect("draw");
|
||||
println!("===== AFTER send: {label} 80x24 =====\n{}", screen_from(terminal.backend().buffer(), 80, 24));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue