Skip to main content

tui/app/
mutation.rs

1//! Mutation-submit methods for `App` (delete, set-tag).
2
3use cli_core::eval::{
4    build_delete_transaction_form, build_set_account_tag_form, build_set_transaction_tag_form,
5};
6
7use crate::app::App;
8use crate::route::RouteCtx;
9use crate::view::ViewId;
10
11impl App {
12    /// Submit a `delete-transaction` mutation. Returns `false` only if the eval worker has stopped.
13    pub fn submit_delete_transaction(&mut self, id: &str) -> bool {
14        let form = build_delete_transaction_form(id);
15        if self.console_eval.is_none() {
16            self.status = "console not connected".to_string();
17            return false;
18        }
19        match self.dispatch_eval(
20            ViewId::Transactions,
21            RouteCtx::Mutation {
22                refresh: ViewId::Transactions,
23            },
24            form,
25        ) {
26            Some(_) => true,
27            None => {
28                self.status = "eval worker stopped".to_string();
29                false
30            }
31        }
32    }
33
34    /// Submit a `set-account-tag` mutation. Returns `false` only if the eval worker has stopped.
35    pub fn submit_account_tag(&mut self, account_id: &str, name: &str, value: &str) -> bool {
36        let form = build_set_account_tag_form(account_id, name, value);
37        if self.console_eval.is_none() {
38            self.status = "console not connected".to_string();
39            return false;
40        }
41        match self.dispatch_eval(
42            ViewId::Accounts,
43            RouteCtx::Mutation {
44                refresh: ViewId::Accounts,
45            },
46            form,
47        ) {
48            Some(_) => true,
49            None => {
50                self.status = "eval worker stopped".to_string();
51                false
52            }
53        }
54    }
55
56    /// Submit a `set-transaction-tag` mutation. Returns `false` only if the eval worker has stopped.
57    pub fn submit_transaction_tag(
58        &mut self,
59        transaction_id: &str,
60        name: &str,
61        value: &str,
62    ) -> bool {
63        let form = build_set_transaction_tag_form(transaction_id, name, value);
64        if self.console_eval.is_none() {
65            self.status = "console not connected".to_string();
66            return false;
67        }
68        match self.dispatch_eval(
69            ViewId::Transactions,
70            RouteCtx::Mutation {
71                refresh: ViewId::Transactions,
72            },
73            form,
74        ) {
75            Some(_) => true,
76            None => {
77                self.status = "eval worker stopped".to_string();
78                false
79            }
80        }
81    }
82}