diff --git a/Cargo.toml b/Cargo.toml index c4feea7..adbfa29 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.45" +version = "0.3.46" 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 80e29e6..9422a8d 100644 --- a/src/action.rs +++ b/src/action.rs @@ -105,7 +105,6 @@ pub enum Action { GetSlashingSpans([u8; 32], bool), GetValidatorLatestClaim([u8; 32], bool), GetValidatorIsDisabled([u8; 32], bool), - GetValidatorInSession([u8; 32], bool), GetCurrentValidatorEraRewards, SetNodeName(Option), @@ -135,7 +134,6 @@ pub enum Action { SetValidatorEraSlash(u32, u128), SetValidatorEraUnlocking(Vec, [u8; 32]), SetValidatorLatestClaim(u32, [u8; 32]), - SetValidatorInSession(bool, [u8; 32]), SetIsBonded(bool, [u8; 32]), SetStakedAmountRatio(Option, Option, [u8; 32]), SetStakedRatio(u128, u128, [u8; 32]), diff --git a/src/components/nominator/current_validator_details.rs b/src/components/nominator/current_validator_details.rs index f5ed658..5039b95 100644 --- a/src/components/nominator/current_validator_details.rs +++ b/src/components/nominator/current_validator_details.rs @@ -73,9 +73,9 @@ impl CurrentValidatorDetails { fn prepare_state_string(&self) -> String { if self.is_active_validator { - "active staking".to_string() + "active".to_string() } else { - "stop staking".to_string() + "chilling".to_string() } } diff --git a/src/components/validator/reward_details.rs b/src/components/validator/reward_details.rs index 7761e32..336bbff 100644 --- a/src/components/validator/reward_details.rs +++ b/src/components/validator/reward_details.rs @@ -8,6 +8,7 @@ use ratatui::{ }; use super::{PartialComponent, Component, CurrentTab}; +use crate::types::EraRewardPoints; use crate::widgets::DotSpinner; use crate::{ action::Action, @@ -23,8 +24,10 @@ pub struct RewardDetails { inflation: String, stash: [u8; 32], in_staking_validators: bool, - in_session_validators: bool, + in_queued_keys: bool, + in_next_keys: bool, is_disabled: bool, + in_rewards: bool, } impl Default for RewardDetails { @@ -43,8 +46,10 @@ impl RewardDetails { inflation: String::from("0.0%"), stash: [0u8; 32], in_staking_validators: false, - in_session_validators: false, + in_queued_keys: false, + in_next_keys: false, is_disabled: false, + in_rewards: false, } } @@ -57,6 +62,16 @@ impl RewardDetails { None => DotSpinner::default().to_string(), } } + + fn update_individual(&mut self, individual: &Vec) { + let (is_disabled, in_rewards) = individual + .iter() + .find(|data| data.account_id == self.stash) + .map(|data| (data.disabled, true)) + .unwrap_or((false, false)); + self.is_disabled = is_disabled; + self.in_rewards = in_rewards; + } } impl PartialComponent for RewardDetails { @@ -81,18 +96,19 @@ impl Component for RewardDetails { fn update(&mut self, action: Action) -> Result> { match action { Action::SetStashAccount(stash) => self.stash = stash, - Action::SetCurrentValidatorEraRewards(_, _, individual) => self.is_disabled = individual - .iter() - .find(|data| data.account_id == self.stash) - .map(|data| data.disabled) - .unwrap_or_default(), - Action::SetValidatorInSession(in_session_validators, account_id) if self.stash == account_id => - self.in_session_validators = in_session_validators, + Action::SetCurrentValidatorEraRewards(_, _, individual) => self.update_individual(&individual), Action::SetValidatorPrefs(commission, disabled, account_id) if self.stash == account_id => { self.commission = commission; self.in_staking_validators = commission.is_some(); self.nominators_blocked = disabled; } + Action::SetSessionKey(name, session_key_info) => { + if name.starts_with("q_") { + self.in_queued_keys = !session_key_info.key.is_empty(); + } else { + self.in_next_keys = !session_key_info.key.is_empty(); + } + }, Action::Apy(apy) => self.apy = apy, Action::Inflation(inflation) => self.inflation = inflation, _ => {} @@ -104,16 +120,19 @@ impl Component for RewardDetails { let [_, _, place] = super::validator_balance_layout(area); let (border_style, border_type) = self.palette.create_border_style(false); - let staking_status = if self.is_disabled { - "Staking status: Disabled".to_string() + let status = if self.is_disabled { + "Disabled" } else { - match (self.in_staking_validators, self.in_session_validators) { - (false, false) => "Staking status: Nothing".to_string(), - (true, false) => "Staking status: Stopping".to_string(), - (false, true) => "Staking status: Pending".to_string(), - (true, true) => "Staking status: Active".to_string(), + let is_fully_in_session = self.in_queued_keys && self.in_next_keys; + match (self.in_staking_validators, is_fully_in_session) { + (true, true) => "Active", + (true, false) => "Rotating", + (false, true) if self.in_rewards => { "Stopping" } + (false, true) if !self.in_rewards => { "Chill" } + _ => "Nothing", } }; + let staking_status = format!("Staking status: {status}"); let table = Table::new( vec![ diff --git a/src/components/validator/stash_info.rs b/src/components/validator/stash_info.rs index 3da03bb..0f6dbf5 100644 --- a/src/components/validator/stash_info.rs +++ b/src/components/validator/stash_info.rs @@ -160,7 +160,6 @@ impl StashInfo { let _ = network_tx.send(Action::GetValidatorAllRewards(account_id, true)); let _ = network_tx.send(Action::GetSlashingSpans(account_id, true)); let _ = network_tx.send(Action::GetValidatorIsDisabled(account_id, true)); - let _ = network_tx.send(Action::GetValidatorInSession(account_id, true)); } } diff --git a/src/network/mod.rs b/src/network/mod.rs index 349ea0b..2a963b9 100644 --- a/src/network/mod.rs +++ b/src/network/mod.rs @@ -118,7 +118,6 @@ impl Network { predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &stash_to_watch).await?; predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &stash_to_watch).await?; predefined_calls::get_slashing_spans(&self.action_tx, &self.online_client_api, &stash_to_watch).await?; - predefined_calls::get_validator_in_session(&self.action_tx, &self.online_client_api, &stash_to_watch).await?; for era_index in self.eras_to_watch.iter() { predefined_calls::get_validator_staking_result(&self.action_tx, &self.online_client_api, &stash_to_watch, *era_index).await?; @@ -209,10 +208,6 @@ impl Network { Ok(()) } - Action::GetValidatorInSession(account_id, is_stash) => { - self.store_stash_or_validator_if_possible(account_id, is_stash); - predefined_calls::get_validator_in_session(&self.action_tx, &self.online_client_api, &account_id).await - } Action::GetValidatorLatestClaim(account_id, is_stash) => { self.store_stash_or_validator_if_possible(account_id, is_stash); predefined_calls::get_validator_latest_claim(&self.action_tx, &self.online_client_api, &account_id).await diff --git a/src/network/predefined_calls.rs b/src/network/predefined_calls.rs index 895e50b..720a4f9 100644 --- a/src/network/predefined_calls.rs +++ b/src/network/predefined_calls.rs @@ -581,18 +581,3 @@ pub async fn get_validator_latest_claim( Ok(()) } - -pub async fn get_validator_in_session( - action_tx: &UnboundedSender, - api: &OnlineClient, - account_id: &[u8; 32], -) -> Result<()> { - let in_list = super::raw_calls::session::validators(api, None) - .await? - .unwrap_or_default() - .iter() - .position(|validator| validator.0 == *account_id) - .is_some(); - action_tx.send(Action::SetValidatorInSession(in_list, *account_id))?; - Ok(()) -}