show spinner for non-validator stash

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch 2025-02-16 14:26:19 +03:00
parent 90c07aa339
commit fafc5bd2c2
Signed by: str3tch
GPG Key ID: 84F3190747EE79AA
3 changed files with 17 additions and 15 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.25" version = "0.3.26"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -8,6 +8,7 @@ use ratatui::{
}; };
use super::{PartialComponent, Component, CurrentTab}; use super::{PartialComponent, Component, CurrentTab};
use crate::widgets::DotSpinner;
use crate::{ use crate::{
action::Action, action::Action,
config::Config, config::Config,
@ -16,7 +17,7 @@ use crate::{
pub struct RewardDetails { pub struct RewardDetails {
palette: StylePalette, palette: StylePalette,
commission: u32, commission: Option<u32>,
nominators_blocked: bool, nominators_blocked: bool,
apy: String, apy: String,
inflation: String, inflation: String,
@ -33,7 +34,7 @@ impl RewardDetails {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
palette: StylePalette::default(), palette: StylePalette::default(),
commission: 0, commission: None,
nominators_blocked: false, nominators_blocked: false,
apy: String::from("0.0%"), apy: String::from("0.0%"),
inflation: String::from("0.0%"), inflation: String::from("0.0%"),
@ -42,11 +43,12 @@ impl RewardDetails {
} }
fn comission_to_string(&self) -> String { fn comission_to_string(&self) -> String {
if self.nominators_blocked { match self.commission {
"blocked".to_string() Some(commission) => {
} else { if self.nominators_blocked { "blocked".to_string() }
let result = self.commission as f64 / 1_000_000_000.0; else { format!("{:.2}%", commission as f64 / 1_000_000_000.0) }
format!("{:.2}%", result) },
None => DotSpinner::default().to_string(),
} }
} }
} }
@ -74,7 +76,7 @@ impl Component for RewardDetails {
match action { match action {
Action::SetStashAccount(stash) => self.stash = stash, Action::SetStashAccount(stash) => self.stash = stash,
Action::SetValidatorPrefs(commission, disabled, account_id) if self.stash == account_id => { Action::SetValidatorPrefs(commission, disabled, account_id) if self.stash == account_id => {
self.commission = commission; self.commission = Some(commission);
self.nominators_blocked = disabled; self.nominators_blocked = disabled;
} }
Action::Apy(apy) => self.apy = apy, Action::Apy(apy) => self.apy = apy,

View File

@ -514,12 +514,12 @@ pub async fn get_validator_prefs(
) -> Result<()> { ) -> Result<()> {
let maybe_validator_prefs = super::raw_calls::staking::validators(api, None, account_id) let maybe_validator_prefs = super::raw_calls::staking::validators(api, None, account_id)
.await?; .await?;
let (comission, blocked) = match maybe_validator_prefs { if let Some(prefs) = maybe_validator_prefs {
Some(prefs) => (prefs.commission.0, prefs.blocked), action_tx.send(Action::SetValidatorPrefs(
None => (0, false), prefs.commission.0,
}; prefs.blocked,
*account_id))?;
action_tx.send(Action::SetValidatorPrefs(comission, blocked, *account_id))?; }
Ok(()) Ok(())
} }