validator details from nominator page added
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
a2584f8212
commit
c7cdafe3b6
@ -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.23"
|
version = "0.3.24"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -84,8 +84,8 @@ pub enum Action {
|
|||||||
GetChainVersion,
|
GetChainVersion,
|
||||||
GetPendingExtrinsics,
|
GetPendingExtrinsics,
|
||||||
GetConnectedPeers,
|
GetConnectedPeers,
|
||||||
GetSessionKeys([u8; 32]),
|
GetSessionKeys([u8; 32], bool),
|
||||||
GetQueuedSessionKeys([u8; 32]),
|
GetQueuedSessionKeys([u8; 32], bool),
|
||||||
GetListenAddresses,
|
GetListenAddresses,
|
||||||
GetLocalIdentity,
|
GetLocalIdentity,
|
||||||
|
|
||||||
@ -97,13 +97,13 @@ pub enum Action {
|
|||||||
GetValidatorsNumber,
|
GetValidatorsNumber,
|
||||||
GetNominatorsNumber,
|
GetNominatorsNumber,
|
||||||
GetInflation,
|
GetInflation,
|
||||||
GetNominatorsByValidator([u8; 32]),
|
GetNominatorsByValidator([u8; 32], bool),
|
||||||
GetValidatorAllRewards([u8; 32]),
|
GetValidatorAllRewards([u8; 32], bool),
|
||||||
GetValidatorLedger([u8; 32]),
|
GetValidatorLedger([u8; 32], bool),
|
||||||
GetIsStashBonded([u8; 32]),
|
GetIsStashBonded([u8; 32], bool),
|
||||||
GetErasStakersOverview([u8; 32]),
|
GetErasStakersOverview([u8; 32], bool),
|
||||||
GetValidatorPrefs([u8; 32]),
|
GetValidatorPrefs([u8; 32], bool),
|
||||||
GetSlashingSpans([u8; 32]),
|
GetSlashingSpans([u8; 32], bool),
|
||||||
GetCurrentValidatorEraRewards,
|
GetCurrentValidatorEraRewards,
|
||||||
|
|
||||||
SetNodeName(Option<String>),
|
SetNodeName(Option<String>),
|
||||||
@ -113,6 +113,7 @@ pub enum Action {
|
|||||||
SetChainVersion(Option<String>),
|
SetChainVersion(Option<String>),
|
||||||
SetStashAccount([u8; 32]),
|
SetStashAccount([u8; 32]),
|
||||||
SetStashSecret([u8; 32]),
|
SetStashSecret([u8; 32]),
|
||||||
|
SetChoosenValidator([u8; 32], u32, u32),
|
||||||
SetSlashingSpansLength(usize),
|
SetSlashingSpansLength(usize),
|
||||||
SetUnlockingIsEmpty(bool),
|
SetUnlockingIsEmpty(bool),
|
||||||
|
|
||||||
@ -127,15 +128,15 @@ pub enum Action {
|
|||||||
SetSessionKey(String, SessionKeyInfo),
|
SetSessionKey(String, SessionKeyInfo),
|
||||||
SetListenAddresses(Vec<String>),
|
SetListenAddresses(Vec<String>),
|
||||||
SetLocalIdentity(String),
|
SetLocalIdentity(String),
|
||||||
SetNominatorsByValidator(Vec<Nominator>),
|
SetNominatorsByValidator(Vec<Nominator>, [u8; 32]),
|
||||||
SetValidatorEraReward(u32, u128),
|
SetValidatorEraReward(u32, u128),
|
||||||
SetValidatorEraClaimed(u32, bool),
|
SetValidatorEraClaimed(u32, bool),
|
||||||
SetValidatorEraSlash(u32, u128),
|
SetValidatorEraSlash(u32, u128),
|
||||||
SetValidatorEraUnlocking(u32, u128),
|
SetValidatorEraUnlocking(u32, u128),
|
||||||
SetIsBonded(bool),
|
SetIsBonded(bool),
|
||||||
SetStakedAmountRatio(u128, u128),
|
SetStakedAmountRatio(u128, u128),
|
||||||
SetStakedRatio(u128, u128),
|
SetStakedRatio(u128, u128, [u8; 32]),
|
||||||
SetValidatorPrefs(u32, bool),
|
SetValidatorPrefs(u32, bool, [u8; 32]),
|
||||||
SetCurrentValidatorEraRewards(u32, u32, Vec<EraRewardPoints>),
|
SetCurrentValidatorEraRewards(u32, u32, Vec<EraRewardPoints>),
|
||||||
|
|
||||||
GetTotalIssuance,
|
GetTotalIssuance,
|
||||||
|
154
src/components/nominator/current_validator_details.rs
Normal file
154
src/components/nominator/current_validator_details.rs
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
use color_eyre::Result;
|
||||||
|
use ratatui::{
|
||||||
|
layout::{Alignment, Constraint, Rect},
|
||||||
|
text::Text,
|
||||||
|
widgets::{Block, Cell, Row, Table},
|
||||||
|
Frame
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::{Component, PartialComponent, CurrentTab};
|
||||||
|
use crate::{action::Action, config::Config, palette::StylePalette};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct CurrentValidatorDetails {
|
||||||
|
network_tx: Option<Sender<Action>>,
|
||||||
|
is_active: bool,
|
||||||
|
palette: StylePalette,
|
||||||
|
choosen: [u8; 32],
|
||||||
|
total_balance: u128,
|
||||||
|
own_balance: u128,
|
||||||
|
others_len: usize,
|
||||||
|
commission: f64,
|
||||||
|
points_ratio: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for CurrentValidatorDetails {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CurrentValidatorDetails {
|
||||||
|
const TICKER: &str = " CSPR";
|
||||||
|
const DECIMALS: usize = 5;
|
||||||
|
|
||||||
|
pub fn new() -> Self {
|
||||||
|
CurrentValidatorDetails {
|
||||||
|
network_tx: None,
|
||||||
|
is_active: false,
|
||||||
|
choosen: [0u8; 32],
|
||||||
|
total_balance: 0,
|
||||||
|
own_balance: 0,
|
||||||
|
others_len: 0,
|
||||||
|
commission: 0.0,
|
||||||
|
points_ratio: 0.0,
|
||||||
|
palette: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prepare_u128(&self, value: u128) -> String {
|
||||||
|
let value = value as f64 / 10f64.powi(18);
|
||||||
|
let after = Self::DECIMALS;
|
||||||
|
format!("{:.after$}{}", value, Self::TICKER)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_choosen_validator(&mut self, account_id: [u8; 32], individual: u32, total: u32) {
|
||||||
|
self.choosen = account_id;
|
||||||
|
self.points_ratio = match total {
|
||||||
|
0 => 0.0,
|
||||||
|
_ => individual as f64 / total as f64,
|
||||||
|
};
|
||||||
|
if let Some(network_tx) = &self.network_tx {
|
||||||
|
let _ = network_tx.send(Action::GetErasStakersOverview(account_id, false));
|
||||||
|
let _ = network_tx.send(Action::GetNominatorsByValidator(account_id, false));
|
||||||
|
let _ = network_tx.send(Action::GetValidatorPrefs(account_id, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialComponent for CurrentValidatorDetails {
|
||||||
|
fn set_active(&mut self, _current_tab: CurrentTab) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Component for CurrentValidatorDetails {
|
||||||
|
fn register_network_handler(&mut self, tx: Sender<Action>) -> Result<()> {
|
||||||
|
self.network_tx = Some(tx);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
||||||
|
if let Some(style) = config.styles.get(&crate::app::Mode::Nominator) {
|
||||||
|
self.palette.with_normal_style(style.get("normal_style").copied());
|
||||||
|
self.palette.with_hover_style(style.get("hover_style").copied());
|
||||||
|
self.palette.with_normal_border_style(style.get("normal_border_style").copied());
|
||||||
|
self.palette.with_hover_border_style(style.get("hover_border_style").copied());
|
||||||
|
self.palette.with_normal_title_style(style.get("normal_title_style").copied());
|
||||||
|
self.palette.with_hover_title_style(style.get("hover_title_style").copied());
|
||||||
|
self.palette.with_highlight_style(style.get("highlight_style").copied());
|
||||||
|
self.palette.with_scrollbar_style(style.get("scrollbar_style").copied());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
|
match action {
|
||||||
|
Action::SetChoosenValidator(account_id, individual, total) => self.update_choosen_validator(account_id, individual, total),
|
||||||
|
Action::SetNominatorsByValidator(noms, account_id) if self.choosen == account_id => self.others_len = noms.len(),
|
||||||
|
Action::SetValidatorPrefs(commission, _, account_id) if self.choosen == account_id =>
|
||||||
|
self.commission = commission as f64 / 1_000_000_000.0,
|
||||||
|
Action::SetStakedRatio(total, own, account_id) if self.choosen == account_id => {
|
||||||
|
self.total_balance = total;
|
||||||
|
self.own_balance = own;
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
|
let [_, place] = super::validator_details_layout(area);
|
||||||
|
let (border_style, border_type) = self.palette.create_border_style(self.is_active);
|
||||||
|
|
||||||
|
let table = Table::new(
|
||||||
|
vec![
|
||||||
|
Row::new(vec![
|
||||||
|
Cell::from(Text::from("Total staked".to_string()).alignment(Alignment::Left)),
|
||||||
|
Cell::from(Text::from(self.prepare_u128(self.total_balance)).alignment(Alignment::Right)),
|
||||||
|
]),
|
||||||
|
Row::new(vec![
|
||||||
|
Cell::from(Text::from("Own stake".to_string()).alignment(Alignment::Left)),
|
||||||
|
Cell::from(Text::from(self.prepare_u128(self.own_balance)).alignment(Alignment::Right)),
|
||||||
|
]),
|
||||||
|
Row::new(vec![
|
||||||
|
Cell::from(Text::from("Nominators".to_string()).alignment(Alignment::Left)),
|
||||||
|
Cell::from(Text::from(self.others_len.to_string()).alignment(Alignment::Right)),
|
||||||
|
]),
|
||||||
|
Row::new(vec![
|
||||||
|
Cell::from(Text::from("Commission".to_string()).alignment(Alignment::Left)),
|
||||||
|
Cell::from(Text::from(format!("{:.4}%", self.commission)).alignment(Alignment::Right)),
|
||||||
|
]),
|
||||||
|
Row::new(vec![
|
||||||
|
Cell::from(Text::from("Points ratio".to_string()).alignment(Alignment::Left)),
|
||||||
|
Cell::from(Text::from(format!("{:.4}%", self.points_ratio)).alignment(Alignment::Right)),
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
Constraint::Max(12),
|
||||||
|
Constraint::Min(0),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.column_spacing(1)
|
||||||
|
.highlight_style(self.palette.create_highlight_style())
|
||||||
|
.block(Block::bordered()
|
||||||
|
.border_style(border_style)
|
||||||
|
.border_type(border_type)
|
||||||
|
.title_alignment(Alignment::Right)
|
||||||
|
.title_style(self.palette.create_title_style(false))
|
||||||
|
.title("Validator details"));
|
||||||
|
|
||||||
|
frame.render_widget(table, place);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
@ -64,6 +64,15 @@ impl CurrentValidators {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_choosen_details(&self, index: usize) {
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::SetChoosenValidator(
|
||||||
|
self.individual[index].account_id,
|
||||||
|
self.individual[index].points,
|
||||||
|
self.total_points));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn save_validator_name(&mut self, new_name: String) {
|
fn save_validator_name(&mut self, new_name: String) {
|
||||||
if let Some(index) = self.table_state.selected() {
|
if let Some(index) = self.table_state.selected() {
|
||||||
let account_id = self.individual[index].account_id;
|
let account_id = self.individual[index].account_id;
|
||||||
@ -88,25 +97,22 @@ impl CurrentValidators {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_known_validators(&mut self, file_path: &PathBuf) -> Result<()> {
|
fn read_known_validators(&mut self, file_path: &PathBuf) -> Result<()> {
|
||||||
match File::open(file_path) {
|
if let Ok(file) = File::open(file_path) {
|
||||||
Ok(file) => {
|
let reader = BufReader::new(file);
|
||||||
let reader = BufReader::new(file);
|
for line in reader.lines() {
|
||||||
for line in reader.lines() {
|
let line = line?.replace("\n", "");
|
||||||
let line = line?.replace("\n", "");
|
let line_split_at = line.find(":").unwrap_or(line.len());
|
||||||
let line_split_at = line.find(":").unwrap_or(line.len());
|
let (name, seed) = line.split_at(line_split_at);
|
||||||
let (name, seed) = line.split_at(line_split_at);
|
let seed_str = &seed[3..];
|
||||||
let seed_str = &seed[3..];
|
|
||||||
|
|
||||||
let account_id: [u8; 32] = hex::decode(seed_str)
|
let account_id: [u8; 32] = hex::decode(seed_str)
|
||||||
.expect("stored seed is valid hex string; qed")
|
.expect("stored seed is valid hex string; qed")
|
||||||
.as_slice()
|
.as_slice()
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("stored seed is valid length; qed");
|
.expect("stored seed is valid length; qed");
|
||||||
|
|
||||||
let _ = self.known_validators.insert(account_id, name.to_string());
|
let _ = self.known_validators.insert(account_id, name.to_string());
|
||||||
}
|
}
|
||||||
},
|
|
||||||
Err(_) => { }
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -115,6 +121,7 @@ impl CurrentValidators {
|
|||||||
if self.individual.len() > 0 {
|
if self.individual.len() > 0 {
|
||||||
self.table_state.select(Some(0));
|
self.table_state.select(Some(0));
|
||||||
self.scroll_state = self.scroll_state.position(0);
|
self.scroll_state = self.scroll_state.position(0);
|
||||||
|
self.update_choosen_details(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +138,7 @@ impl CurrentValidators {
|
|||||||
};
|
};
|
||||||
self.table_state.select(Some(i));
|
self.table_state.select(Some(i));
|
||||||
self.scroll_state = self.scroll_state.position(i);
|
self.scroll_state = self.scroll_state.position(i);
|
||||||
|
self.update_choosen_details(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn last_row(&mut self) {
|
fn last_row(&mut self) {
|
||||||
@ -138,6 +146,7 @@ impl CurrentValidators {
|
|||||||
let last = self.individual.len() - 1;
|
let last = self.individual.len() - 1;
|
||||||
self.table_state.select(Some(last));
|
self.table_state.select(Some(last));
|
||||||
self.scroll_state = self.scroll_state.position(last);
|
self.scroll_state = self.scroll_state.position(last);
|
||||||
|
self.update_choosen_details(last);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +163,7 @@ impl CurrentValidators {
|
|||||||
};
|
};
|
||||||
self.table_state.select(Some(i));
|
self.table_state.select(Some(i));
|
||||||
self.scroll_state = self.scroll_state.position(i);
|
self.scroll_state = self.scroll_state.position(i);
|
||||||
|
self.update_choosen_details(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_era_rewards(
|
fn update_era_rewards(
|
||||||
@ -176,11 +186,10 @@ impl CurrentValidators {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let index = self.table_state
|
|
||||||
.selected()
|
|
||||||
.unwrap_or_default();
|
|
||||||
self.scroll_state = self.scroll_state.content_length(self.individual.len());
|
self.scroll_state = self.scroll_state.content_length(self.individual.len());
|
||||||
self.scroll_state = self.scroll_state.position(index);
|
if let Some(index) = self.table_state.selected() {
|
||||||
|
self.update_choosen_details(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +209,7 @@ impl Component for CurrentValidators {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
||||||
if let Some(style) = config.styles.get(&crate::app::Mode::Validator) {
|
if let Some(style) = config.styles.get(&crate::app::Mode::Nominator) {
|
||||||
self.palette.with_normal_style(style.get("normal_style").copied());
|
self.palette.with_normal_style(style.get("normal_style").copied());
|
||||||
self.palette.with_hover_style(style.get("hover_style").copied());
|
self.palette.with_hover_style(style.get("hover_style").copied());
|
||||||
self.palette.with_normal_border_style(style.get("normal_border_style").copied());
|
self.palette.with_normal_border_style(style.get("normal_border_style").copied());
|
||||||
|
@ -130,7 +130,7 @@ impl PartialComponent for EventLogs {
|
|||||||
|
|
||||||
impl Component for EventLogs {
|
impl Component for EventLogs {
|
||||||
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
||||||
if let Some(style) = config.styles.get(&crate::app::Mode::Validator) {
|
if let Some(style) = config.styles.get(&crate::app::Mode::Nominator) {
|
||||||
self.palette.with_normal_style(style.get("normal_style").copied());
|
self.palette.with_normal_style(style.get("normal_style").copied());
|
||||||
self.palette.with_hover_style(style.get("hover_style").copied());
|
self.palette.with_hover_style(style.get("hover_style").copied());
|
||||||
self.palette.with_normal_border_style(style.get("normal_border_style").copied());
|
self.palette.with_normal_border_style(style.get("normal_border_style").copied());
|
||||||
|
@ -14,9 +14,11 @@ use crate::{action::Action, app::Mode, config::Config};
|
|||||||
mod event_log;
|
mod event_log;
|
||||||
mod current_validators;
|
mod current_validators;
|
||||||
mod rename_known_validator;
|
mod rename_known_validator;
|
||||||
|
mod current_validator_details;
|
||||||
|
|
||||||
use event_log::EventLogs;
|
use event_log::EventLogs;
|
||||||
use current_validators::CurrentValidators;
|
use current_validators::CurrentValidators;
|
||||||
|
use current_validator_details::CurrentValidatorDetails;
|
||||||
use rename_known_validator::RenameKnownValidator;
|
use rename_known_validator::RenameKnownValidator;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@ -44,6 +46,7 @@ impl Default for Nominator {
|
|||||||
current_tab: CurrentTab::Nothing,
|
current_tab: CurrentTab::Nothing,
|
||||||
components: vec![
|
components: vec![
|
||||||
Box::new(CurrentValidators::default()),
|
Box::new(CurrentValidators::default()),
|
||||||
|
Box::new(CurrentValidatorDetails::default()),
|
||||||
Box::new(EventLogs::default()),
|
Box::new(EventLogs::default()),
|
||||||
Box::new(RenameKnownValidator::default()),
|
Box::new(RenameKnownValidator::default()),
|
||||||
],
|
],
|
||||||
@ -176,7 +179,7 @@ pub fn nominator_layout(area: Rect) -> [Rect; 3] {
|
|||||||
pub fn validator_details_layout(area: Rect) -> [Rect; 2] {
|
pub fn validator_details_layout(area: Rect) -> [Rect; 2] {
|
||||||
let [place, _, _] = nominator_layout(area);
|
let [place, _, _] = nominator_layout(area);
|
||||||
Layout::horizontal([
|
Layout::horizontal([
|
||||||
Constraint::Percentage(70),
|
Constraint::Percentage(60),
|
||||||
Constraint::Percentage(30),
|
Constraint::Percentage(40),
|
||||||
]).areas(place)
|
]).areas(place)
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ impl Component for RenameKnownValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
||||||
if let Some(style) = config.styles.get(&crate::app::Mode::Wallet) {
|
if let Some(style) = config.styles.get(&crate::app::Mode::Nominator) {
|
||||||
self.palette.with_normal_style(style.get("normal_style").copied());
|
self.palette.with_normal_style(style.get("normal_style").copied());
|
||||||
self.palette.with_normal_border_style(style.get("normal_border_style").copied());
|
self.palette.with_normal_border_style(style.get("normal_border_style").copied());
|
||||||
self.palette.with_normal_title_style(style.get("normal_title_style").copied());
|
self.palette.with_normal_title_style(style.get("normal_title_style").copied());
|
||||||
|
@ -27,6 +27,7 @@ pub struct NominatorsByValidator {
|
|||||||
scroll_state: ScrollbarState,
|
scroll_state: ScrollbarState,
|
||||||
table_state: TableState,
|
table_state: TableState,
|
||||||
nominators: Vec<Nominator>,
|
nominators: Vec<Nominator>,
|
||||||
|
stash: [u8; 32],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for NominatorsByValidator {
|
impl Default for NominatorsByValidator {
|
||||||
@ -46,6 +47,7 @@ impl NominatorsByValidator {
|
|||||||
scroll_state: ScrollbarState::new(0),
|
scroll_state: ScrollbarState::new(0),
|
||||||
table_state: TableState::new(),
|
table_state: TableState::new(),
|
||||||
nominators: Vec::new(),
|
nominators: Vec::new(),
|
||||||
|
stash: [0u8; 32],
|
||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +149,9 @@ impl Component for NominatorsByValidator {
|
|||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
match action {
|
match action {
|
||||||
Action::SetNominatorsByValidator(nominators) => self.update_nominators(nominators),
|
Action::SetStashAccount(stash) => self.stash = stash,
|
||||||
|
Action::SetNominatorsByValidator(nominators, account_id) if self.stash == account_id =>
|
||||||
|
self.update_nominators(nominators),
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
@ -20,6 +20,7 @@ pub struct RewardDetails {
|
|||||||
nominators_blocked: bool,
|
nominators_blocked: bool,
|
||||||
apy: String,
|
apy: String,
|
||||||
inflation: String,
|
inflation: String,
|
||||||
|
stash: [u8; 32],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RewardDetails {
|
impl Default for RewardDetails {
|
||||||
@ -36,6 +37,7 @@ impl RewardDetails {
|
|||||||
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%"),
|
||||||
|
stash: [0u8; 32],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +72,8 @@ impl Component for RewardDetails {
|
|||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
match action {
|
match action {
|
||||||
Action::SetValidatorPrefs(commission, disabled) => {
|
Action::SetStashAccount(stash) => self.stash = stash,
|
||||||
|
Action::SetValidatorPrefs(commission, disabled, account_id) if self.stash == account_id => {
|
||||||
self.commission = commission;
|
self.commission = commission;
|
||||||
self.nominators_blocked = disabled;
|
self.nominators_blocked = disabled;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ pub struct StakingDetails {
|
|||||||
palette: StylePalette,
|
palette: StylePalette,
|
||||||
staked_own: u128,
|
staked_own: u128,
|
||||||
staked_total: u128,
|
staked_total: u128,
|
||||||
|
stash: [u8; 32],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for StakingDetails {
|
impl Default for StakingDetails {
|
||||||
@ -35,6 +36,7 @@ impl StakingDetails {
|
|||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
staked_own: 0,
|
staked_own: 0,
|
||||||
staked_total: 0,
|
staked_total: 0,
|
||||||
|
stash: [0u8; 32],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +68,8 @@ impl Component for StakingDetails {
|
|||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
match action {
|
match action {
|
||||||
Action::SetStakedRatio(total, own) => {
|
Action::SetStashAccount(account_id) => self.stash = account_id,
|
||||||
|
Action::SetStakedRatio(total, own, account_id) if self.stash == account_id => {
|
||||||
self.staked_total = total;
|
self.staked_total = total;
|
||||||
self.staked_own = own;
|
self.staked_own = own;
|
||||||
}
|
}
|
||||||
|
@ -203,15 +203,15 @@ impl StashInfo {
|
|||||||
|
|
||||||
if let Some(network_tx) = &self.network_tx {
|
if let Some(network_tx) = &self.network_tx {
|
||||||
let _ = network_tx.send(Action::BalanceRequest(account_id, false));
|
let _ = network_tx.send(Action::BalanceRequest(account_id, false));
|
||||||
let _ = network_tx.send(Action::GetValidatorLedger(account_id));
|
let _ = network_tx.send(Action::GetValidatorLedger(account_id, true));
|
||||||
let _ = network_tx.send(Action::GetIsStashBonded(account_id));
|
let _ = network_tx.send(Action::GetIsStashBonded(account_id, true));
|
||||||
let _ = network_tx.send(Action::GetErasStakersOverview(account_id));
|
let _ = network_tx.send(Action::GetErasStakersOverview(account_id, true));
|
||||||
let _ = network_tx.send(Action::GetValidatorPrefs(account_id));
|
let _ = network_tx.send(Action::GetValidatorPrefs(account_id, true));
|
||||||
let _ = network_tx.send(Action::GetNominatorsByValidator(account_id));
|
let _ = network_tx.send(Action::GetNominatorsByValidator(account_id, true));
|
||||||
let _ = network_tx.send(Action::GetQueuedSessionKeys(account_id));
|
let _ = network_tx.send(Action::GetQueuedSessionKeys(account_id, true));
|
||||||
let _ = network_tx.send(Action::GetSessionKeys(account_id));
|
let _ = network_tx.send(Action::GetSessionKeys(account_id, true));
|
||||||
let _ = network_tx.send(Action::GetValidatorAllRewards(account_id));
|
let _ = network_tx.send(Action::GetValidatorAllRewards(account_id, true));
|
||||||
let _ = network_tx.send(Action::GetSlashingSpans(account_id));
|
let _ = network_tx.send(Action::GetSlashingSpans(account_id, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ pub struct Network {
|
|||||||
best_hash: Option<H256>,
|
best_hash: Option<H256>,
|
||||||
finalized_hash: Option<H256>,
|
finalized_hash: Option<H256>,
|
||||||
stash_to_watch: Option<[u8; 32]>,
|
stash_to_watch: Option<[u8; 32]>,
|
||||||
|
validator_details_to_watch: Option<[u8; 32]>,
|
||||||
accounts_to_watch: std::collections::HashSet<[u8; 32]>,
|
accounts_to_watch: std::collections::HashSet<[u8; 32]>,
|
||||||
transactions_to_watch: Vec<TxToWatch>,
|
transactions_to_watch: Vec<TxToWatch>,
|
||||||
eras_to_watch: std::collections::HashSet<u32>,
|
eras_to_watch: std::collections::HashSet<u32>,
|
||||||
@ -56,6 +57,7 @@ impl Network {
|
|||||||
best_hash: None,
|
best_hash: None,
|
||||||
finalized_hash: None,
|
finalized_hash: None,
|
||||||
stash_to_watch: None,
|
stash_to_watch: None,
|
||||||
|
validator_details_to_watch: None,
|
||||||
accounts_to_watch: Default::default(),
|
accounts_to_watch: Default::default(),
|
||||||
transactions_to_watch: Default::default(),
|
transactions_to_watch: Default::default(),
|
||||||
eras_to_watch: Default::default(),
|
eras_to_watch: Default::default(),
|
||||||
@ -63,10 +65,17 @@ impl Network {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store_stash_if_possible(&mut self, new_stash: [u8; 32]) {
|
fn store_stash_or_validator_if_possible(&mut self, account_id: [u8; 32], is_stash: bool) {
|
||||||
match self.stash_to_watch {
|
if is_stash {
|
||||||
Some(stash) if stash == new_stash => {},
|
match self.stash_to_watch {
|
||||||
_ => self.stash_to_watch = Some(new_stash),
|
Some(stash) if stash == account_id => {},
|
||||||
|
_ => self.stash_to_watch = Some(account_id),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match self.validator_details_to_watch {
|
||||||
|
Some(stash) if stash == account_id => {},
|
||||||
|
_ => self.validator_details_to_watch = Some(account_id),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +123,11 @@ impl Network {
|
|||||||
predefined_calls::get_validator_staking_result(&self.action_tx, &self.online_client_api, &stash_to_watch, *era_index).await?;
|
predefined_calls::get_validator_staking_result(&self.action_tx, &self.online_client_api, &stash_to_watch, *era_index).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(validator_details_to_watch) = self.validator_details_to_watch {
|
||||||
|
predefined_calls::get_nominators_by_validator(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
|
||||||
|
predefined_calls::get_validator_prefs(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
|
||||||
|
predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
|
||||||
|
}
|
||||||
for account_id in self.accounts_to_watch.iter() {
|
for account_id in self.accounts_to_watch.iter() {
|
||||||
predefined_calls::get_balance(&self.action_tx, &self.online_client_api, &account_id).await?;
|
predefined_calls::get_balance(&self.action_tx, &self.online_client_api, &account_id).await?;
|
||||||
}
|
}
|
||||||
@ -191,41 +205,41 @@ impl Network {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
Action::GetSlashingSpans(stash) => {
|
Action::GetSlashingSpans(account_id, is_stash) => {
|
||||||
self.store_stash_if_possible(stash);
|
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||||
predefined_calls::get_slashing_spans(&self.action_tx, &self.online_client_api, &stash).await
|
predefined_calls::get_slashing_spans(&self.action_tx, &self.online_client_api, &account_id).await
|
||||||
}
|
}
|
||||||
Action::GetValidatorLedger(stash) => {
|
Action::GetValidatorLedger(account_id, is_stash) => {
|
||||||
self.store_stash_if_possible(stash);
|
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||||
predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &stash).await
|
predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &account_id).await
|
||||||
}
|
}
|
||||||
Action::GetIsStashBonded(stash) => {
|
Action::GetIsStashBonded(account_id, is_stash) => {
|
||||||
self.store_stash_if_possible(stash);
|
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||||
predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &stash).await
|
predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &account_id).await
|
||||||
},
|
},
|
||||||
Action::GetErasStakersOverview(stash) => {
|
Action::GetErasStakersOverview(account_id, is_stash) => {
|
||||||
self.store_stash_if_possible(stash);
|
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||||
predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &stash).await
|
predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &account_id).await
|
||||||
},
|
},
|
||||||
Action::GetValidatorPrefs(stash) => {
|
Action::GetValidatorPrefs(account_id, is_stash) => {
|
||||||
self.store_stash_if_possible(stash);
|
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||||
predefined_calls::get_validator_prefs(&self.action_tx, &self.online_client_api, &stash).await
|
predefined_calls::get_validator_prefs(&self.action_tx, &self.online_client_api, &account_id).await
|
||||||
},
|
},
|
||||||
Action::GetValidatorAllRewards(stash) => {
|
Action::GetNominatorsByValidator(account_id, is_stash) => {
|
||||||
self.store_stash_if_possible(stash);
|
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||||
predefined_calls::get_validator_staking_results(&self.action_tx, &self.online_client_api, &stash).await
|
predefined_calls::get_nominators_by_validator(&self.action_tx, &self.online_client_api, &account_id).await
|
||||||
},
|
},
|
||||||
Action::GetNominatorsByValidator(stash) => {
|
Action::GetValidatorAllRewards(account_id, is_stash) => {
|
||||||
self.store_stash_if_possible(stash);
|
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||||
predefined_calls::get_nominators_by_validator(&self.action_tx, &self.online_client_api, &stash).await
|
predefined_calls::get_validator_staking_results(&self.action_tx, &self.online_client_api, &account_id).await
|
||||||
},
|
},
|
||||||
Action::GetQueuedSessionKeys(stash) => {
|
Action::GetQueuedSessionKeys(account_id, is_stash) => {
|
||||||
self.store_stash_if_possible(stash);
|
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||||
predefined_calls::get_queued_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &stash).await
|
predefined_calls::get_queued_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &account_id).await
|
||||||
},
|
},
|
||||||
Action::GetSessionKeys(stash) => {
|
Action::GetSessionKeys(account_id, is_stash) => {
|
||||||
self.store_stash_if_possible(stash);
|
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||||
predefined_calls::get_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &stash).await
|
predefined_calls::get_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &account_id).await
|
||||||
},
|
},
|
||||||
Action::BalanceRequest(account_id, remove) => {
|
Action::BalanceRequest(account_id, remove) => {
|
||||||
if remove {
|
if remove {
|
||||||
|
@ -472,7 +472,7 @@ pub async fn get_nominators_by_validator(
|
|||||||
None => Vec::new(),
|
None => Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
action_tx.send(Action::SetNominatorsByValidator(nominators))?;
|
action_tx.send(Action::SetNominatorsByValidator(nominators, *account_id))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,7 +503,7 @@ pub async fn get_staking_value_ratio(
|
|||||||
Some(overview) => (overview.total, overview.own),
|
Some(overview) => (overview.total, overview.own),
|
||||||
None => (0, 0),
|
None => (0, 0),
|
||||||
};
|
};
|
||||||
action_tx.send(Action::SetStakedRatio(total, own))?;
|
action_tx.send(Action::SetStakedRatio(total, own, *account_id))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,7 +519,7 @@ pub async fn get_validator_prefs(
|
|||||||
None => (0, false),
|
None => (0, false),
|
||||||
};
|
};
|
||||||
|
|
||||||
action_tx.send(Action::SetValidatorPrefs(comission, blocked))?;
|
action_tx.send(Action::SetValidatorPrefs(comission, blocked, *account_id))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user