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"
authors = ["str3tch <stretch@ghostchain.io>"]
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"
[dependencies]

View File

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

View File

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