Compare commits
No commits in common. "de1732372e167059d55d96ef25f8148aa008a7b8" and "f8b421554611687697ec69f863037a4f2fc77165" have entirely different histories.
de1732372e
...
f8b4215546
@ -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.44"
|
version = "0.3.42"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
homepage = "https://git.ghostchain.io/ghostchain"
|
homepage = "https://git.ghostchain.io/ghostchain"
|
||||||
repository = "https://git.ghostchain.io/ghostchain/ghost-eye"
|
repository = "https://git.ghostchain.io/ghostchain/ghost-eye"
|
||||||
|
@ -26,7 +26,7 @@ pub enum Action {
|
|||||||
SetActiveScreen(crate::app::Mode),
|
SetActiveScreen(crate::app::Mode),
|
||||||
UsedExplorerBlock(Option<u32>),
|
UsedExplorerBlock(Option<u32>),
|
||||||
UsedExplorerLog(Option<String>),
|
UsedExplorerLog(Option<String>),
|
||||||
UsedAccount([u8; 32], String),
|
UsedAccount(String),
|
||||||
NewAccount(String),
|
NewAccount(String),
|
||||||
NewAddressBookRecord(String, String),
|
NewAddressBookRecord(String, String),
|
||||||
SetSender(String, Option<u32>),
|
SetSender(String, Option<u32>),
|
||||||
@ -138,8 +138,8 @@ pub enum Action {
|
|||||||
SetValidatorEraUnlocking(u32, u128, [u8; 32]),
|
SetValidatorEraUnlocking(u32, u128, [u8; 32]),
|
||||||
SetValidatorLatestClaim(u32, [u8; 32]),
|
SetValidatorLatestClaim(u32, [u8; 32]),
|
||||||
SetValidatorInSession(bool, [u8; 32]),
|
SetValidatorInSession(bool, [u8; 32]),
|
||||||
SetIsBonded(bool, [u8; 32]),
|
SetIsBonded(bool),
|
||||||
SetStakedAmountRatio(Option<u128>, Option<u128>, [u8; 32]),
|
SetStakedAmountRatio(u128, u128, [u8; 32]),
|
||||||
SetStakedRatio(u128, u128, [u8; 32]),
|
SetStakedRatio(u128, u128, [u8; 32]),
|
||||||
SetValidatorPrefs(Option<u32>, bool, [u8; 32]),
|
SetValidatorPrefs(Option<u32>, bool, [u8; 32]),
|
||||||
SetCurrentValidatorEraRewards(u32, u32, Vec<EraRewardPoints>),
|
SetCurrentValidatorEraRewards(u32, u32, Vec<EraRewardPoints>),
|
||||||
|
@ -141,7 +141,7 @@ impl Component for CurrentValidatorDetails {
|
|||||||
Action::SetChoosenValidator(account_id, individual, total) => self.update_choosen_validator(account_id, individual, total),
|
Action::SetChoosenValidator(account_id, individual, total) => self.update_choosen_validator(account_id, individual, total),
|
||||||
Action::SetValidatorPrefs(commission, is_disabled, account_id) if self.choosen == account_id => self.update_commission(commission, is_disabled),
|
Action::SetValidatorPrefs(commission, is_disabled, account_id) if self.choosen == account_id => self.update_commission(commission, is_disabled),
|
||||||
Action::SetNominatorsByValidator(noms, account_id) if self.choosen == account_id => self.others_len = noms.len(),
|
Action::SetNominatorsByValidator(noms, account_id) if self.choosen == account_id => self.others_len = noms.len(),
|
||||||
Action::SetStakedAmountRatio(_, active_stake, account_id) if self.choosen == account_id => self.active_stake = active_stake.unwrap_or_default(),
|
Action::SetStakedAmountRatio(_, active_stake, account_id) if self.choosen == account_id => self.active_stake = active_stake,
|
||||||
Action::SetValidatorLatestClaim(era_index, account_id) if self.choosen == account_id => self.latest_era_claim = era_index,
|
Action::SetValidatorLatestClaim(era_index, account_id) if self.choosen == account_id => self.latest_era_claim = era_index,
|
||||||
Action::SetStakedRatio(total, own, account_id) if self.choosen == account_id => {
|
Action::SetStakedRatio(total, own, account_id) if self.choosen == account_id => {
|
||||||
self.total_balance = total;
|
self.total_balance = total;
|
||||||
|
@ -22,8 +22,7 @@ pub struct BondPopup {
|
|||||||
is_active: bool,
|
is_active: bool,
|
||||||
action_tx: Option<UnboundedSender<Action>>,
|
action_tx: Option<UnboundedSender<Action>>,
|
||||||
network_tx: Option<Sender<Action>>,
|
network_tx: Option<Sender<Action>>,
|
||||||
stash_secret_seed: [u8; 32],
|
secret_seed: [u8; 32],
|
||||||
stash_account_id: [u8; 32],
|
|
||||||
minimal_bond: u128,
|
minimal_bond: u128,
|
||||||
is_bonded: bool,
|
is_bonded: bool,
|
||||||
amount: Input,
|
amount: Input,
|
||||||
@ -40,8 +39,7 @@ impl BondPopup {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
is_active: false,
|
is_active: false,
|
||||||
stash_secret_seed: [0u8; 32],
|
secret_seed: [0u8; 32],
|
||||||
stash_account_id: [0u8; 32],
|
|
||||||
action_tx: None,
|
action_tx: None,
|
||||||
network_tx: None,
|
network_tx: None,
|
||||||
minimal_bond: 0u128,
|
minimal_bond: 0u128,
|
||||||
@ -72,9 +70,9 @@ impl BondPopup {
|
|||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
let amount = (value * 1_000_000_000_000_000_000.0) as u128;
|
let amount = (value * 1_000_000_000_000_000_000.0) as u128;
|
||||||
let _ = if self.is_bonded {
|
let _ = if self.is_bonded {
|
||||||
network_tx.send(Action::BondValidatorExtraFrom(self.stash_secret_seed, amount))
|
network_tx.send(Action::BondValidatorExtraFrom(self.secret_seed, amount))
|
||||||
} else {
|
} else {
|
||||||
network_tx.send(Action::BondValidatorFrom(self.stash_secret_seed, amount))
|
network_tx.send(Action::BondValidatorFrom(self.secret_seed, amount))
|
||||||
};
|
};
|
||||||
if let Some(action_tx) = &self.action_tx {
|
if let Some(action_tx) = &self.action_tx {
|
||||||
let _ = action_tx.send(Action::ClosePopup);
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
@ -156,11 +154,9 @@ impl Component for BondPopup {
|
|||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
match action {
|
match action {
|
||||||
Action::SetIsBonded(is_bonded, account_id) if self.stash_account_id == account_id =>
|
Action::SetIsBonded(is_bonded) => self.is_bonded = is_bonded,
|
||||||
self.is_bonded = is_bonded,
|
|
||||||
Action::SetMinValidatorBond(minimal_bond) => self.minimal_bond = minimal_bond,
|
Action::SetMinValidatorBond(minimal_bond) => self.minimal_bond = minimal_bond,
|
||||||
Action::SetStashSecret(secret_seed) => self.stash_secret_seed = secret_seed,
|
Action::SetStashSecret(secret_seed) => self.secret_seed = secret_seed,
|
||||||
Action::SetStashAccount(account_id) => self.stash_account_id = account_id,
|
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
@ -6,7 +6,6 @@ use ratatui::{
|
|||||||
Frame
|
Frame
|
||||||
};
|
};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
|
||||||
|
|
||||||
use super::{Component, PartialComponent, CurrentTab};
|
use super::{Component, PartialComponent, CurrentTab};
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -18,7 +17,6 @@ use crate::{
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ChillPopup {
|
pub struct ChillPopup {
|
||||||
is_active: bool,
|
is_active: bool,
|
||||||
action_tx: Option<UnboundedSender<Action>>,
|
|
||||||
network_tx: Option<Sender<Action>>,
|
network_tx: Option<Sender<Action>>,
|
||||||
secret_seed: [u8; 32],
|
secret_seed: [u8; 32],
|
||||||
palette: StylePalette
|
palette: StylePalette
|
||||||
@ -36,7 +34,6 @@ impl ChillPopup {
|
|||||||
is_active: false,
|
is_active: false,
|
||||||
secret_seed: [0u8; 32],
|
secret_seed: [0u8; 32],
|
||||||
network_tx: None,
|
network_tx: None,
|
||||||
action_tx: None,
|
|
||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,9 +41,6 @@ impl ChillPopup {
|
|||||||
fn submit_message(&mut self) {
|
fn submit_message(&mut self) {
|
||||||
if let Some(network_tx) = &self.network_tx {
|
if let Some(network_tx) = &self.network_tx {
|
||||||
let _ = network_tx.send(Action::ChillFrom(self.secret_seed));
|
let _ = network_tx.send(Action::ChillFrom(self.secret_seed));
|
||||||
if let Some(action_tx) = &self.action_tx {
|
|
||||||
let _ = action_tx.send(Action::ClosePopup);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,11 +60,6 @@ impl Component for ChillPopup {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
|
||||||
self.action_tx = Some(tx);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
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::Wallet) {
|
||||||
self.palette.with_normal_style(style.get("normal_style").copied());
|
self.palette.with_normal_style(style.get("normal_style").copied());
|
||||||
|
@ -98,11 +98,10 @@ impl Component for StashDetails {
|
|||||||
match action {
|
match action {
|
||||||
Action::SetStashSecret(secret) => self.stash_secret = secret,
|
Action::SetStashSecret(secret) => self.stash_secret = secret,
|
||||||
Action::SetStashAccount(account_id) => self.stash_account_id = account_id,
|
Action::SetStashAccount(account_id) => self.stash_account_id = account_id,
|
||||||
Action::SetIsBonded(is_bonded, account_id) if self.stash_account_id == account_id =>
|
Action::SetIsBonded(is_bonded) => self.is_bonded = is_bonded,
|
||||||
self.is_bonded = is_bonded,
|
|
||||||
Action::SetStakedAmountRatio(total, active, account_id) if self.stash_account_id == account_id => {
|
Action::SetStakedAmountRatio(total, active, account_id) if self.stash_account_id == account_id => {
|
||||||
self.staked_total = total;
|
self.staked_total = Some(total);
|
||||||
self.staked_active = active;
|
self.staked_active = Some(active);
|
||||||
},
|
},
|
||||||
Action::BalanceResponse(account_id, maybe_balance) if account_id == self.stash_account_id => {
|
Action::BalanceResponse(account_id, maybe_balance) if account_id == self.stash_account_id => {
|
||||||
if let Some(network_tx) = &self.network_tx {
|
if let Some(network_tx) = &self.network_tx {
|
||||||
|
@ -22,8 +22,7 @@ pub struct UnbondPopup {
|
|||||||
is_active: bool,
|
is_active: bool,
|
||||||
action_tx: Option<UnboundedSender<Action>>,
|
action_tx: Option<UnboundedSender<Action>>,
|
||||||
network_tx: Option<Sender<Action>>,
|
network_tx: Option<Sender<Action>>,
|
||||||
stash_secret_seed: [u8; 32],
|
secret_seed: [u8; 32],
|
||||||
stash_account_id: [u8; 32],
|
|
||||||
is_bonded: bool,
|
is_bonded: bool,
|
||||||
amount: Input,
|
amount: Input,
|
||||||
palette: StylePalette
|
palette: StylePalette
|
||||||
@ -39,8 +38,7 @@ impl UnbondPopup {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
is_active: false,
|
is_active: false,
|
||||||
stash_secret_seed: [0u8; 32],
|
secret_seed: [0u8; 32],
|
||||||
stash_account_id: [0u8; 32],
|
|
||||||
action_tx: None,
|
action_tx: None,
|
||||||
network_tx: None,
|
network_tx: None,
|
||||||
is_bonded: false,
|
is_bonded: false,
|
||||||
@ -69,7 +67,7 @@ impl UnbondPopup {
|
|||||||
if self.is_bonded {
|
if self.is_bonded {
|
||||||
let amount = (value * 1_000_000_000_000_000_000.0) as u128;
|
let amount = (value * 1_000_000_000_000_000_000.0) as u128;
|
||||||
let _ = network_tx.send(Action::UnbondFrom(
|
let _ = network_tx.send(Action::UnbondFrom(
|
||||||
self.stash_secret_seed, amount));
|
self.secret_seed, amount));
|
||||||
} else {
|
} else {
|
||||||
self.log_event(
|
self.log_event(
|
||||||
format!("current stash doesn't have bond yet"),
|
format!("current stash doesn't have bond yet"),
|
||||||
@ -155,10 +153,8 @@ impl Component for UnbondPopup {
|
|||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
match action {
|
match action {
|
||||||
Action::SetIsBonded(is_bonded, account_id) if self.stash_account_id == account_id =>
|
Action::SetIsBonded(is_bonded) => self.is_bonded = is_bonded,
|
||||||
self.is_bonded = is_bonded,
|
Action::SetStashSecret(secret_seed) => self.secret_seed = secret_seed,
|
||||||
Action::SetStashSecret(secret_seed) => self.stash_secret_seed = secret_seed,
|
|
||||||
Action::SetStashAccount(account_id) => self.stash_account_id = account_id,
|
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
@ -126,7 +126,7 @@ impl Component for WithdrawPopup {
|
|||||||
Action::SetSlashingSpansLength(length, account_id) if self.stash_account == account_id =>
|
Action::SetSlashingSpansLength(length, account_id) if self.stash_account == account_id =>
|
||||||
self.slashing_spans_length = length as u32,
|
self.slashing_spans_length = length as u32,
|
||||||
Action::SetStakedAmountRatio(_, active_balance, account_id) if self.stash_account == account_id =>
|
Action::SetStakedAmountRatio(_, active_balance, account_id) if self.stash_account == account_id =>
|
||||||
self.active_balance = active_balance.unwrap_or_default(),
|
self.active_balance = active_balance,
|
||||||
Action::SetUnlockingIsEmpty(is_empty, account_id) if self.stash_account == account_id =>
|
Action::SetUnlockingIsEmpty(is_empty, account_id) if self.stash_account == account_id =>
|
||||||
self.unlocking_is_empty = is_empty,
|
self.unlocking_is_empty = is_empty,
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -88,9 +88,8 @@ impl Accounts {
|
|||||||
|
|
||||||
fn set_used_account(&mut self, index: usize) {
|
fn set_used_account(&mut self, index: usize) {
|
||||||
let used_seed = self.wallet_keys[index].seed.clone();
|
let used_seed = self.wallet_keys[index].seed.clone();
|
||||||
let account_id = self.wallet_keys[index].account_id;
|
|
||||||
if let Some(action_tx) = &self.action_tx {
|
if let Some(action_tx) = &self.action_tx {
|
||||||
let _ = action_tx.send(Action::UsedAccount(account_id, used_seed.clone()));
|
let _ = action_tx.send(Action::UsedAccount(used_seed.clone()));
|
||||||
}
|
}
|
||||||
self.set_sender_nonce(index);
|
self.set_sender_nonce(index);
|
||||||
}
|
}
|
||||||
@ -527,7 +526,7 @@ impl Component for Accounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
let [_, place, _, _] = super::account_layout(area);
|
let [_, place, _] = super::account_layout(area);
|
||||||
let (border_style, border_type) = self.palette.create_border_style(self.is_active);
|
let (border_style, border_type) = self.palette.create_border_style(self.is_active);
|
||||||
|
|
||||||
let table = Table::new(
|
let table = Table::new(
|
||||||
|
@ -111,7 +111,7 @@ impl Component for Balance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
let [_, _, place, _] = super::account_layout(area);
|
let [_, _, place] = super::account_layout(area);
|
||||||
let (border_style, border_type) = self.palette
|
let (border_style, border_type) = self.palette
|
||||||
.create_border_style(self.is_active);
|
.create_border_style(self.is_active);
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ mod overview;
|
|||||||
mod add_address_book_record;
|
mod add_address_book_record;
|
||||||
mod rename_address_book_record;
|
mod rename_address_book_record;
|
||||||
mod details;
|
mod details;
|
||||||
mod staking_ledger;
|
|
||||||
|
|
||||||
use balance::Balance;
|
use balance::Balance;
|
||||||
use transfer::Transfer;
|
use transfer::Transfer;
|
||||||
@ -32,7 +31,6 @@ use overview::Overview;
|
|||||||
use add_address_book_record::AddAddressBookRecord;
|
use add_address_book_record::AddAddressBookRecord;
|
||||||
use rename_address_book_record::RenameAddressBookRecord;
|
use rename_address_book_record::RenameAddressBookRecord;
|
||||||
use details::AccountDetails;
|
use details::AccountDetails;
|
||||||
use staking_ledger::StakingLedger;
|
|
||||||
|
|
||||||
use super::Component;
|
use super::Component;
|
||||||
use crate::{action::Action, app::Mode, config::Config};
|
use crate::{action::Action, app::Mode, config::Config};
|
||||||
@ -72,7 +70,6 @@ impl Default for Wallet {
|
|||||||
Box::new(Overview::default()),
|
Box::new(Overview::default()),
|
||||||
Box::new(Accounts::default()),
|
Box::new(Accounts::default()),
|
||||||
Box::new(Balance::default()),
|
Box::new(Balance::default()),
|
||||||
Box::new(StakingLedger::default()),
|
|
||||||
Box::new(AddressBook::default()),
|
Box::new(AddressBook::default()),
|
||||||
Box::new(EventLogs::default()),
|
Box::new(EventLogs::default()),
|
||||||
Box::new(AddAccount::default()),
|
Box::new(AddAccount::default()),
|
||||||
@ -266,12 +263,11 @@ pub fn bars_layout(area: Rect) -> [Rect; 2] {
|
|||||||
]).areas(place)
|
]).areas(place)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn account_layout(area: Rect) -> [Rect; 4] {
|
pub fn account_layout(area: Rect) -> [Rect; 3] {
|
||||||
let [place, _] = bars_layout(area);
|
let [place, _] = bars_layout(area);
|
||||||
Layout::vertical([
|
Layout::vertical([
|
||||||
Constraint::Max(4),
|
Constraint::Max(4),
|
||||||
Constraint::Min(0),
|
Constraint::Min(0),
|
||||||
Constraint::Max(7),
|
Constraint::Max(7),
|
||||||
Constraint::Max(5),
|
|
||||||
]).areas(place)
|
]).areas(place)
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ impl Component for Overview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
let [place, _, _, _] = super::account_layout(area);
|
let [place, _, _] = super::account_layout(area);
|
||||||
let (border_style, border_type) = self.palette
|
let (border_style, border_type) = self.palette
|
||||||
.create_border_style(self.is_active);
|
.create_border_style(self.is_active);
|
||||||
|
|
||||||
|
@ -1,154 +0,0 @@
|
|||||||
use color_eyre::Result;
|
|
||||||
use ratatui::{
|
|
||||||
text::Text,
|
|
||||||
layout::{Alignment, Constraint, Rect},
|
|
||||||
widgets::{Block, Cell, Row, Table},
|
|
||||||
Frame
|
|
||||||
};
|
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
|
|
||||||
use super::{Component, PartialComponent, CurrentTab};
|
|
||||||
use crate::{
|
|
||||||
widgets::DotSpinner,
|
|
||||||
action::Action,
|
|
||||||
config::Config,
|
|
||||||
palette::StylePalette,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct StakingLedger {
|
|
||||||
is_active: bool,
|
|
||||||
is_bonded: bool,
|
|
||||||
account_id: [u8; 32],
|
|
||||||
network_tx: Option<Sender<Action>>,
|
|
||||||
total_staked: Option<u128>,
|
|
||||||
active_staked: Option<u128>,
|
|
||||||
palette: StylePalette
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for StakingLedger {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StakingLedger {
|
|
||||||
const TICKER: &str = " CSPR";
|
|
||||||
const DECIMALS: usize = 6;
|
|
||||||
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
is_active: false,
|
|
||||||
is_bonded: false,
|
|
||||||
account_id: [0u8; 32],
|
|
||||||
network_tx: None,
|
|
||||||
total_staked: None,
|
|
||||||
active_staked: None,
|
|
||||||
palette: StylePalette::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_used_account_id(&mut self, account_id: [u8; 32]) {
|
|
||||||
self.account_id = account_id;
|
|
||||||
if let Some(network_tx) = &self.network_tx {
|
|
||||||
let _ = network_tx.send(Action::GetValidatorLedger(account_id, false));
|
|
||||||
let _ = network_tx.send(Action::GetIsStashBonded(account_id, false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn prepare_u128(&self, maybe_value: Option<u128>) -> String {
|
|
||||||
match maybe_value {
|
|
||||||
Some(value) => {
|
|
||||||
let value = value as f64 / 10f64.powi(18);
|
|
||||||
let after = Self::DECIMALS;
|
|
||||||
format!("{:.after$}{}", value, Self::TICKER)
|
|
||||||
},
|
|
||||||
None => format!("{}{}", DotSpinner::default().to_string(), Self::TICKER)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_bonded_to_string(&self) -> String {
|
|
||||||
if self.is_bonded {
|
|
||||||
"bonded".to_string()
|
|
||||||
} else {
|
|
||||||
"no bond".to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialComponent for StakingLedger {
|
|
||||||
fn set_active(&mut self, current_tab: CurrentTab) {
|
|
||||||
match current_tab {
|
|
||||||
CurrentTab::Accounts => self.is_active = true,
|
|
||||||
_ => self.is_active = false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for StakingLedger {
|
|
||||||
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::Wallet) {
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
|
||||||
match action {
|
|
||||||
Action::UsedAccount(account_id, _) => self.set_used_account_id(account_id),
|
|
||||||
Action::SetIsBonded(is_bonded, account_id) if self.account_id == account_id => self.is_bonded = is_bonded,
|
|
||||||
Action::SetStakedAmountRatio(total, active, account_id) if self.account_id == account_id => {
|
|
||||||
self.total_staked = total;
|
|
||||||
self.active_staked = active;
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
|
||||||
let [_, _, _, place] = super::account_layout(area);
|
|
||||||
let (border_style, border_type) = self.palette
|
|
||||||
.create_border_style(self.is_active);
|
|
||||||
|
|
||||||
let table = Table::new(
|
|
||||||
[
|
|
||||||
Row::new(vec![
|
|
||||||
Cell::from(Text::from("Bond ready: ".to_string()).alignment(Alignment::Left)),
|
|
||||||
Cell::from(Text::from(self.is_bonded_to_string()).alignment(Alignment::Right)),
|
|
||||||
]),
|
|
||||||
Row::new(vec![
|
|
||||||
Cell::from(Text::from("total: ".to_string()).alignment(Alignment::Left)),
|
|
||||||
Cell::from(Text::from(self.prepare_u128(self.total_staked)).alignment(Alignment::Right))
|
|
||||||
]),
|
|
||||||
Row::new(vec![
|
|
||||||
Cell::from(Text::from("active: ".to_string()).alignment(Alignment::Left)),
|
|
||||||
Cell::from(Text::from(self.prepare_u128(self.active_staked)).alignment(Alignment::Right)),
|
|
||||||
]),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
Constraint::Max(10),
|
|
||||||
Constraint::Min(14),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
.block(Block::bordered()
|
|
||||||
.border_style(border_style)
|
|
||||||
.border_type(border_type)
|
|
||||||
.title_alignment(Alignment::Right)
|
|
||||||
.title_style(self.palette.create_title_style(false))
|
|
||||||
.title("Nomination stake"));
|
|
||||||
|
|
||||||
frame.render_widget(table, place);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
@ -215,7 +215,7 @@ impl Component for Transfer {
|
|||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
match action {
|
match action {
|
||||||
Action::UsedAccount(_, seed) => self.sender = seed,
|
Action::UsedAccount(seed) => self.sender = seed,
|
||||||
Action::TransferTo(who) => {
|
Action::TransferTo(who) => {
|
||||||
self.receiver = Input::new(who);
|
self.receiver = Input::new(who);
|
||||||
self.receiver_or_amount = ReceiverOrAmount::Amount;
|
self.receiver_or_amount = ReceiverOrAmount::Amount;
|
||||||
|
@ -129,8 +129,6 @@ impl Network {
|
|||||||
predefined_calls::get_validator_prefs(&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?;
|
predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
|
||||||
predefined_calls::get_validator_latest_claim(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
|
predefined_calls::get_validator_latest_claim(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
|
||||||
predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
|
|
||||||
predefined_calls::get_is_stash_bonded(&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?;
|
||||||
|
@ -430,17 +430,11 @@ pub async fn get_validators_ledger(
|
|||||||
let maybe_ledger = super::raw_calls::staking::ledger(api, None, account_id)
|
let maybe_ledger = super::raw_calls::staking::ledger(api, None, account_id)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
match maybe_ledger {
|
if let Some(ledger) = maybe_ledger {
|
||||||
Some(ledger) => {
|
action_tx.send(Action::SetStakedAmountRatio(ledger.total, ledger.active, *account_id))?;
|
||||||
action_tx.send(Action::SetStakedAmountRatio(Some(ledger.total), Some(ledger.active), *account_id))?;
|
action_tx.send(Action::SetUnlockingIsEmpty(ledger.unlocking.0.is_empty(), *account_id))?;
|
||||||
action_tx.send(Action::SetUnlockingIsEmpty(ledger.unlocking.0.is_empty(), *account_id))?;
|
for chunk in ledger.unlocking.0.iter() {
|
||||||
for chunk in ledger.unlocking.0.iter() {
|
action_tx.send(Action::SetValidatorEraUnlocking(chunk.era, chunk.value, *account_id))?;
|
||||||
action_tx.send(Action::SetValidatorEraUnlocking(chunk.era, chunk.value, *account_id))?;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
action_tx.send(Action::SetStakedAmountRatio(None, None, *account_id))?;
|
|
||||||
action_tx.send(Action::SetUnlockingIsEmpty(true, *account_id))?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +481,7 @@ pub async fn get_is_stash_bonded(
|
|||||||
let is_bonded = super::raw_calls::staking::bonded(api, None, account_id)
|
let is_bonded = super::raw_calls::staking::bonded(api, None, account_id)
|
||||||
.await?
|
.await?
|
||||||
.is_some();
|
.is_some();
|
||||||
action_tx.send(Action::SetIsBonded(is_bonded, *account_id))?;
|
action_tx.send(Action::SetIsBonded(is_bonded))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user