1
//! `account balance` from the palette: the typed account is resolved against
2
//! the account options, then its balances print in the Console.
3

            
4
use cli_core::eval::escape_str;
5
use forms::FormValues;
6

            
7
use super::App;
8
use super::lookup::Goal;
9
use crate::command::{BALANCE_ACCOUNT, BALANCE_ARGS};
10
use crate::view::ViewId;
11
use crate::window::Origin;
12

            
13
impl App {
14
    /// Print the balances of the account `input` names, by label or id.
15
5
    pub fn show_account_balance(&mut self, input: &str) {
16
5
        let mut values = FormValues::default();
17
5
        values.set(BALANCE_ACCOUNT, input);
18
5
        let origin = self.window_or_open(ViewId::Console);
19
5
        self.start_lookup(Goal::Balance(origin), &BALANCE_ARGS, values);
20
5
    }
21

            
22
4
    pub(super) fn print_resolved_balance(&mut self, origin: Origin, resolved: &FormValues) {
23
4
        let Some(console) = self.origin_window(origin) else {
24
            return;
25
        };
26
4
        let id = resolved.text(BALANCE_ACCOUNT).unwrap_or_default();
27
4
        self.submit_console_form(console, format!("(get-balances {})", escape_str(id)));
28
4
        self.show_window_if_free(console);
29
4
    }
30
}