diff --git a/Cargo.toml b/Cargo.toml index 1aa0696..ab63969 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "ghost-eye" authors = ["str3tch "] description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost" -version = "0.3.55" +version = "0.3.56" edition = "2021" homepage = "https://git.ghostchain.io/ghostchain" repository = "https://git.ghostchain.io/ghostchain/ghost-eye" diff --git a/src/action.rs b/src/action.rs index 2b3cc0f..052d389 100644 --- a/src/action.rs +++ b/src/action.rs @@ -36,6 +36,7 @@ pub enum Action { ClosePopup, RotateSessionKeys, PayoutValidatorPopup(u32, bool), + WithdrawValidatorPopup, BalanceRequest([u8; 32], bool), BalanceResponse([u8; 32], Option), diff --git a/src/components/validator/mod.rs b/src/components/validator/mod.rs index 46b3938..1fd055e 100644 --- a/src/components/validator/mod.rs +++ b/src/components/validator/mod.rs @@ -244,6 +244,10 @@ impl Component for Validator { self.previous_tab = self.current_tab; self.current_tab = CurrentTab::PayoutPopup; } + Action::WithdrawValidatorPopup => { + self.previous_tab = self.current_tab; + self.current_tab = CurrentTab::WithdrawPopup; + }, Action::ClosePopup => self.current_tab = self.previous_tab, _ => {}, } diff --git a/src/components/validator/payout_popup.rs b/src/components/validator/payout_popup.rs index df68075..5d1d561 100644 --- a/src/components/validator/payout_popup.rs +++ b/src/components/validator/payout_popup.rs @@ -112,6 +112,7 @@ impl Component for PayoutPopup { } Ok(()) } + fn handle_key_event(&mut self, key: KeyEvent) -> Result> { if self.is_active && key.kind == KeyEventKind::Press { match key.code { diff --git a/src/components/validator/withdrawals.rs b/src/components/validator/withdrawals.rs index b719ff3..dee1cd0 100644 --- a/src/components/validator/withdrawals.rs +++ b/src/components/validator/withdrawals.rs @@ -11,9 +11,10 @@ use ratatui::{ }, Frame }; +use tokio::sync::mpsc::UnboundedSender; use super::{PartialComponent, Component, CurrentTab}; -use crate::types::UnlockChunk; +use crate::types::{ActionTarget, ActionLevel, UnlockChunk}; use crate::{ action::Action, config::Config, @@ -22,6 +23,7 @@ use crate::{ pub struct Withdrawals { is_active: bool, + action_tx: Option>, palette: StylePalette, scroll_state: ScrollbarState, table_state: TableState, @@ -43,6 +45,7 @@ impl Withdrawals { pub fn new() -> Self { Self { is_active: false, + action_tx: None, scroll_state: ScrollbarState::new(0), table_state: TableState::new(), palette: StylePalette::default(), @@ -52,6 +55,21 @@ impl Withdrawals { } } + fn try_open_popup(&mut self) { + if let Some(action_tx) = &self.action_tx { + if let Some(index) = self.table_state.selected() { + if index == 0 && self.unlockings[0].era > self.current_era { + let _ = action_tx.send(Action::WithdrawValidatorPopup); + } else { + let _ = action_tx.send(Action::EventLog( + "Nothing to be witdrawn yet on the selected unlocking".to_string(), + ActionLevel::Info, + ActionTarget::ValidatorLog)); + } + } + } + } + fn first_row(&mut self) { if self.unlockings.len() > 0 { self.table_state.select(Some(0)); @@ -143,6 +161,11 @@ impl PartialComponent for Withdrawals { } impl Component for Withdrawals { + fn register_action_handler(&mut self, tx: UnboundedSender) -> Result<()> { + self.action_tx = Some(tx); + Ok(()) + } + fn register_config_handler(&mut self, config: Config) -> Result<()> { if let Some(style) = config.styles.get(&crate::app::Mode::Validator) { self.palette.with_normal_style(style.get("normal_style").copied()); @@ -175,6 +198,7 @@ impl Component for Withdrawals { KeyCode::Down | KeyCode::Char('j') => self.next_row(), KeyCode::Char('g') => self.first_row(), KeyCode::Char('G') => self.last_row(), + KeyCode::Enter => self.try_open_popup(), _ => {}, }; }