Compare commits

...

2 Commits

Author SHA1 Message Date
b9c863e2ea
align tables on validator tab with additional values
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-08-08 02:27:40 +03:00
ef81076f71
avoid capped 1 in a Perbill struct
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-08-08 00:39:04 +03:00
10 changed files with 40 additions and 41 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.64"
version = "0.3.66"
edition = "2021"
homepage = "https://git.ghostchain.io/ghostchain"
repository = "https://git.ghostchain.io/ghostchain/ghost-eye"

View File

@ -78,6 +78,8 @@ pub enum Action {
NominatorsNumber(u32),
Inflation(String),
Apy(String),
TreasuryApy(String),
NextReward(u128),
GetBlockAuthor(H256, Vec<DigestItem>),
SetBlockAuthor(H256, String),

View File

@ -20,7 +20,6 @@ use crate::{
struct Details {
incoming_fee: String,
outgoing_fee: String,
gatekeeper: String,
}
#[derive(Default)]
@ -58,9 +57,8 @@ impl Component for GatekeeperDetails {
},
Action::SetGatekeepedNetwork(network) => {
self.gatekeeper_details.insert(network.chain_id, Details {
incoming_fee: format!("{:.5}%", network.incoming_fee as f64 / 1_000_000_000.0),
outgoing_fee: format!("{:.5}%", network.outgoing_fee as f64 / 1_000_000_000.0),
gatekeeper: network.gatekeeper,
incoming_fee: format!("{:.5}%", network.incoming_fee as f64 / 10_000_000.0),
outgoing_fee: format!("{:.5}%", network.outgoing_fee as f64 / 10_000_000.0),
});
}
_ => {}
@ -100,10 +98,6 @@ impl Component for GatekeeperDetails {
Cell::from(Text::from("Outgoing fee".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(current_gatekeeper_details.outgoing_fee).alignment(Alignment::Right)),
]),
Row::new(vec![
Cell::from(Text::from("Gatekeeper".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(current_gatekeeper_details.gatekeeper).alignment(Alignment::Right)),
]),
],
[
Constraint::Length(12),

View File

@ -203,9 +203,8 @@ impl Component for Gatekeepers {
let list = List::new(
self.gatekeepers
.iter()
.map(|network| ListItem::new(format!("{} ({}) | {}",
.map(|network| ListItem::new(format!("{} (type {})",
network.chain_name,
network.chain_id,
network.chain_type))
)
)

View File

@ -287,7 +287,7 @@ impl Component for Validator {
pub fn validator_layout(area: Rect) -> [Rect; 4] {
Layout::vertical([
Constraint::Length(19),
Constraint::Length(18),
Constraint::Fill(1),
Constraint::Fill(1),
Constraint::Percentage(25),
@ -315,7 +315,7 @@ pub fn validator_gatekeeped_networks_layout(area: Rect) -> [Rect; 2] {
let [_, _, place] = validator_session_and_listen_layout(area);
Layout::horizontal([
Constraint::Fill(1),
Constraint::Length(57),
Constraint::Length(30),
]).areas(place)
}
@ -333,6 +333,6 @@ pub fn validator_balance_layout(area: Rect) -> [Rect; 3] {
Layout::vertical([
Constraint::Length(6),
Constraint::Length(6),
Constraint::Length(9),
Constraint::Fill(1),
]).areas(place)
}

View File

@ -21,6 +21,7 @@ pub struct RewardDetails {
commission: Option<u32>,
nominators_blocked: bool,
apy: String,
treasury_apy: String,
inflation: String,
stash: [u8; 32],
in_staking_validators: bool,
@ -43,6 +44,7 @@ impl RewardDetails {
commission: None,
nominators_blocked: false,
apy: String::from("0.0%"),
treasury_apy: String::from("0.0%"),
inflation: String::from("0.0%"),
stash: [0u8; 32],
in_staking_validators: false,
@ -110,6 +112,7 @@ impl Component for RewardDetails {
}
},
Action::Apy(apy) => self.apy = apy,
Action::TreasuryApy(apy) => self.treasury_apy = apy,
Action::Inflation(inflation) => self.inflation = inflation,
_ => {}
};
@ -141,16 +144,20 @@ impl Component for RewardDetails {
Cell::from(Text::from(self.comission_to_string()).alignment(Alignment::Right)),
]),
Row::new(vec![
Cell::from(Text::from("Current APY".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from("Validator APY".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.apy.clone()).alignment(Alignment::Right)),
]),
Row::new(vec![
Cell::from(Text::from("Treasury APY".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.treasury_apy.clone()).alignment(Alignment::Right)),
]),
Row::new(vec![
Cell::from(Text::from("Inflation".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.inflation.clone()).alignment(Alignment::Right)),
]),
],
[
Constraint::Min(11),
Constraint::Min(13),
Constraint::Min(0),
],
)

View File

@ -20,6 +20,7 @@ pub struct StakingDetails {
palette: StylePalette,
staked_own: u128,
staked_total: u128,
next_reward: u128,
stash: [u8; 32],
reward_destination: RewardDestination,
}
@ -39,6 +40,7 @@ impl StakingDetails {
palette: StylePalette::default(),
staked_own: 0,
staked_total: 0,
next_reward: 0,
stash: [0u8; 32],
reward_destination: Default::default(),
}
@ -89,6 +91,7 @@ impl Component for StakingDetails {
fn update(&mut self, action: Action) -> Result<Option<Action>> {
match action {
Action::SetStashAccount(account_id) => self.stash = account_id,
Action::NextReward(next_reward) => self.next_reward = next_reward,
Action::SetStakingPayee(destination, account_id) if self.stash == account_id =>
self.reward_destination = destination,
Action::SetStakedRatio(total, own, account_id) if self.stash == account_id => {
@ -119,6 +122,10 @@ impl Component for StakingDetails {
Cell::from(Text::from("Other stake".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128(self.staked_total.saturating_sub(self.staked_own))).alignment(Alignment::Right)),
]),
Row::new(vec![
Cell::from(Text::from("Next reward".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128(self.next_reward)).alignment(Alignment::Right)),
]),
],
[
Constraint::Min(11),

View File

@ -101,20 +101,6 @@ fn multiply_by_rational_saturating(value: u128, p: u32, q: u32) -> u128 {
result_divisor_part.saturating_add(result_remainder_part)
}
pub fn prepare_perbill_fraction_string(value: Perbill) -> String {
let d = value.deconstruct();
let mut m = 10_000_000;
let units = d / m;
let rest = d % m;
for _ in 0..2 {
m /= 10;
}
format!("{}.{:02}%", units, rest / m)
}
pub fn get_slow_clap_storage_key(first: &[u8], second: &[u8]) -> Vec<u8> {
let mut key = SLOW_CLAP_DB_PREFIX.to_vec();
key.extend(first);

View File

@ -11,7 +11,7 @@ mod subscriptions;
mod miscellaneous;
mod raw_calls;
pub use miscellaneous::{prepare_perbill_fraction_string, calculate_for_fraction};
pub use miscellaneous::calculate_for_fraction;
use crate::{
types::{ActionLevel, ActionTarget},

View File

@ -4,9 +4,9 @@ use subxt::{
backend::rpc::RpcClient,
client::OnlineClient,
config::substrate::DigestItem,
ext::{sp_core::crypto::{
ext::sp_core::crypto::{
AccountId32, Ss58AddressFormat, Ss58Codec,
}, sp_runtime::{traits::Saturating, Perbill}},
},
rpc_params,
utils::H256,
};
@ -196,18 +196,22 @@ pub async fn get_inflation(
.unwrap_or_default();
let (inflation, fraction) = super::calculate_for_fraction(total_staked, adjusted_issuance);
let current_ratio = Perbill::from_rational(accumulated_commission, adjusted_issuance);
let expected_inflation = inflation
.saturating_mul(Perbill::one().saturating_add(current_ratio))
.saturating_pow(365)
.saturating_sub(Perbill::one());
let expected_fraction = expected_inflation.saturating_mul(fraction);
let current_ratio: f64 = 1.0 + accumulated_commission as f64 / adjusted_issuance as f64;
let yearly_current_ratio = current_ratio.powf(365.0) - 1.0;
let inflation_str = super::prepare_perbill_fraction_string(expected_inflation);
let fraction_str = super::prepare_perbill_fraction_string(expected_fraction);
let expected_inflation = (inflation.deconstruct() as f64) * yearly_current_ratio / 10_000_000.0;
let expected_fraction = (fraction.deconstruct() as f64) * yearly_current_ratio / 10_000_000.0;
let expected_reminder = expected_inflation - expected_fraction;
let inflation_str = format!("{:.4}%", expected_inflation);
let fraction_str = format!("{:.4}%", expected_fraction);
let treasury_str = format!("{:.4}%", expected_reminder);
action_tx.send(Action::Inflation(inflation_str))?;
action_tx.send(Action::Apy(fraction_str))?;
action_tx.send(Action::TreasuryApy(treasury_str))?;
action_tx.send(Action::NextReward(accumulated_commission))?;
Ok(())
}