Lines
96.88 %
Functions
50 %
Branches
100 %
//! Commodity-convert submit and reply handling for `App`.
use cli_core::eval::parse_scalar_reply;
use cli_core::transaction::submit_call;
use forms::{CONVERT, FormValues};
use crate::app::App;
use crate::route::RouteCtx;
impl App {
/// Submit the `convert` form; its ratio reply lands on the status line.
///
/// Returns `None` only when there is no eval worker or it has stopped.
pub fn submit_commodity_convert(
&mut self,
values: &FormValues,
from_label: &str,
to_label: &str,
) -> Option<i64> {
if self.console_eval.is_none() {
self.status = "console not connected".to_string();
return None;
}
let ctx = RouteCtx::ConvertQuery {
amount_str: values.text("amount").unwrap_or_default().to_string(),
from_label: from_label.to_string(),
to_label: to_label.to_string(),
};
let id = self.dispatch_app_eval(ctx, submit_call(&CONVERT, values));
if id.is_none() {
self.status = crate::tabs::nms_eval::UNAVAILABLE.to_string();
id
/// Handle a `convert` reply by formatting a status message.
pub(super) fn deliver_convert_reply(
wire: &str,
amount_str: &str,
) {
match parse_scalar_reply(wire) {
Ok(result) => {
self.status = format!("{amount_str} {from_label} = {result} {to_label}");
Err(e) => self.status = format!("convert failed: {e}"),