remove redundant selectability for session keys in validators tab

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch 2025-02-17 15:14:22 +03:00
parent 08e0f3d576
commit 9d346172b6
Signed by: str3tch
GPG Key ID: 84F3190747EE79AA
3 changed files with 7 additions and 97 deletions

View File

@ -2,7 +2,7 @@
name = "ghost-eye" name = "ghost-eye"
authors = ["str3tch <stretch@ghostchain.io>"] authors = ["str3tch <stretch@ghostchain.io>"]
description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost" description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost"
version = "0.3.32" version = "0.3.33"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -52,7 +52,6 @@ use withdraw_popup::WithdrawPopup;
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]
pub enum CurrentTab { pub enum CurrentTab {
Nothing, Nothing,
StashInfo,
ListenAddresses, ListenAddresses,
NominatorsByValidator, NominatorsByValidator,
History, History,
@ -118,15 +117,13 @@ impl Validator {
CurrentTab::Withdrawals => self.current_tab = CurrentTab::History, CurrentTab::Withdrawals => self.current_tab = CurrentTab::History,
CurrentTab::History => self.current_tab = CurrentTab::NominatorsByValidator, CurrentTab::History => self.current_tab = CurrentTab::NominatorsByValidator,
CurrentTab::NominatorsByValidator => self.current_tab = CurrentTab::ListenAddresses, CurrentTab::NominatorsByValidator => self.current_tab = CurrentTab::ListenAddresses,
CurrentTab::ListenAddresses => self.current_tab = CurrentTab::StashInfo,
_ => {} _ => {}
} }
} }
fn move_right(&mut self) { fn move_right(&mut self) {
match self.current_tab { match self.current_tab {
CurrentTab::Nothing => self.current_tab = CurrentTab::StashInfo, CurrentTab::Nothing => self.current_tab = CurrentTab::ListenAddresses,
CurrentTab::StashInfo => self.current_tab = CurrentTab::ListenAddresses,
CurrentTab::ListenAddresses => self.current_tab = CurrentTab::NominatorsByValidator, CurrentTab::ListenAddresses => self.current_tab = CurrentTab::NominatorsByValidator,
CurrentTab::NominatorsByValidator => self.current_tab = CurrentTab::History, CurrentTab::NominatorsByValidator => self.current_tab = CurrentTab::History,
CurrentTab::History => self.current_tab = CurrentTab::Withdrawals, CurrentTab::History => self.current_tab = CurrentTab::Withdrawals,
@ -267,7 +264,7 @@ impl Component for Validator {
match action { match action {
Action::SetActiveScreen(Mode::Validator) => { Action::SetActiveScreen(Mode::Validator) => {
self.is_active = true; self.is_active = true;
self.current_tab = CurrentTab::StashInfo; self.current_tab = CurrentTab::ListenAddresses;
} }
Action::PayoutValidatorPopup(_, _) => { Action::PayoutValidatorPopup(_, _) => {
self.previous_tab = self.current_tab; self.previous_tab = self.current_tab;

View File

@ -3,16 +3,12 @@ use std::fs::File;
use std::io::{Write, BufRead, BufReader}; use std::io::{Write, BufRead, BufReader};
use color_eyre::Result; use color_eyre::Result;
use crossterm::event::{KeyCode, KeyEvent}; use ratatui::layout::Constraint;
use ratatui::layout::{Constraint, Margin};
use ratatui::style::{Modifier, Stylize}; use ratatui::style::{Modifier, Stylize};
use ratatui::{ use ratatui::{
text::Text, text::Text,
layout::{Alignment, Rect}, layout::{Alignment, Rect},
widgets::{ widgets::{Block, Cell, Row, Table},
Block, Cell, Row, Table, TableState, Scrollbar,
ScrollbarOrientation, ScrollbarState,
},
Frame Frame
}; };
@ -42,8 +38,6 @@ pub struct StashInfo {
action_tx: Option<UnboundedSender<Action>>, action_tx: Option<UnboundedSender<Action>>,
network_tx: Option<Sender<Action>>, network_tx: Option<Sender<Action>>,
palette: StylePalette, palette: StylePalette,
scroll_state: ScrollbarState,
table_state: TableState,
stash_pair: Option<PairSigner<CasperConfig, Pair>>, stash_pair: Option<PairSigner<CasperConfig, Pair>>,
stash_address: String, stash_address: String,
session_keys: std::collections::HashMap<String, SessionKeyInfo>, session_keys: std::collections::HashMap<String, SessionKeyInfo>,
@ -63,8 +57,6 @@ impl StashInfo {
is_active: false, is_active: false,
action_tx: None, action_tx: None,
network_tx: None, network_tx: None,
scroll_state: ScrollbarState::new(0),
table_state: TableState::new(),
palette: StylePalette::default(), palette: StylePalette::default(),
stash_address: String::new(), stash_address: String::new(),
stash_pair: None, stash_pair: None,
@ -81,51 +73,6 @@ impl StashInfo {
} }
} }
fn first_row(&mut self) {
if self.session_keys.len() > 0 {
self.table_state.select(Some(0));
self.scroll_state = self.scroll_state.position(0);
}
}
fn next_row(&mut self) {
let i = match self.table_state.selected() {
Some(i) => {
if i >= self.session_keys.len() - 1 {
i
} else {
i + 1
}
},
None => 0,
};
self.table_state.select(Some(i));
self.scroll_state = self.scroll_state.position(i);
}
fn last_row(&mut self) {
if self.session_keys.len() > 0 {
let last = self.session_keys.len() - 1;
self.table_state.select(Some(last));
self.scroll_state = self.scroll_state.position(last);
}
}
fn previous_row(&mut self) {
let i = match self.table_state.selected() {
Some(i) => {
if i == 0 {
0
} else {
i - 1
}
},
None => 0
};
self.table_state.select(Some(i));
self.scroll_state = self.scroll_state.position(i);
}
fn read_or_create_stash(&mut self) -> Result<()> { fn read_or_create_stash(&mut self) -> Result<()> {
match File::open(&self.stash_filepath) { match File::open(&self.stash_filepath) {
Ok(file) => { Ok(file) => {
@ -230,16 +177,7 @@ impl StashInfo {
} }
impl PartialComponent for StashInfo { impl PartialComponent for StashInfo {
fn set_active(&mut self, current_tab: CurrentTab) { fn set_active(&mut self, _current_tab: CurrentTab) { }
match current_tab {
CurrentTab::StashInfo => self.is_active = true,
_ => {
self.is_active = false;
self.table_state.select(None);
self.scroll_state = self.scroll_state.position(0);
}
}
}
} }
impl Component for StashInfo { impl Component for StashInfo {
@ -276,19 +214,6 @@ impl Component for StashInfo {
Ok(None) Ok(None)
} }
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
if self.is_active {
match key.code {
KeyCode::Up | KeyCode::Char('k') => self.previous_row(),
KeyCode::Down | KeyCode::Char('j') => self.next_row(),
KeyCode::Char('g') => self.first_row(),
KeyCode::Char('G') => self.last_row(),
_ => {},
};
}
Ok(None)
}
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> { fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
let [place, _] = super::validator_session_and_listen_layout(area); let [place, _] = super::validator_session_and_listen_layout(area);
let (border_style, border_type) = self.palette.create_border_style(self.is_active); let (border_style, border_type) = self.palette.create_border_style(self.is_active);
@ -340,19 +265,7 @@ impl Component for StashInfo {
.title_style(self.palette.create_title_style(false)) .title_style(self.palette.create_title_style(false))
.title(self.stash_address.clone())); .title(self.stash_address.clone()));
let scrollbar = Scrollbar::default() frame.render_widget(table, place);
.orientation(ScrollbarOrientation::VerticalRight)
.begin_symbol(None)
.end_symbol(None)
.style(self.palette.create_scrollbar_style());
frame.render_stateful_widget(table, place, &mut self.table_state);
frame.render_stateful_widget(
scrollbar,
place.inner(Margin { vertical: 1, horizontal: 1 }),
&mut self.scroll_state,
);
Ok(()) Ok(())
} }
} }