Compare commits
3 Commits
105ca64dc6
...
756a1089f6
Author | SHA1 | Date | |
---|---|---|---|
756a1089f6 | |||
edd1b6d616 | |||
13295288ce |
@ -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.47"
|
version = "0.3.50"
|
||||||
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"
|
||||||
|
@ -41,17 +41,6 @@
|
|||||||
"popup_style": "blue",
|
"popup_style": "blue",
|
||||||
"popup_title_style": "blue",
|
"popup_title_style": "blue",
|
||||||
},
|
},
|
||||||
"Nominator": {
|
|
||||||
"normal_style": "",
|
|
||||||
"hover_style": "bold yellow italic on blue",
|
|
||||||
"normal_border_style": "blue",
|
|
||||||
"hover_border_style": "blue",
|
|
||||||
"normal_title_style": "blue",
|
|
||||||
"hover_title_style": "",
|
|
||||||
"highlight_style": "yellow bold",
|
|
||||||
"popup_style": "blue",
|
|
||||||
"popup_title_style": "blue",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
"keybindings": {
|
"keybindings": {
|
||||||
"Menu": {
|
"Menu": {
|
||||||
@ -77,12 +66,6 @@
|
|||||||
"<Ctrl-c>": "Quit",
|
"<Ctrl-c>": "Quit",
|
||||||
"<Ctrl-z>": "Suspend",
|
"<Ctrl-z>": "Suspend",
|
||||||
},
|
},
|
||||||
"Nominator": {
|
|
||||||
"<q>": "Quit",
|
|
||||||
"<Ctrl-d>": "Quit",
|
|
||||||
"<Ctrl-c>": "Quit",
|
|
||||||
"<Ctrl-z>": "Suspend",
|
|
||||||
},
|
|
||||||
"Empty": {
|
"Empty": {
|
||||||
"<q>": "Quit",
|
"<q>": "Quit",
|
||||||
"<Ctrl-d>": "Quit",
|
"<Ctrl-d>": "Quit",
|
||||||
|
@ -5,7 +5,9 @@ use subxt::utils::H256;
|
|||||||
use subxt::config::substrate::DigestItem;
|
use subxt::config::substrate::DigestItem;
|
||||||
|
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
ActionLevel, ActionTarget, CasperExtrinsicDetails, EraInfo, EraRewardPoints, Nominator, PeerInformation, SessionKeyInfo, UnlockChunk, SystemAccount
|
ActionLevel, ActionTarget, CasperExtrinsicDetails, EraInfo, EraRewardPoints,
|
||||||
|
Nominator, PeerInformation, SessionKeyInfo, UnlockChunk, SystemAccount,
|
||||||
|
RewardDestination,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
|
||||||
@ -51,8 +53,9 @@ pub enum Action {
|
|||||||
StoreRotatedKeys(String),
|
StoreRotatedKeys(String),
|
||||||
|
|
||||||
TransferBalance(String, [u8; 32], u128),
|
TransferBalance(String, [u8; 32], u128),
|
||||||
BondValidatorExtraFrom([u8; 32], u128),
|
BondValidatorExtraFrom([u8; 32], u128, ActionTarget),
|
||||||
BondValidatorFrom([u8; 32], u128),
|
BondValidatorFrom([u8; 32], u128, ActionTarget),
|
||||||
|
SetPayee([u8; 32], RewardDestination, ActionTarget),
|
||||||
PayoutStakers([u8; 32], [u8; 32], u32),
|
PayoutStakers([u8; 32], [u8; 32], u32),
|
||||||
SetSessionKeys([u8; 32], String),
|
SetSessionKeys([u8; 32], String),
|
||||||
ValidateFrom([u8; 32], u32),
|
ValidateFrom([u8; 32], u32),
|
||||||
@ -104,6 +107,7 @@ pub enum Action {
|
|||||||
GetValidatorPrefs([u8; 32], bool),
|
GetValidatorPrefs([u8; 32], bool),
|
||||||
GetSlashingSpans([u8; 32], bool),
|
GetSlashingSpans([u8; 32], bool),
|
||||||
GetValidatorLatestClaim([u8; 32], bool),
|
GetValidatorLatestClaim([u8; 32], bool),
|
||||||
|
GetStakingPayee([u8; 32], bool),
|
||||||
GetValidatorIsDisabled([u8; 32], bool),
|
GetValidatorIsDisabled([u8; 32], bool),
|
||||||
GetCurrentValidatorEraRewards,
|
GetCurrentValidatorEraRewards,
|
||||||
|
|
||||||
@ -134,6 +138,7 @@ pub enum Action {
|
|||||||
SetValidatorEraSlash(u32, u128),
|
SetValidatorEraSlash(u32, u128),
|
||||||
SetValidatorEraUnlocking(Vec<UnlockChunk>, [u8; 32]),
|
SetValidatorEraUnlocking(Vec<UnlockChunk>, [u8; 32]),
|
||||||
SetValidatorLatestClaim(u32, [u8; 32]),
|
SetValidatorLatestClaim(u32, [u8; 32]),
|
||||||
|
SetStakingPayee(RewardDestination, [u8; 32]),
|
||||||
SetIsBonded(bool, [u8; 32]),
|
SetIsBonded(bool, [u8; 32]),
|
||||||
SetStakedAmountRatio(Option<u128>, Option<u128>, [u8; 32]),
|
SetStakedAmountRatio(Option<u128>, Option<u128>, [u8; 32]),
|
||||||
SetStakedRatio(u128, u128, [u8; 32]),
|
SetStakedRatio(u128, u128, [u8; 32]),
|
||||||
|
13
src/app.rs
13
src/app.rs
@ -12,7 +12,7 @@ use crate::{
|
|||||||
tui::{Event, Tui},
|
tui::{Event, Tui},
|
||||||
components::{
|
components::{
|
||||||
menu::Menu, version::Version, explorer::Explorer, wallet::Wallet,
|
menu::Menu, version::Version, explorer::Explorer, wallet::Wallet,
|
||||||
validator::Validator, nominator::Nominator, empty::Empty,
|
validator::Validator, empty::Empty,
|
||||||
health::Health, fps::FpsCounter,
|
health::Health, fps::FpsCounter,
|
||||||
Component,
|
Component,
|
||||||
},
|
},
|
||||||
@ -24,7 +24,6 @@ pub enum Mode {
|
|||||||
Explorer,
|
Explorer,
|
||||||
Wallet,
|
Wallet,
|
||||||
Validator,
|
Validator,
|
||||||
Nominator,
|
|
||||||
Empty,
|
Empty,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +72,6 @@ impl App {
|
|||||||
Box::new(Explorer::default()),
|
Box::new(Explorer::default()),
|
||||||
Box::new(Wallet::default()),
|
Box::new(Wallet::default()),
|
||||||
Box::new(Validator::default()),
|
Box::new(Validator::default()),
|
||||||
Box::new(Nominator::default()),
|
|
||||||
Box::new(Empty::default()),
|
Box::new(Empty::default()),
|
||||||
],
|
],
|
||||||
should_quite: false,
|
should_quite: false,
|
||||||
@ -268,15 +266,6 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Mode::Nominator => {
|
|
||||||
if let Some(component) = self.components.get_mut(7) {
|
|
||||||
if let Err(err) = component.draw(frame, frame.area()) {
|
|
||||||
let _ = self
|
|
||||||
.action_tx
|
|
||||||
.send(Action::Error(format!("failed to draw: {:?}", err)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(component) = self.components.last_mut() {
|
if let Some(component) = self.components.last_mut() {
|
||||||
if let Err(err) = component.draw(frame, frame.area()) {
|
if let Err(err) = component.draw(frame, frame.area()) {
|
||||||
|
@ -30,7 +30,6 @@ impl Menu {
|
|||||||
String::from("Explorer"),
|
String::from("Explorer"),
|
||||||
String::from("Wallet"),
|
String::from("Wallet"),
|
||||||
String::from("Validator"),
|
String::from("Validator"),
|
||||||
String::from("Nominator"),
|
|
||||||
String::from("Prices"),
|
String::from("Prices"),
|
||||||
String::from("Governance"),
|
String::from("Governance"),
|
||||||
String::from("Operations"),
|
String::from("Operations"),
|
||||||
@ -59,7 +58,6 @@ impl Menu {
|
|||||||
0 => Ok(Some(Action::SetMode(Mode::Explorer))),
|
0 => Ok(Some(Action::SetMode(Mode::Explorer))),
|
||||||
1 => Ok(Some(Action::SetMode(Mode::Wallet))),
|
1 => Ok(Some(Action::SetMode(Mode::Wallet))),
|
||||||
2 => Ok(Some(Action::SetMode(Mode::Validator))),
|
2 => Ok(Some(Action::SetMode(Mode::Validator))),
|
||||||
3 => Ok(Some(Action::SetMode(Mode::Nominator))),
|
|
||||||
_ => Ok(Some(Action::SetMode(Mode::Empty))),
|
_ => Ok(Some(Action::SetMode(Mode::Empty))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +78,6 @@ impl Menu {
|
|||||||
0 => Ok(Some(Action::SetMode(Mode::Explorer))),
|
0 => Ok(Some(Action::SetMode(Mode::Explorer))),
|
||||||
1 => Ok(Some(Action::SetMode(Mode::Wallet))),
|
1 => Ok(Some(Action::SetMode(Mode::Wallet))),
|
||||||
2 => Ok(Some(Action::SetMode(Mode::Validator))),
|
2 => Ok(Some(Action::SetMode(Mode::Validator))),
|
||||||
3 => Ok(Some(Action::SetMode(Mode::Nominator))),
|
|
||||||
_ => Ok(Some(Action::SetMode(Mode::Empty))),
|
_ => Ok(Some(Action::SetMode(Mode::Empty))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,7 +118,6 @@ impl Component for Menu {
|
|||||||
Some(0) => Ok(Some(Action::SetActiveScreen(Mode::Explorer))),
|
Some(0) => Ok(Some(Action::SetActiveScreen(Mode::Explorer))),
|
||||||
Some(1) => Ok(Some(Action::SetActiveScreen(Mode::Wallet))),
|
Some(1) => Ok(Some(Action::SetActiveScreen(Mode::Wallet))),
|
||||||
Some(2) => Ok(Some(Action::SetActiveScreen(Mode::Validator))),
|
Some(2) => Ok(Some(Action::SetActiveScreen(Mode::Validator))),
|
||||||
Some(3) => Ok(Some(Action::SetActiveScreen(Mode::Nominator))),
|
|
||||||
_ => Ok(Some(Action::SetActiveScreen(Mode::Empty))),
|
_ => Ok(Some(Action::SetActiveScreen(Mode::Empty))),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,6 @@ pub mod version;
|
|||||||
pub mod explorer;
|
pub mod explorer;
|
||||||
pub mod wallet;
|
pub mod wallet;
|
||||||
pub mod validator;
|
pub mod validator;
|
||||||
pub mod nominator;
|
|
||||||
pub mod empty;
|
pub mod empty;
|
||||||
|
|
||||||
pub trait Component {
|
pub trait Component {
|
||||||
|
@ -1,217 +0,0 @@
|
|||||||
use color_eyre::Result;
|
|
||||||
use crossterm::event::{KeyCode, KeyEvent};
|
|
||||||
use ratatui::{
|
|
||||||
layout::{Alignment, Constraint, Margin, Rect},
|
|
||||||
style::{Color, Style},
|
|
||||||
text::Text,
|
|
||||||
widgets::{
|
|
||||||
Block, Padding, Cell, Row, Scrollbar, ScrollbarOrientation,
|
|
||||||
ScrollbarState, Table, TableState,
|
|
||||||
},
|
|
||||||
Frame
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{Component, PartialComponent, CurrentTab};
|
|
||||||
use crate::{
|
|
||||||
types::ActionLevel,
|
|
||||||
action::Action,
|
|
||||||
config::Config,
|
|
||||||
palette::StylePalette,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
struct LogDetails {
|
|
||||||
time: chrono::DateTime<chrono::Local>,
|
|
||||||
level: ActionLevel,
|
|
||||||
message: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct EventLogs {
|
|
||||||
is_active: bool,
|
|
||||||
scroll_state: ScrollbarState,
|
|
||||||
table_state: TableState,
|
|
||||||
logs: std::collections::VecDeque<LogDetails>,
|
|
||||||
palette: StylePalette
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove later
|
|
||||||
impl Default for EventLogs {
|
|
||||||
fn default() -> Self {
|
|
||||||
EventLogs {
|
|
||||||
is_active: false,
|
|
||||||
scroll_state: Default::default(),
|
|
||||||
table_state: Default::default(),
|
|
||||||
logs: std::collections::VecDeque::from(vec![
|
|
||||||
LogDetails {
|
|
||||||
time: chrono::Local::now(),
|
|
||||||
level: ActionLevel::Warn,
|
|
||||||
message: "NOT FINALIZED PAGE! NEEDED IN ORDER TO SEE VALIDATORS POINTS".to_string(),
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
palette: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EventLogs {
|
|
||||||
//const MAX_LOGS: usize = 50;
|
|
||||||
|
|
||||||
//fn add_new_log(&mut self, message: String, level: ActionLevel) {
|
|
||||||
// self.logs.push_front(LogDetails {
|
|
||||||
// time: chrono::Local::now(),
|
|
||||||
// level,
|
|
||||||
// message,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// if self.logs.len() > Self::MAX_LOGS {
|
|
||||||
// let _ = self.logs.pop_back();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
fn first_row(&mut self) {
|
|
||||||
if self.logs.len() > 0 {
|
|
||||||
self.table_state.select(Some(0));
|
|
||||||
self.scroll_state = self.scroll_state.position(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn next_row(&mut self) {
|
|
||||||
let i = match self.table_state.selected() {
|
|
||||||
Some(i) => {
|
|
||||||
if i >= self.logs.len() - 1 {
|
|
||||||
i
|
|
||||||
} else {
|
|
||||||
i + 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => 0,
|
|
||||||
};
|
|
||||||
self.table_state.select(Some(i));
|
|
||||||
self.scroll_state = self.scroll_state.position(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn last_row(&mut self) {
|
|
||||||
if self.logs.len() > 0 {
|
|
||||||
let last = self.logs.len() - 1;
|
|
||||||
self.table_state.select(Some(last));
|
|
||||||
self.scroll_state = self.scroll_state.position(last);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn previous_row(&mut self) {
|
|
||||||
let i = match self.table_state.selected() {
|
|
||||||
Some(i) => {
|
|
||||||
if i == 0 {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
i - 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => 0
|
|
||||||
};
|
|
||||||
self.table_state.select(Some(i));
|
|
||||||
self.scroll_state = self.scroll_state.position(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialComponent for EventLogs {
|
|
||||||
fn set_active(&mut self, current_tab: CurrentTab) {
|
|
||||||
match current_tab {
|
|
||||||
CurrentTab::EventLogs => self.is_active = true,
|
|
||||||
_ => {
|
|
||||||
self.is_active = false;
|
|
||||||
self.table_state.select(None);
|
|
||||||
self.scroll_state = self.scroll_state.position(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for EventLogs {
|
|
||||||
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 handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
|
||||||
match key.code {
|
|
||||||
KeyCode::Up | KeyCode::Char('k') if self.is_active => self.previous_row(),
|
|
||||||
KeyCode::Down | KeyCode::Char('j') if self.is_active => self.next_row(),
|
|
||||||
KeyCode::Char('g') if self.is_active => self.first_row(),
|
|
||||||
KeyCode::Char('G') if self.is_active => self.last_row(),
|
|
||||||
_ => {},
|
|
||||||
};
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, _action: Action) -> Result<Option<Action>> {
|
|
||||||
//match action {
|
|
||||||
// Action::EventLog(message, level, target) if target == ActionTarget::NominatorLog =>
|
|
||||||
// self.add_new_log(message, level),
|
|
||||||
// _ => {}
|
|
||||||
//};
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
|
||||||
let [_, _, place] = super::nominator_layout(area);
|
|
||||||
|
|
||||||
let (border_style, border_type) = self.palette.create_border_style(self.is_active);
|
|
||||||
let error_style = Style::new().fg(Color::Red);
|
|
||||||
let warn_style = Style::new().fg(Color::Yellow);
|
|
||||||
let info_style = Style::new().fg(Color::Green);
|
|
||||||
|
|
||||||
let table = Table::new(
|
|
||||||
self.logs
|
|
||||||
.iter()
|
|
||||||
.map(|log| {
|
|
||||||
let style = match log.level {
|
|
||||||
ActionLevel::Info => info_style,
|
|
||||||
ActionLevel::Warn => warn_style,
|
|
||||||
ActionLevel::Error => error_style,
|
|
||||||
};
|
|
||||||
Row::new(vec![
|
|
||||||
Cell::from(Text::from(log.time.format("%H:%M:%S").to_string()).style(style).alignment(Alignment::Left)),
|
|
||||||
Cell::from(Text::from(log.message.clone()).style(style).alignment(Alignment::Left)),
|
|
||||||
])
|
|
||||||
}),
|
|
||||||
[
|
|
||||||
Constraint::Max(8),
|
|
||||||
Constraint::Min(0),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
.column_spacing(1)
|
|
||||||
.highlight_style(self.palette.create_highlight_style())
|
|
||||||
.block(Block::bordered()
|
|
||||||
.border_style(border_style)
|
|
||||||
.border_type(border_type)
|
|
||||||
.padding(Padding::right(2))
|
|
||||||
.title_alignment(Alignment::Right)
|
|
||||||
.title_style(self.palette.create_title_style(false))
|
|
||||||
.title("Action Logs"));
|
|
||||||
|
|
||||||
let scrollbar = Scrollbar::default()
|
|
||||||
.orientation(ScrollbarOrientation::VerticalRight)
|
|
||||||
.begin_symbol(None)
|
|
||||||
.end_symbol(None)
|
|
||||||
.style(self.palette.create_scrollbar_style());
|
|
||||||
|
|
||||||
frame.render_stateful_widget(table, place, &mut self.table_state);
|
|
||||||
frame.render_stateful_widget(
|
|
||||||
scrollbar,
|
|
||||||
place.inner(Margin { vertical: 1, horizontal: 1 }),
|
|
||||||
&mut self.scroll_state,
|
|
||||||
);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,185 +0,0 @@
|
|||||||
use color_eyre::Result;
|
|
||||||
use crossterm::event::{KeyCode, KeyEvent};
|
|
||||||
use ratatui::{
|
|
||||||
layout::{Constraint, Layout, Rect},
|
|
||||||
Frame,
|
|
||||||
};
|
|
||||||
|
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
|
||||||
|
|
||||||
use super::Component;
|
|
||||||
use crate::{action::Action, app::Mode, config::Config};
|
|
||||||
|
|
||||||
mod event_log;
|
|
||||||
mod current_validators;
|
|
||||||
mod rename_known_validator;
|
|
||||||
mod current_validator_details;
|
|
||||||
|
|
||||||
use event_log::EventLogs;
|
|
||||||
use current_validators::CurrentValidators;
|
|
||||||
use current_validator_details::CurrentValidatorDetails;
|
|
||||||
use rename_known_validator::RenameKnownValidator;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub enum CurrentTab {
|
|
||||||
Nothing,
|
|
||||||
CurrentValidators,
|
|
||||||
EventLogs,
|
|
||||||
RenameKnownValidator,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait PartialComponent: Component {
|
|
||||||
fn set_active(&mut self, current_tab: CurrentTab);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Nominator {
|
|
||||||
is_active: bool,
|
|
||||||
current_tab: CurrentTab,
|
|
||||||
components: Vec<Box<dyn PartialComponent>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Nominator {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
is_active: false,
|
|
||||||
current_tab: CurrentTab::Nothing,
|
|
||||||
components: vec![
|
|
||||||
Box::new(CurrentValidators::default()),
|
|
||||||
Box::new(CurrentValidatorDetails::default()),
|
|
||||||
Box::new(EventLogs::default()),
|
|
||||||
Box::new(RenameKnownValidator::default()),
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Nominator {
|
|
||||||
fn move_left(&mut self) {
|
|
||||||
match self.current_tab {
|
|
||||||
CurrentTab::EventLogs => self.current_tab = CurrentTab::CurrentValidators,
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn move_right(&mut self) {
|
|
||||||
match self.current_tab {
|
|
||||||
CurrentTab::CurrentValidators => self.current_tab = CurrentTab::EventLogs,
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for Nominator {
|
|
||||||
fn register_network_handler(&mut self, tx: Sender<Action>) -> Result<()> {
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.register_network_handler(tx.clone())?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.register_action_handler(tx.clone())?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.register_config_handler(config.clone())?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
|
||||||
if !self.is_active { return Ok(None) }
|
|
||||||
|
|
||||||
match self.current_tab {
|
|
||||||
CurrentTab::RenameKnownValidator => match key.code {
|
|
||||||
KeyCode::Esc => {
|
|
||||||
self.current_tab = CurrentTab::CurrentValidators;
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.handle_key_event(key)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => match key.code {
|
|
||||||
KeyCode::Esc => {
|
|
||||||
self.is_active = false;
|
|
||||||
self.current_tab = CurrentTab::Nothing;
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
return Ok(Some(Action::SetActiveScreen(Mode::Menu)));
|
|
||||||
},
|
|
||||||
KeyCode::Char('l') | KeyCode::Right => {
|
|
||||||
self.move_right();
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
KeyCode::Char('h') | KeyCode::Left => {
|
|
||||||
self.move_left();
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.handle_key_event(key)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
|
||||||
match action {
|
|
||||||
Action::RenameKnownValidatorRecord =>
|
|
||||||
self.current_tab = CurrentTab::RenameKnownValidator,
|
|
||||||
Action::UpdateKnownValidator(_) =>
|
|
||||||
self.current_tab = CurrentTab::CurrentValidators,
|
|
||||||
Action::SetActiveScreen(Mode::Nominator) => {
|
|
||||||
self.is_active = true;
|
|
||||||
self.current_tab = CurrentTab::CurrentValidators;
|
|
||||||
},
|
|
||||||
_ => {},
|
|
||||||
}
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
component.update(action.clone())?;
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
|
||||||
let screen = super::screen_layout(area);
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.draw(frame, screen)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn nominator_layout(area: Rect) -> [Rect; 3] {
|
|
||||||
Layout::vertical([
|
|
||||||
Constraint::Percentage(25),
|
|
||||||
Constraint::Percentage(50),
|
|
||||||
Constraint::Percentage(25),
|
|
||||||
]).areas(area)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn validator_details_layout(area: Rect) -> [Rect; 2] {
|
|
||||||
let [place, _, _] = nominator_layout(area);
|
|
||||||
Layout::horizontal([
|
|
||||||
Constraint::Percentage(60),
|
|
||||||
Constraint::Percentage(40),
|
|
||||||
]).areas(place)
|
|
||||||
}
|
|
@ -71,10 +71,11 @@ impl BondPopup {
|
|||||||
match str_amount.parse::<f64>() {
|
match str_amount.parse::<f64>() {
|
||||||
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 log_target = ActionTarget::ValidatorLog;
|
||||||
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.stash_secret_seed, amount, log_target))
|
||||||
} else {
|
} else {
|
||||||
network_tx.send(Action::BondValidatorFrom(self.stash_secret_seed, amount))
|
network_tx.send(Action::BondValidatorFrom(self.stash_secret_seed, amount, log_target))
|
||||||
};
|
};
|
||||||
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);
|
||||||
|
@ -6,8 +6,10 @@ use ratatui::{
|
|||||||
widgets::{Block, Cell, Row, Table},
|
widgets::{Block, Cell, Row, Table},
|
||||||
Frame
|
Frame
|
||||||
};
|
};
|
||||||
|
use subxt::ext::sp_core::crypto::{Ss58Codec, Ss58AddressFormat, AccountId32};
|
||||||
|
|
||||||
use super::{PartialComponent, Component, CurrentTab};
|
use super::{PartialComponent, Component, CurrentTab};
|
||||||
|
use crate::types::RewardDestination;
|
||||||
use crate::{
|
use crate::{
|
||||||
action::Action,
|
action::Action,
|
||||||
config::Config,
|
config::Config,
|
||||||
@ -19,6 +21,7 @@ pub struct StakingDetails {
|
|||||||
staked_own: u128,
|
staked_own: u128,
|
||||||
staked_total: u128,
|
staked_total: u128,
|
||||||
stash: [u8; 32],
|
stash: [u8; 32],
|
||||||
|
reward_destination: RewardDestination,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for StakingDetails {
|
impl Default for StakingDetails {
|
||||||
@ -37,6 +40,7 @@ impl StakingDetails {
|
|||||||
staked_own: 0,
|
staked_own: 0,
|
||||||
staked_total: 0,
|
staked_total: 0,
|
||||||
stash: [0u8; 32],
|
stash: [0u8; 32],
|
||||||
|
reward_destination: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +49,22 @@ impl StakingDetails {
|
|||||||
let after = Self::DECIMALS;
|
let after = Self::DECIMALS;
|
||||||
format!("{:.after$}{}", value, Self::TICKER)
|
format!("{:.after$}{}", value, Self::TICKER)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_reward_destination(&self) -> String {
|
||||||
|
match self.reward_destination {
|
||||||
|
RewardDestination::Staked => "re-stake".to_string(),
|
||||||
|
RewardDestination::Stash => "stake".to_string(),
|
||||||
|
RewardDestination::Controller => "controller".to_string(),
|
||||||
|
RewardDestination::None => "empty".to_string(),
|
||||||
|
RewardDestination::Account(account_id) => {
|
||||||
|
let address = AccountId32::from(account_id)
|
||||||
|
.to_ss58check_with_version(Ss58AddressFormat::custom(1996));
|
||||||
|
let tail = address.len().saturating_sub(5);
|
||||||
|
format!("{}..{}", &address[..5], &address[tail..])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialComponent for StakingDetails {
|
impl PartialComponent for StakingDetails {
|
||||||
@ -69,6 +89,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::SetStashAccount(account_id) => self.stash = account_id,
|
Action::SetStashAccount(account_id) => self.stash = account_id,
|
||||||
|
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 => {
|
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;
|
||||||
@ -82,6 +104,7 @@ impl Component for StakingDetails {
|
|||||||
let [_, place, _] = super::validator_balance_layout(area);
|
let [_, place, _] = super::validator_balance_layout(area);
|
||||||
let (border_style, border_type) = self.palette.create_border_style(false);
|
let (border_style, border_type) = self.palette.create_border_style(false);
|
||||||
|
|
||||||
|
let title = format!("Staking details: {}", self.get_reward_destination());
|
||||||
let table = Table::new(
|
let table = Table::new(
|
||||||
vec![
|
vec![
|
||||||
Row::new(vec![
|
Row::new(vec![
|
||||||
@ -109,7 +132,7 @@ impl Component for StakingDetails {
|
|||||||
.border_type(border_type)
|
.border_type(border_type)
|
||||||
.title_alignment(Alignment::Right)
|
.title_alignment(Alignment::Right)
|
||||||
.title_style(self.palette.create_title_style(false))
|
.title_style(self.palette.create_title_style(false))
|
||||||
.title("Staking details"));
|
.title(title));
|
||||||
|
|
||||||
frame.render_widget(table, place);
|
frame.render_widget(table, place);
|
||||||
|
|
||||||
|
@ -160,6 +160,7 @@ impl StashInfo {
|
|||||||
let _ = network_tx.send(Action::GetValidatorAllRewards(account_id, true));
|
let _ = network_tx.send(Action::GetValidatorAllRewards(account_id, true));
|
||||||
let _ = network_tx.send(Action::GetSlashingSpans(account_id, true));
|
let _ = network_tx.send(Action::GetSlashingSpans(account_id, true));
|
||||||
let _ = network_tx.send(Action::GetValidatorIsDisabled(account_id, true));
|
let _ = network_tx.send(Action::GetValidatorIsDisabled(account_id, true));
|
||||||
|
let _ = network_tx.send(Action::GetStakingPayee(account_id, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,9 @@ impl Accounts {
|
|||||||
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;
|
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(
|
||||||
|
account_id,
|
||||||
|
used_seed.clone()));
|
||||||
}
|
}
|
||||||
self.set_sender_nonce(index);
|
self.set_sender_nonce(index);
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,19 @@ impl AddAccount {
|
|||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl AddAccount {
|
fn close_popup(&mut self) {
|
||||||
|
self.is_active = false;
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn submit_message(&mut self) {
|
fn submit_message(&mut self) {
|
||||||
if let Some(action_tx) = &self.action_tx {
|
if let Some(action_tx) = &self.action_tx {
|
||||||
let _ = action_tx.send(Action::NewAccount(self.name.value().to_string()));
|
let _ = action_tx.send(Action::NewAccount(
|
||||||
|
self.name.value().to_string()));
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +108,7 @@ impl Component for AddAccount {
|
|||||||
KeyCode::Backspace => self.delete_char(),
|
KeyCode::Backspace => self.delete_char(),
|
||||||
KeyCode::Left => self.move_cursor_left(),
|
KeyCode::Left => self.move_cursor_left(),
|
||||||
KeyCode::Right => self.move_cursor_right(),
|
KeyCode::Right => self.move_cursor_right(),
|
||||||
KeyCode::Esc => self.is_active = false,
|
KeyCode::Esc => self.close_popup(),
|
||||||
_ => {},
|
_ => {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -48,9 +48,14 @@ impl AddAddressBookRecord {
|
|||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl AddAddressBookRecord {
|
fn close_popup(&mut self) {
|
||||||
|
self.is_active = false;
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn submit_message(&mut self) {
|
fn submit_message(&mut self) {
|
||||||
match self.name_or_address {
|
match self.name_or_address {
|
||||||
NameOrAddress::Name => self.name_or_address = NameOrAddress::Address,
|
NameOrAddress::Name => self.name_or_address = NameOrAddress::Address,
|
||||||
@ -58,6 +63,7 @@ impl AddAddressBookRecord {
|
|||||||
let _ = action_tx.send(Action::NewAddressBookRecord(
|
let _ = action_tx.send(Action::NewAddressBookRecord(
|
||||||
self.name.value().to_string(),
|
self.name.value().to_string(),
|
||||||
self.address.value().to_string()));
|
self.address.value().to_string()));
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +156,7 @@ impl Component for AddAddressBookRecord {
|
|||||||
KeyCode::Backspace => self.delete_char(),
|
KeyCode::Backspace => self.delete_char(),
|
||||||
KeyCode::Left => self.move_cursor_left(),
|
KeyCode::Left => self.move_cursor_left(),
|
||||||
KeyCode::Right => self.move_cursor_right(),
|
KeyCode::Right => self.move_cursor_right(),
|
||||||
KeyCode::Esc => self.is_active = false,
|
KeyCode::Esc => self.close_popup(),
|
||||||
_ => {},
|
_ => {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
209
src/components/wallet/bond_popup.rs
Normal file
209
src/components/wallet/bond_popup.rs
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
|
||||||
|
use color_eyre::Result;
|
||||||
|
use ratatui::{
|
||||||
|
layout::{Position, Alignment, Constraint, Flex, Layout, Rect},
|
||||||
|
widgets::{Block, Clear, Paragraph},
|
||||||
|
Frame
|
||||||
|
};
|
||||||
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
use super::{Component, PartialComponent, CurrentTab};
|
||||||
|
use crate::{
|
||||||
|
action::Action,
|
||||||
|
config::Config,
|
||||||
|
palette::StylePalette,
|
||||||
|
types::{ActionLevel, ActionTarget},
|
||||||
|
widgets::{Input, InputRequest},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct BondPopup {
|
||||||
|
is_active: bool,
|
||||||
|
action_tx: Option<UnboundedSender<Action>>,
|
||||||
|
network_tx: Option<Sender<Action>>,
|
||||||
|
account_secret_seed: [u8; 32],
|
||||||
|
account_id: [u8; 32],
|
||||||
|
minimal_bond: u128,
|
||||||
|
is_bonded: bool,
|
||||||
|
amount: Input,
|
||||||
|
palette: StylePalette
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for BondPopup {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BondPopup {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
is_active: false,
|
||||||
|
account_secret_seed: [0u8; 32],
|
||||||
|
account_id: [0u8; 32],
|
||||||
|
action_tx: None,
|
||||||
|
network_tx: None,
|
||||||
|
minimal_bond: 0u128,
|
||||||
|
is_bonded: false,
|
||||||
|
amount: Input::new(String::new()),
|
||||||
|
palette: StylePalette::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log_event(&mut self, message: String, level: ActionLevel) {
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(
|
||||||
|
Action::EventLog(message, level, ActionTarget::WalletLog));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn close_popup(&mut self) {
|
||||||
|
self.is_active = false;
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_used_account(&mut self, account_id: [u8; 32], secret_seed_str: String) {
|
||||||
|
let secret_seed: [u8; 32] = hex::decode(secret_seed_str)
|
||||||
|
.expect("stored seed is valid hex string; qed")
|
||||||
|
.as_slice()
|
||||||
|
.try_into()
|
||||||
|
.expect("stored seed is valid length; qed");
|
||||||
|
self.account_id = account_id;
|
||||||
|
self.account_secret_seed = secret_seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn submit_message(&mut self) {
|
||||||
|
if let Some(network_tx) = &self.network_tx {
|
||||||
|
let str_amount = self.amount.value();
|
||||||
|
let str_amount = if str_amount.starts_with('.') {
|
||||||
|
&format!("0{}", str_amount)[..]
|
||||||
|
} else {
|
||||||
|
str_amount
|
||||||
|
};
|
||||||
|
match str_amount.parse::<f64>() {
|
||||||
|
Ok(value) => {
|
||||||
|
let amount = (value * 1_000_000_000_000_000_000.0) as u128;
|
||||||
|
let log_target = ActionTarget::WalletLog;
|
||||||
|
let _ = if self.is_bonded {
|
||||||
|
network_tx.send(Action::BondValidatorExtraFrom(self.account_secret_seed, amount, log_target))
|
||||||
|
} else {
|
||||||
|
network_tx.send(Action::BondValidatorFrom(self.account_secret_seed, amount, log_target))
|
||||||
|
};
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => self.log_event(
|
||||||
|
format!("invalid amount, error: {err}"), ActionLevel::Error),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enter_char(&mut self, new_char: char) {
|
||||||
|
let is_separator_needed = !self.amount.value().contains('.') && new_char == '.';
|
||||||
|
if new_char.is_digit(10) || is_separator_needed {
|
||||||
|
let _ = self.amount.handle(InputRequest::InsertChar(new_char));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_char(&mut self) {
|
||||||
|
let _ = self.amount.handle(InputRequest::DeletePrevChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_cursor_right(&mut self) {
|
||||||
|
let _ = self.amount.handle(InputRequest::GoToNextChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_cursor_left(&mut self) {
|
||||||
|
let _ = self.amount.handle(InputRequest::GoToPrevChar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialComponent for BondPopup {
|
||||||
|
fn set_active(&mut self, current_tab: CurrentTab) {
|
||||||
|
match current_tab {
|
||||||
|
CurrentTab::BondPopup => self.is_active = true,
|
||||||
|
_ => {
|
||||||
|
self.is_active = false;
|
||||||
|
self.amount = Input::new(String::new());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Component for BondPopup {
|
||||||
|
fn register_network_handler(&mut self, tx: Sender<Action>) -> Result<()> {
|
||||||
|
self.network_tx = Some(tx);
|
||||||
|
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<()> {
|
||||||
|
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_border_style(style.get("normal_border_style").copied());
|
||||||
|
self.palette.with_normal_title_style(style.get("normal_title_style").copied());
|
||||||
|
self.palette.with_popup_style(style.get("popup_style").copied());
|
||||||
|
self.palette.with_popup_title_style(style.get("popup_title_style").copied());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
||||||
|
if self.is_active && key.kind == KeyEventKind::Press {
|
||||||
|
match key.code {
|
||||||
|
KeyCode::Enter => self.submit_message(),
|
||||||
|
KeyCode::Char(to_insert) => self.enter_char(to_insert),
|
||||||
|
KeyCode::Backspace => self.delete_char(),
|
||||||
|
KeyCode::Left => self.move_cursor_left(),
|
||||||
|
KeyCode::Right => self.move_cursor_right(),
|
||||||
|
KeyCode::Esc => self.close_popup(),
|
||||||
|
_ => {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
|
match action {
|
||||||
|
Action::SetIsBonded(is_bonded, account_id) if self.account_id == account_id =>
|
||||||
|
self.is_bonded = is_bonded,
|
||||||
|
Action::UsedAccount(account_id, secret_seed) => self.update_used_account(account_id, secret_seed),
|
||||||
|
Action::SetMinValidatorBond(minimal_bond) => self.minimal_bond = minimal_bond,
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
|
if self.is_active {
|
||||||
|
let (border_style, border_type) = self.palette.create_popup_style();
|
||||||
|
let input = Paragraph::new(self.amount.value())
|
||||||
|
.block(Block::bordered()
|
||||||
|
.border_style(border_style)
|
||||||
|
.border_type(border_type)
|
||||||
|
.title_style(self.palette.create_popup_title_style())
|
||||||
|
.title_alignment(Alignment::Right)
|
||||||
|
.title(format!("Staking bond amount")));
|
||||||
|
let v = Layout::vertical([Constraint::Max(3)]).flex(Flex::Center);
|
||||||
|
let h = Layout::horizontal([Constraint::Max(50)]).flex(Flex::Center);
|
||||||
|
let [area] = v.areas(area);
|
||||||
|
let [area] = h.areas(area);
|
||||||
|
|
||||||
|
frame.render_widget(Clear, area);
|
||||||
|
frame.render_widget(input, area);
|
||||||
|
frame.set_cursor_position(Position::new(
|
||||||
|
area.x + self.amount.cursor() as u16 + 1,
|
||||||
|
area.y + 1
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
@ -113,7 +113,12 @@ impl CurrentValidatorDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PartialComponent for CurrentValidatorDetails {
|
impl PartialComponent for CurrentValidatorDetails {
|
||||||
fn set_active(&mut self, _current_tab: CurrentTab) {}
|
fn set_active(&mut self, current_tab: CurrentTab) {
|
||||||
|
match current_tab {
|
||||||
|
CurrentTab::CurrentValidatorsPopup => self.is_active = true,
|
||||||
|
_ => self.is_active = false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for CurrentValidatorDetails {
|
impl Component for CurrentValidatorDetails {
|
||||||
@ -123,7 +128,7 @@ impl Component for CurrentValidatorDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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::Nominator) {
|
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());
|
||||||
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());
|
||||||
@ -154,9 +159,9 @@ impl Component for CurrentValidatorDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
let [_, place] = super::validator_details_layout(area);
|
if self.is_active {
|
||||||
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 [_, place] = super::nominator_layout(area);
|
||||||
let table = Table::new(
|
let table = Table::new(
|
||||||
vec![
|
vec![
|
||||||
Row::new(vec![
|
Row::new(vec![
|
||||||
@ -211,6 +216,8 @@ impl Component for CurrentValidatorDetails {
|
|||||||
.title("Validator details"));
|
.title("Validator details"));
|
||||||
|
|
||||||
frame.render_widget(table, place);
|
frame.render_widget(table, place);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,6 +6,7 @@ use color_eyre::Result;
|
|||||||
use crossterm::event::{KeyCode, KeyEvent};
|
use crossterm::event::{KeyCode, KeyEvent};
|
||||||
use ratatui::layout::{Constraint, Margin};
|
use ratatui::layout::{Constraint, Margin};
|
||||||
use ratatui::style::{Stylize, Modifier};
|
use ratatui::style::{Stylize, Modifier};
|
||||||
|
use ratatui::widgets::Clear;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
text::Text,
|
text::Text,
|
||||||
layout::{Alignment, Rect},
|
layout::{Alignment, Rect},
|
||||||
@ -38,6 +39,8 @@ pub struct CurrentValidators {
|
|||||||
total_points: u32,
|
total_points: u32,
|
||||||
era_index: u32,
|
era_index: u32,
|
||||||
my_stash_id: Option<[u8; 32]>,
|
my_stash_id: Option<[u8; 32]>,
|
||||||
|
account_id: [u8; 32],
|
||||||
|
account_secret_seed: [u8; 32],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CurrentValidators {
|
impl Default for CurrentValidators {
|
||||||
@ -62,10 +65,37 @@ impl CurrentValidators {
|
|||||||
total_points: 0,
|
total_points: 0,
|
||||||
era_index: 0,
|
era_index: 0,
|
||||||
my_stash_id: None,
|
my_stash_id: None,
|
||||||
|
account_id: [0u8; 32],
|
||||||
|
account_secret_seed: [0u8; 32],
|
||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn close_popup(&mut self) {
|
||||||
|
self.is_active = false;
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_selected(&mut self, index: usize) {
|
||||||
|
if self.individual.len() > 0 {
|
||||||
|
self.table_state.select(Some(index));
|
||||||
|
self.scroll_state = self.scroll_state.position(index);
|
||||||
|
self.update_choosen_details(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_used_account(&mut self, account_id: [u8; 32], secret_seed_str: String) {
|
||||||
|
let secret_seed: [u8; 32] = hex::decode(secret_seed_str)
|
||||||
|
.expect("stored seed is valid hex string; qed")
|
||||||
|
.as_slice()
|
||||||
|
.try_into()
|
||||||
|
.expect("stored seed is valid length; qed");
|
||||||
|
self.account_id = account_id;
|
||||||
|
self.account_secret_seed = secret_seed;
|
||||||
|
}
|
||||||
|
|
||||||
fn update_choosen_details(&self, index: usize) {
|
fn update_choosen_details(&self, index: usize) {
|
||||||
if let Some(action_tx) = &self.action_tx {
|
if let Some(action_tx) = &self.action_tx {
|
||||||
let (selected_account_id, selected_points) = self.individual
|
let (selected_account_id, selected_points) = self.individual
|
||||||
@ -143,9 +173,7 @@ impl CurrentValidators {
|
|||||||
|
|
||||||
fn first_row(&mut self) {
|
fn first_row(&mut self) {
|
||||||
if self.individual.len() > 0 {
|
if self.individual.len() > 0 {
|
||||||
self.table_state.select(Some(0));
|
self.move_selected(0);
|
||||||
self.scroll_state = self.scroll_state.position(0);
|
|
||||||
self.update_choosen_details(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,17 +188,13 @@ impl CurrentValidators {
|
|||||||
},
|
},
|
||||||
None => 0,
|
None => 0,
|
||||||
};
|
};
|
||||||
self.table_state.select(Some(i));
|
self.move_selected(i);
|
||||||
self.scroll_state = self.scroll_state.position(i);
|
|
||||||
self.update_choosen_details(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn last_row(&mut self) {
|
fn last_row(&mut self) {
|
||||||
if self.individual.len() > 0 {
|
if self.individual.len() > 0 {
|
||||||
let last = self.individual.len() - 1;
|
let last = self.individual.len() - 1;
|
||||||
self.table_state.select(Some(last));
|
self.move_selected(last);
|
||||||
self.scroll_state = self.scroll_state.position(last);
|
|
||||||
self.update_choosen_details(last);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,9 +209,7 @@ impl CurrentValidators {
|
|||||||
},
|
},
|
||||||
None => 0
|
None => 0
|
||||||
};
|
};
|
||||||
self.table_state.select(Some(i));
|
self.move_selected(i);
|
||||||
self.scroll_state = self.scroll_state.position(i);
|
|
||||||
self.update_choosen_details(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_era_rewards(
|
fn update_era_rewards(
|
||||||
@ -207,9 +229,6 @@ impl CurrentValidators {
|
|||||||
.position(|item| item.account_id == account_id) {
|
.position(|item| item.account_id == account_id) {
|
||||||
self.individual.swap(0, index);
|
self.individual.swap(0, index);
|
||||||
}
|
}
|
||||||
let current_index = self.table_state.selected().unwrap_or_default();
|
|
||||||
self.table_state.select(Some(current_index));
|
|
||||||
self.update_choosen_details(current_index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +239,7 @@ impl CurrentValidators {
|
|||||||
impl PartialComponent for CurrentValidators {
|
impl PartialComponent for CurrentValidators {
|
||||||
fn set_active(&mut self, current_tab: CurrentTab) {
|
fn set_active(&mut self, current_tab: CurrentTab) {
|
||||||
match current_tab {
|
match current_tab {
|
||||||
CurrentTab::CurrentValidators => self.is_active = true,
|
CurrentTab::CurrentValidatorsPopup => self.is_active = true,
|
||||||
_ => self.is_active = false,
|
_ => self.is_active = false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,7 +252,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::Nominator) {
|
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());
|
||||||
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());
|
||||||
@ -253,6 +272,7 @@ impl Component for CurrentValidators {
|
|||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
match action {
|
match action {
|
||||||
Action::UpdateKnownValidator(validator_name) => self.save_validator_name(validator_name),
|
Action::UpdateKnownValidator(validator_name) => self.save_validator_name(validator_name),
|
||||||
|
Action::UsedAccount(account_id, secret_seed) => self.update_used_account(account_id, secret_seed),
|
||||||
Action::SetStashAccount(account_id) => self.my_stash_id = Some(account_id),
|
Action::SetStashAccount(account_id) => self.my_stash_id = Some(account_id),
|
||||||
Action::SetCurrentValidatorEraRewards(era_index, total_points, individual) =>
|
Action::SetCurrentValidatorEraRewards(era_index, total_points, individual) =>
|
||||||
self.update_era_rewards(era_index, total_points, &individual),
|
self.update_era_rewards(era_index, total_points, &individual),
|
||||||
@ -271,6 +291,7 @@ impl Component for CurrentValidators {
|
|||||||
KeyCode::Char('R') => self.update_known_validator_record(),
|
KeyCode::Char('R') => self.update_known_validator_record(),
|
||||||
KeyCode::Char('C') => self.clear_choosen(),
|
KeyCode::Char('C') => self.clear_choosen(),
|
||||||
KeyCode::Enter => self.flip_validator_check(),
|
KeyCode::Enter => self.flip_validator_check(),
|
||||||
|
KeyCode::Esc => self.close_popup(),
|
||||||
_ => {},
|
_ => {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -278,8 +299,9 @@ impl Component for CurrentValidators {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
let [place, _] = super::validator_details_layout(area);
|
if self.is_active {
|
||||||
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 [place, _] = super::nominator_layout(area);
|
||||||
let table = Table::new(
|
let table = Table::new(
|
||||||
self.individual
|
self.individual
|
||||||
.iter()
|
.iter()
|
||||||
@ -345,7 +367,7 @@ impl Component for CurrentValidators {
|
|||||||
.padding(Padding::right(2))
|
.padding(Padding::right(2))
|
||||||
.title_alignment(Alignment::Right)
|
.title_alignment(Alignment::Right)
|
||||||
.title_style(self.palette.create_title_style(false))
|
.title_style(self.palette.create_title_style(false))
|
||||||
.title(format!("Validators | Total points: {}", self.total_points)));
|
.title(format!("Validators {} | Total points: {}", self.individual.len(), self.total_points)));
|
||||||
|
|
||||||
let scrollbar = Scrollbar::default()
|
let scrollbar = Scrollbar::default()
|
||||||
.orientation(ScrollbarOrientation::VerticalRight)
|
.orientation(ScrollbarOrientation::VerticalRight)
|
||||||
@ -353,12 +375,14 @@ impl Component for CurrentValidators {
|
|||||||
.end_symbol(None)
|
.end_symbol(None)
|
||||||
.style(self.palette.create_scrollbar_style());
|
.style(self.palette.create_scrollbar_style());
|
||||||
|
|
||||||
|
frame.render_widget(Clear, place);
|
||||||
frame.render_stateful_widget(table, place, &mut self.table_state);
|
frame.render_stateful_widget(table, place, &mut self.table_state);
|
||||||
frame.render_stateful_widget(
|
frame.render_stateful_widget(
|
||||||
scrollbar,
|
scrollbar,
|
||||||
place.inner(Margin { vertical: 1, horizontal: 1 }),
|
place.inner(Margin { vertical: 1, horizontal: 1 }),
|
||||||
&mut self.scroll_state,
|
&mut self.scroll_state,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossterm::event::{KeyCode, KeyEvent};
|
use crossterm::event::{KeyCode, KeyEvent};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Constraint, Layout, Rect},
|
layout::{Constraint, Flex, Layout, Rect},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -18,8 +18,13 @@ mod accounts;
|
|||||||
mod overview;
|
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 account_details;
|
||||||
mod staking_ledger;
|
mod staking_ledger;
|
||||||
|
mod bond_popup;
|
||||||
|
mod payee_popup;
|
||||||
|
mod current_validators;
|
||||||
|
mod current_validator_details;
|
||||||
|
mod rename_known_validator;
|
||||||
|
|
||||||
use balance::Balance;
|
use balance::Balance;
|
||||||
use transfer::Transfer;
|
use transfer::Transfer;
|
||||||
@ -31,8 +36,13 @@ use accounts::Accounts;
|
|||||||
use overview::Overview;
|
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 account_details::AccountDetails;
|
||||||
use staking_ledger::StakingLedger;
|
use staking_ledger::StakingLedger;
|
||||||
|
use bond_popup::BondPopup;
|
||||||
|
use payee_popup::PayeePopup;
|
||||||
|
use current_validators::CurrentValidators;
|
||||||
|
use current_validator_details::CurrentValidatorDetails;
|
||||||
|
use rename_known_validator::RenameKnownValidator;
|
||||||
|
|
||||||
use super::Component;
|
use super::Component;
|
||||||
use crate::{action::Action, app::Mode, config::Config};
|
use crate::{action::Action, app::Mode, config::Config};
|
||||||
@ -49,6 +59,9 @@ pub enum CurrentTab {
|
|||||||
RenameAddressBookRecord,
|
RenameAddressBookRecord,
|
||||||
Transfer,
|
Transfer,
|
||||||
AccountDetails,
|
AccountDetails,
|
||||||
|
BondPopup,
|
||||||
|
PayeePopup,
|
||||||
|
CurrentValidatorsPopup,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PartialComponent: Component {
|
pub trait PartialComponent: Component {
|
||||||
@ -81,6 +94,11 @@ impl Default for Wallet {
|
|||||||
Box::new(RenameAddressBookRecord::default()),
|
Box::new(RenameAddressBookRecord::default()),
|
||||||
Box::new(Transfer::default()),
|
Box::new(Transfer::default()),
|
||||||
Box::new(AccountDetails::default()),
|
Box::new(AccountDetails::default()),
|
||||||
|
Box::new(BondPopup::default()),
|
||||||
|
Box::new(PayeePopup::default()),
|
||||||
|
Box::new(CurrentValidators::default()),
|
||||||
|
Box::new(CurrentValidatorDetails::default()),
|
||||||
|
Box::new(RenameKnownValidator::default()),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,61 +155,46 @@ impl Component for Wallet {
|
|||||||
CurrentTab::RenameAddressBookRecord |
|
CurrentTab::RenameAddressBookRecord |
|
||||||
CurrentTab::Transfer |
|
CurrentTab::Transfer |
|
||||||
CurrentTab::AccountDetails |
|
CurrentTab::AccountDetails |
|
||||||
CurrentTab::AddAddressBookRecord => match key.code {
|
CurrentTab::BondPopup |
|
||||||
KeyCode::Esc => {
|
CurrentTab::PayeePopup |
|
||||||
self.current_tab = self.previous_tab;
|
CurrentTab::CurrentValidatorsPopup |
|
||||||
for component in self.components.iter_mut() {
|
CurrentTab::AddAddressBookRecord => {
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
for component in self.components.iter_mut() {
|
for component in self.components.iter_mut() {
|
||||||
component.handle_key_event(key)?;
|
component.handle_key_event(key)?;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
_ => match key.code {
|
_ => match key.code {
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
self.is_active = false;
|
self.is_active = false;
|
||||||
self.current_tab = CurrentTab::Nothing;
|
self.current_tab = CurrentTab::Nothing;
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
return Ok(Some(Action::SetActiveScreen(Mode::Menu)));
|
return Ok(Some(Action::SetActiveScreen(Mode::Menu)));
|
||||||
},
|
},
|
||||||
KeyCode::Char('W') => {
|
KeyCode::Char('W') => {
|
||||||
self.previous_tab = self.current_tab;
|
self.previous_tab = self.current_tab;
|
||||||
self.current_tab = CurrentTab::AddAccount;
|
self.current_tab = CurrentTab::AddAccount;
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
KeyCode::Char('A') => {
|
KeyCode::Char('A') => {
|
||||||
self.previous_tab = self.current_tab;
|
self.previous_tab = self.current_tab;
|
||||||
self.current_tab = CurrentTab::AddAddressBookRecord;
|
self.current_tab = CurrentTab::AddAddressBookRecord;
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
KeyCode::Char('T') => {
|
KeyCode::Char('T') => {
|
||||||
self.previous_tab = self.current_tab;
|
self.previous_tab = self.current_tab;
|
||||||
self.current_tab = CurrentTab::Transfer;
|
self.current_tab = CurrentTab::Transfer;
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
KeyCode::Char('l') | KeyCode::Right => {
|
KeyCode::Char('B') => {
|
||||||
self.move_right();
|
self.previous_tab = self.current_tab;
|
||||||
for component in self.components.iter_mut() {
|
self.current_tab = CurrentTab::BondPopup;
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
KeyCode::Char('h') | KeyCode::Left => {
|
KeyCode::Char('I') => {
|
||||||
self.move_left();
|
self.previous_tab = self.current_tab;
|
||||||
for component in self.components.iter_mut() {
|
self.current_tab = CurrentTab::PayeePopup;
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
KeyCode::Char('N') => {
|
||||||
|
self.previous_tab = self.current_tab;
|
||||||
|
self.current_tab = CurrentTab::CurrentValidatorsPopup;
|
||||||
|
},
|
||||||
|
KeyCode::Char('l') | KeyCode::Right => self.move_right(),
|
||||||
|
KeyCode::Char('h') | KeyCode::Left => self.move_left(),
|
||||||
_ => {
|
_ => {
|
||||||
for component in self.components.iter_mut() {
|
for component in self.components.iter_mut() {
|
||||||
component.handle_key_event(key)?;
|
component.handle_key_event(key)?;
|
||||||
@ -209,14 +212,6 @@ impl Component for Wallet {
|
|||||||
self.current_tab = CurrentTab::Accounts;
|
self.current_tab = CurrentTab::Accounts;
|
||||||
self.previous_tab = CurrentTab::Accounts;
|
self.previous_tab = CurrentTab::Accounts;
|
||||||
},
|
},
|
||||||
Action::UpdateAccountName(_) | Action::NewAccount(_) => {
|
|
||||||
self.previous_tab = self.current_tab;
|
|
||||||
self.current_tab = CurrentTab::Accounts;
|
|
||||||
},
|
|
||||||
Action::UpdateAddressBookRecord(_) | Action::NewAddressBookRecord(_, _) | Action::ClosePopup => {
|
|
||||||
self.previous_tab = self.current_tab;
|
|
||||||
self.current_tab = CurrentTab::AddressBook;
|
|
||||||
},
|
|
||||||
Action::RenameAccount(_) => {
|
Action::RenameAccount(_) => {
|
||||||
self.previous_tab = self.current_tab;
|
self.previous_tab = self.current_tab;
|
||||||
self.current_tab = CurrentTab::RenameAccount;
|
self.current_tab = CurrentTab::RenameAccount;
|
||||||
@ -233,6 +228,7 @@ impl Component for Wallet {
|
|||||||
self.previous_tab = self.current_tab;
|
self.previous_tab = self.current_tab;
|
||||||
self.current_tab = CurrentTab::AccountDetails;
|
self.current_tab = CurrentTab::AccountDetails;
|
||||||
},
|
},
|
||||||
|
Action::ClosePopup => self.current_tab = self.previous_tab,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
for component in self.components.iter_mut() {
|
for component in self.components.iter_mut() {
|
||||||
@ -272,6 +268,15 @@ pub fn account_layout(area: Rect) -> [Rect; 4] {
|
|||||||
Constraint::Max(4),
|
Constraint::Max(4),
|
||||||
Constraint::Min(0),
|
Constraint::Min(0),
|
||||||
Constraint::Max(7),
|
Constraint::Max(7),
|
||||||
Constraint::Max(5),
|
Constraint::Max(6),
|
||||||
]).areas(place)
|
]).areas(place)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn nominator_layout(area: Rect) -> [Rect; 2] {
|
||||||
|
let v = Layout::vertical([Constraint::Max(11)]).flex(Flex::Center);
|
||||||
|
let [area] = v.areas(area);
|
||||||
|
Layout::horizontal([
|
||||||
|
Constraint::Percentage(60),
|
||||||
|
Constraint::Percentage(40),
|
||||||
|
]).areas(area)
|
||||||
|
}
|
||||||
|
374
src/components/wallet/payee_popup.rs
Normal file
374
src/components/wallet/payee_popup.rs
Normal file
@ -0,0 +1,374 @@
|
|||||||
|
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
|
||||||
|
use color_eyre::Result;
|
||||||
|
use ratatui::{
|
||||||
|
layout::{Alignment, Constraint, Flex, Layout, Position, Rect},
|
||||||
|
text::Text,
|
||||||
|
widgets::{Block, Cell, Clear, Paragraph, Row, Table, TableState},
|
||||||
|
Frame,
|
||||||
|
};
|
||||||
|
use subxt::ext::sp_core::crypto::{
|
||||||
|
ByteArray, Ss58Codec, Ss58AddressFormat, AccountId32,
|
||||||
|
};
|
||||||
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
use super::{Component, PartialComponent, CurrentTab};
|
||||||
|
use crate::{
|
||||||
|
action::Action,
|
||||||
|
config::Config,
|
||||||
|
palette::StylePalette,
|
||||||
|
types::{ActionLevel, ActionTarget, RewardDestination},
|
||||||
|
widgets::{Input, InputRequest},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct PayeePopup {
|
||||||
|
is_active: bool,
|
||||||
|
action_tx: Option<UnboundedSender<Action>>,
|
||||||
|
network_tx: Option<Sender<Action>>,
|
||||||
|
table_state: TableState,
|
||||||
|
account_secret_seed: [u8; 32],
|
||||||
|
account_id: [u8; 32],
|
||||||
|
proposed_account_id: Option<[u8; 32]>,
|
||||||
|
is_bonded: bool,
|
||||||
|
is_account_chosen: bool,
|
||||||
|
is_input_active: bool,
|
||||||
|
address: Input,
|
||||||
|
possible_payee_options: &'static [(&'static str, &'static str)],
|
||||||
|
current_reward_destination: RewardDestination,
|
||||||
|
palette: StylePalette
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PayeePopup {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PayeePopup {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
is_active: false,
|
||||||
|
account_secret_seed: [0u8; 32],
|
||||||
|
account_id: [0u8; 32],
|
||||||
|
proposed_account_id: None,
|
||||||
|
action_tx: None,
|
||||||
|
network_tx: None,
|
||||||
|
table_state: TableState::new(),
|
||||||
|
is_bonded: false,
|
||||||
|
is_account_chosen: false,
|
||||||
|
is_input_active: false,
|
||||||
|
address: Input::new(String::new()),
|
||||||
|
current_reward_destination: Default::default(),
|
||||||
|
possible_payee_options: &[
|
||||||
|
("Re-stake", "(pay into the stash account, increasing the amount at stake accordingly)"),
|
||||||
|
("Stake", "(pay into the stash account, not increasing the amount at stake)"),
|
||||||
|
("Account", "(pay into a specified account different from stash)"),
|
||||||
|
("None", "(refuse to receive all rewards from staking)"),
|
||||||
|
],
|
||||||
|
palette: StylePalette::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn close_popup(&mut self) {
|
||||||
|
self.is_active = false;
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_index_from_destination(&mut self) -> usize {
|
||||||
|
let (index, address) = match self.current_reward_destination {
|
||||||
|
RewardDestination::Staked => (0, Default::default()),
|
||||||
|
RewardDestination::Stash => (1, Default::default()),
|
||||||
|
RewardDestination::Account(account_id) => {
|
||||||
|
let address = AccountId32::from(account_id)
|
||||||
|
.to_ss58check_with_version(Ss58AddressFormat::custom(1996));
|
||||||
|
(2, address)
|
||||||
|
},
|
||||||
|
RewardDestination::None => (3, Default::default()),
|
||||||
|
_ => (0, Default::default()),
|
||||||
|
};
|
||||||
|
self.address = Input::new(address);
|
||||||
|
index
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_to_row(&mut self, index: usize) {
|
||||||
|
self.table_state.select(Some(index));
|
||||||
|
self.is_account_chosen = index == 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_row(&mut self) {
|
||||||
|
let i = match self.table_state.selected() {
|
||||||
|
Some(i) => {
|
||||||
|
if i >= self.possible_payee_options.len() - 1 {
|
||||||
|
i
|
||||||
|
} else {
|
||||||
|
i + 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => 0,
|
||||||
|
};
|
||||||
|
self.move_to_row(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn previous_row(&mut self) {
|
||||||
|
let i = match self.table_state.selected() {
|
||||||
|
Some(i) => {
|
||||||
|
if i == 0 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
i - 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => 0
|
||||||
|
};
|
||||||
|
self.move_to_row(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log_event(&mut self, message: String, level: ActionLevel) {
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::EventLog(
|
||||||
|
message,
|
||||||
|
level,
|
||||||
|
ActionTarget::WalletLog));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_used_account(&mut self, account_id: [u8; 32], secret_seed_str: String) {
|
||||||
|
let secret_seed: [u8; 32] = hex::decode(secret_seed_str)
|
||||||
|
.expect("stored seed is valid hex string; qed")
|
||||||
|
.as_slice()
|
||||||
|
.try_into()
|
||||||
|
.expect("stored seed is valid length; qed");
|
||||||
|
self.account_id = account_id;
|
||||||
|
self.account_secret_seed = secret_seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn trigger_address_input(&mut self) {
|
||||||
|
self.is_input_active = !self.is_input_active;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn submit_new_input(&mut self) {
|
||||||
|
match AccountId32::from_ss58check_with_version(self.address.value()) {
|
||||||
|
Ok((account_id, format)) => {
|
||||||
|
if format != Ss58AddressFormat::custom(1996) {
|
||||||
|
self.log_event(
|
||||||
|
format!("provided public address for {} is not part of Casper/Ghost ecosystem", self.address.value()),
|
||||||
|
ActionLevel::Error);
|
||||||
|
}
|
||||||
|
let seed_vec = account_id.to_raw_vec();
|
||||||
|
let mut account_id = [0u8; 32];
|
||||||
|
account_id.copy_from_slice(&seed_vec);
|
||||||
|
|
||||||
|
self.proposed_account_id = Some(account_id);
|
||||||
|
self.submit_new_payee();
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
self.log_event(
|
||||||
|
format!("could not create valid account id from {}", self.address.value()),
|
||||||
|
ActionLevel::Error);
|
||||||
|
self.proposed_account_id = None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn submit_new_payee(&mut self) {
|
||||||
|
if let Some(index) = self.table_state.selected() {
|
||||||
|
let new_destination = match index {
|
||||||
|
0 => RewardDestination::Staked,
|
||||||
|
1 => RewardDestination::Stash,
|
||||||
|
2 => {
|
||||||
|
let account_id = self.proposed_account_id
|
||||||
|
.expect("checked before in submit_new_input; qed");
|
||||||
|
RewardDestination::Account(account_id)
|
||||||
|
}
|
||||||
|
3 => RewardDestination::None,
|
||||||
|
_ => RewardDestination::Staked,
|
||||||
|
};
|
||||||
|
|
||||||
|
if !self.is_bonded {
|
||||||
|
self.log_event(
|
||||||
|
"no bond detected, stake minimum bond amount first".to_string(),
|
||||||
|
ActionLevel::Warn);
|
||||||
|
} else if new_destination == self.current_reward_destination {
|
||||||
|
self.log_event(
|
||||||
|
"same destination choosen, no need for transaction".to_string(),
|
||||||
|
ActionLevel::Warn);
|
||||||
|
} else {
|
||||||
|
if let Some(network_tx) = &self.network_tx {
|
||||||
|
let _ = network_tx.send(Action::SetPayee(
|
||||||
|
self.account_secret_seed,
|
||||||
|
new_destination,
|
||||||
|
ActionTarget::WalletLog));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enter_char(&mut self, new_char: char) {
|
||||||
|
let _ = self.address.handle(InputRequest::InsertChar(new_char));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_char(&mut self) {
|
||||||
|
let _ = self.address.handle(InputRequest::DeletePrevChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_cursor_right(&mut self) {
|
||||||
|
let _ = self.address.handle(InputRequest::GoToNextChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_cursor_left(&mut self) {
|
||||||
|
let _ = self.address.handle(InputRequest::GoToPrevChar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialComponent for PayeePopup {
|
||||||
|
fn set_active(&mut self, current_tab: CurrentTab) {
|
||||||
|
match current_tab {
|
||||||
|
CurrentTab::PayeePopup => self.is_active = true,
|
||||||
|
_ => {
|
||||||
|
self.is_active = false;
|
||||||
|
self.is_account_chosen = false;
|
||||||
|
self.is_input_active = false;
|
||||||
|
|
||||||
|
let index = self.parse_index_from_destination();
|
||||||
|
self.move_to_row(index);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Component for PayeePopup {
|
||||||
|
fn register_network_handler(&mut self, tx: Sender<Action>) -> Result<()> {
|
||||||
|
self.network_tx = Some(tx);
|
||||||
|
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<()> {
|
||||||
|
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_border_style(style.get("normal_border_style").copied());
|
||||||
|
self.palette.with_normal_title_style(style.get("normal_title_style").copied());
|
||||||
|
self.palette.with_popup_style(style.get("popup_style").copied());
|
||||||
|
self.palette.with_popup_title_style(style.get("popup_title_style").copied());
|
||||||
|
self.palette.with_highlight_style(style.get("highlight_style").copied());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
||||||
|
if self.is_active && key.kind == KeyEventKind::Press {
|
||||||
|
if self.is_input_active {
|
||||||
|
match key.code {
|
||||||
|
KeyCode::Enter => self.submit_new_input(),
|
||||||
|
KeyCode::Char(to_insert) => self.enter_char(to_insert),
|
||||||
|
KeyCode::Backspace => self.delete_char(),
|
||||||
|
KeyCode::Left => self.move_cursor_left(),
|
||||||
|
KeyCode::Right => self.move_cursor_right(),
|
||||||
|
KeyCode::Esc => self.trigger_address_input(),
|
||||||
|
_ => {},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
match key.code {
|
||||||
|
KeyCode::Enter if !self.is_account_chosen => self.submit_new_payee(),
|
||||||
|
KeyCode::Enter if self.is_account_chosen => self.trigger_address_input(),
|
||||||
|
KeyCode::Up | KeyCode::Char('k') => self.previous_row(),
|
||||||
|
KeyCode::Down | KeyCode::Char('j') => self.next_row(),
|
||||||
|
KeyCode::Esc => self.close_popup(),
|
||||||
|
_ => {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
|
match action {
|
||||||
|
Action::UsedAccount(account_id, secret_seed) => self.update_used_account(account_id, secret_seed),
|
||||||
|
Action::SetIsBonded(is_bonded, account_id) if self.account_id == account_id =>
|
||||||
|
self.is_bonded = is_bonded,
|
||||||
|
Action::SetStakingPayee(reward_destination, account_id) if self.account_id == account_id => {
|
||||||
|
let destination_changed = self.current_reward_destination != reward_destination;
|
||||||
|
self.current_reward_destination = reward_destination;
|
||||||
|
if destination_changed || self.table_state.selected().is_none() {
|
||||||
|
let index = self.parse_index_from_destination();
|
||||||
|
self.move_to_row(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
|
if self.is_active {
|
||||||
|
let (border_style, border_type) = self.palette.create_popup_style();
|
||||||
|
let size = area.as_size();
|
||||||
|
let input_area = Rect::new(size.width / 2, size.height / 2, 51, 3);
|
||||||
|
|
||||||
|
let table = Table::new(
|
||||||
|
self.possible_payee_options
|
||||||
|
.iter()
|
||||||
|
.map(|data| {
|
||||||
|
Row::new(vec![
|
||||||
|
Cell::from(Text::from(data.0.to_string()).alignment(Alignment::Left)),
|
||||||
|
Cell::from(Text::from(data.1.to_string()).alignment(Alignment::Left)),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
[Constraint::Length(8), Constraint::Min(0)]
|
||||||
|
)
|
||||||
|
.highlight_style(self.palette.create_highlight_style())
|
||||||
|
.column_spacing(1)
|
||||||
|
.block(Block::bordered()
|
||||||
|
.border_style(border_style)
|
||||||
|
.border_type(border_type)
|
||||||
|
.title_style(self.palette.create_popup_title_style())
|
||||||
|
.title_alignment(Alignment::Right)
|
||||||
|
.title("Select reward destination"));
|
||||||
|
|
||||||
|
let v = Layout::vertical([Constraint::Max(6)]).flex(Flex::Center);
|
||||||
|
let h = Layout::horizontal([Constraint::Max(83)]).flex(Flex::Center);
|
||||||
|
let [area] = v.areas(area);
|
||||||
|
let [area] = h.areas(area);
|
||||||
|
|
||||||
|
frame.render_widget(Clear, area);
|
||||||
|
frame.render_stateful_widget(table, area, &mut self.table_state);
|
||||||
|
|
||||||
|
if self.is_input_active {
|
||||||
|
let input_amount = Paragraph::new(self.address.value())
|
||||||
|
.block(Block::bordered()
|
||||||
|
.border_style(border_style)
|
||||||
|
.border_type(border_type)
|
||||||
|
.title_style(self.palette.create_popup_title_style())
|
||||||
|
.title_alignment(Alignment::Right)
|
||||||
|
.title("Destination account"));
|
||||||
|
|
||||||
|
let v = Layout::vertical([Constraint::Max(8)]).flex(Flex::Center);
|
||||||
|
let h = Layout::horizontal([Constraint::Max(51)]).flex(Flex::Center);
|
||||||
|
let [input_area] = v.areas(input_area);
|
||||||
|
let [input_area] = h.areas(input_area);
|
||||||
|
|
||||||
|
frame.render_widget(Clear, input_area);
|
||||||
|
frame.render_widget(input_amount, input_area);
|
||||||
|
|
||||||
|
frame.set_cursor_position(Position::new(
|
||||||
|
input_area.x + self.address.cursor() as u16 + 1,
|
||||||
|
input_area.y + 1
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
@ -40,12 +40,19 @@ impl RenameAccount {
|
|||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl RenameAccount {
|
fn close_popup(&mut self) {
|
||||||
|
self.is_active = false;
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn submit_message(&mut self) {
|
fn submit_message(&mut self) {
|
||||||
if let Some(action_tx) = &self.action_tx {
|
if let Some(action_tx) = &self.action_tx {
|
||||||
let _ = action_tx.send(Action::UpdateAccountName(self.name.value().to_string()));
|
let _ = action_tx.send(Action::UpdateAccountName(
|
||||||
|
self.name.value().to_string()));
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +119,7 @@ impl Component for RenameAccount {
|
|||||||
KeyCode::Backspace => self.delete_char(),
|
KeyCode::Backspace => self.delete_char(),
|
||||||
KeyCode::Left => self.move_cursor_left(),
|
KeyCode::Left => self.move_cursor_left(),
|
||||||
KeyCode::Right => self.move_cursor_right(),
|
KeyCode::Right => self.move_cursor_right(),
|
||||||
KeyCode::Esc => self.is_active = false,
|
KeyCode::Esc => self.close_popup(),
|
||||||
_ => {},
|
_ => {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -40,13 +40,19 @@ impl RenameAddressBookRecord {
|
|||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl RenameAddressBookRecord {
|
fn close_popup(&mut self) {
|
||||||
|
self.is_active = false;
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn submit_message(&mut self) {
|
fn submit_message(&mut self) {
|
||||||
if let Some(action_tx) = &self.action_tx {
|
if let Some(action_tx) = &self.action_tx {
|
||||||
let _ = action_tx.send(Action::UpdateAddressBookRecord(
|
let _ = action_tx.send(Action::UpdateAddressBookRecord(
|
||||||
self.name.value().to_string()));
|
self.name.value().to_string()));
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +119,7 @@ impl Component for RenameAddressBookRecord {
|
|||||||
KeyCode::Backspace => self.delete_char(),
|
KeyCode::Backspace => self.delete_char(),
|
||||||
KeyCode::Left => self.move_cursor_left(),
|
KeyCode::Left => self.move_cursor_left(),
|
||||||
KeyCode::Right => self.move_cursor_right(),
|
KeyCode::Right => self.move_cursor_right(),
|
||||||
KeyCode::Esc => self.is_active = false,
|
KeyCode::Esc => self.close_popup(),
|
||||||
_ => {},
|
_ => {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -38,14 +38,18 @@ impl RenameKnownValidator {
|
|||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl RenameKnownValidator {
|
fn close_popup(&mut self) {
|
||||||
|
self.is_active = false;
|
||||||
|
self.name = Input::new(String::new());
|
||||||
|
}
|
||||||
|
|
||||||
fn submit_message(&mut self) {
|
fn submit_message(&mut self) {
|
||||||
if let Some(action_tx) = &self.action_tx {
|
if let Some(action_tx) = &self.action_tx {
|
||||||
let _ = action_tx.send(Action::UpdateKnownValidator(
|
let _ = action_tx.send(Action::UpdateKnownValidator(
|
||||||
self.name.value().to_string()));
|
self.name.value().to_string()));
|
||||||
}
|
}
|
||||||
|
self.close_popup();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enter_char(&mut self, new_char: char) {
|
fn enter_char(&mut self, new_char: char) {
|
||||||
@ -66,15 +70,7 @@ impl RenameKnownValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PartialComponent for RenameKnownValidator {
|
impl PartialComponent for RenameKnownValidator {
|
||||||
fn set_active(&mut self, current_tab: CurrentTab) {
|
fn set_active(&mut self, _current_tab: CurrentTab) { }
|
||||||
match current_tab {
|
|
||||||
CurrentTab::RenameKnownValidator => self.is_active = true,
|
|
||||||
_ => {
|
|
||||||
self.is_active = false;
|
|
||||||
self.name = Input::new(String::new());
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for RenameKnownValidator {
|
impl Component for RenameKnownValidator {
|
||||||
@ -83,8 +79,16 @@ impl Component for RenameKnownValidator {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
|
match action {
|
||||||
|
Action::RenameKnownValidatorRecord => self.is_active = true,
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
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::Nominator) {
|
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());
|
||||||
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());
|
||||||
@ -102,7 +106,7 @@ impl Component for RenameKnownValidator {
|
|||||||
KeyCode::Backspace => self.delete_char(),
|
KeyCode::Backspace => self.delete_char(),
|
||||||
KeyCode::Left => self.move_cursor_left(),
|
KeyCode::Left => self.move_cursor_left(),
|
||||||
KeyCode::Right => self.move_cursor_right(),
|
KeyCode::Right => self.move_cursor_right(),
|
||||||
KeyCode::Esc => self.is_active = false,
|
KeyCode::Esc => self.close_popup(),
|
||||||
_ => {},
|
_ => {},
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -5,14 +5,13 @@ use ratatui::{
|
|||||||
widgets::{Block, Cell, Row, Table},
|
widgets::{Block, Cell, Row, Table},
|
||||||
Frame
|
Frame
|
||||||
};
|
};
|
||||||
|
use subxt::ext::sp_core::crypto::{Ss58Codec, Ss58AddressFormat, AccountId32};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
use super::{Component, PartialComponent, CurrentTab};
|
use super::{Component, PartialComponent, CurrentTab};
|
||||||
use crate::{
|
use crate::{
|
||||||
widgets::DotSpinner,
|
action::Action, config::Config, palette::StylePalette,
|
||||||
action::Action,
|
types::RewardDestination, widgets::DotSpinner,
|
||||||
config::Config,
|
|
||||||
palette::StylePalette,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -23,6 +22,7 @@ pub struct StakingLedger {
|
|||||||
network_tx: Option<Sender<Action>>,
|
network_tx: Option<Sender<Action>>,
|
||||||
total_staked: Option<u128>,
|
total_staked: Option<u128>,
|
||||||
active_staked: Option<u128>,
|
active_staked: Option<u128>,
|
||||||
|
reward_destination: RewardDestination,
|
||||||
palette: StylePalette
|
palette: StylePalette
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +44,7 @@ impl StakingLedger {
|
|||||||
network_tx: None,
|
network_tx: None,
|
||||||
total_staked: None,
|
total_staked: None,
|
||||||
active_staked: None,
|
active_staked: None,
|
||||||
|
reward_destination: Default::default(),
|
||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,6 +53,7 @@ impl StakingLedger {
|
|||||||
self.account_id = account_id;
|
self.account_id = account_id;
|
||||||
if let Some(network_tx) = &self.network_tx {
|
if let Some(network_tx) = &self.network_tx {
|
||||||
let _ = network_tx.send(Action::GetValidatorLedger(account_id, false));
|
let _ = network_tx.send(Action::GetValidatorLedger(account_id, false));
|
||||||
|
let _ = network_tx.send(Action::GetStakingPayee(account_id, false));
|
||||||
let _ = network_tx.send(Action::GetIsStashBonded(account_id, false));
|
let _ = network_tx.send(Action::GetIsStashBonded(account_id, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,6 +69,21 @@ impl StakingLedger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_reward_destination(&self) -> String {
|
||||||
|
match self.reward_destination {
|
||||||
|
RewardDestination::Staked => "re-stake".to_string(),
|
||||||
|
RewardDestination::Stash => "stake".to_string(),
|
||||||
|
RewardDestination::Controller => "controller".to_string(),
|
||||||
|
RewardDestination::None => "none".to_string(),
|
||||||
|
RewardDestination::Account(account_id) => {
|
||||||
|
let address = AccountId32::from(account_id)
|
||||||
|
.to_ss58check_with_version(Ss58AddressFormat::custom(1996));
|
||||||
|
let tail = address.len().saturating_sub(5);
|
||||||
|
format!("{}..{}", &address[..5], &address[tail..])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn is_bonded_to_string(&self) -> String {
|
fn is_bonded_to_string(&self) -> String {
|
||||||
if self.is_bonded {
|
if self.is_bonded {
|
||||||
"bonded".to_string()
|
"bonded".to_string()
|
||||||
@ -106,7 +123,10 @@ impl Component for StakingLedger {
|
|||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
match action {
|
match action {
|
||||||
Action::UsedAccount(account_id, _) => self.set_used_account_id(account_id),
|
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::SetIsBonded(is_bonded, account_id) if self.account_id == account_id =>
|
||||||
|
self.is_bonded = is_bonded,
|
||||||
|
Action::SetStakingPayee(reward_destination, account_id) if self.account_id == account_id =>
|
||||||
|
self.reward_destination = reward_destination,
|
||||||
Action::SetStakedAmountRatio(total, active, account_id) if self.account_id == account_id => {
|
Action::SetStakedAmountRatio(total, active, account_id) if self.account_id == account_id => {
|
||||||
self.total_staked = total;
|
self.total_staked = total;
|
||||||
self.active_staked = active;
|
self.active_staked = active;
|
||||||
@ -124,20 +144,24 @@ impl Component for StakingLedger {
|
|||||||
let table = Table::new(
|
let table = Table::new(
|
||||||
[
|
[
|
||||||
Row::new(vec![
|
Row::new(vec![
|
||||||
Cell::from(Text::from("Bond ready: ".to_string()).alignment(Alignment::Left)),
|
Cell::from(Text::from("bond ready:".to_string()).alignment(Alignment::Left)),
|
||||||
Cell::from(Text::from(self.is_bonded_to_string()).alignment(Alignment::Right)),
|
Cell::from(Text::from(self.is_bonded_to_string()).alignment(Alignment::Right)),
|
||||||
]),
|
]),
|
||||||
Row::new(vec![
|
Row::new(vec![
|
||||||
Cell::from(Text::from("total: ".to_string()).alignment(Alignment::Left)),
|
Cell::from(Text::from("destination:".to_string()).alignment(Alignment::Left)),
|
||||||
|
Cell::from(Text::from(self.get_reward_destination()).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))
|
Cell::from(Text::from(self.prepare_u128(self.total_staked)).alignment(Alignment::Right))
|
||||||
]),
|
]),
|
||||||
Row::new(vec![
|
Row::new(vec![
|
||||||
Cell::from(Text::from("active: ".to_string()).alignment(Alignment::Left)),
|
Cell::from(Text::from("active:".to_string()).alignment(Alignment::Left)),
|
||||||
Cell::from(Text::from(self.prepare_u128(self.active_staked)).alignment(Alignment::Right)),
|
Cell::from(Text::from(self.prepare_u128(self.active_staked)).alignment(Alignment::Right)),
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
Constraint::Max(10),
|
Constraint::Max(12),
|
||||||
Constraint::Min(14),
|
Constraint::Min(14),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -59,6 +59,13 @@ impl Transfer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn close_popup(&mut self) {
|
||||||
|
self.is_active = false;
|
||||||
|
if let Some(action_tx) = &self.action_tx {
|
||||||
|
let _ = action_tx.send(Action::ClosePopup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn log_event(&mut self, message: String, level: ActionLevel) {
|
fn log_event(&mut self, message: String, level: ActionLevel) {
|
||||||
if let Some(action_tx) = &self.action_tx {
|
if let Some(action_tx) = &self.action_tx {
|
||||||
let _ = action_tx.send(
|
let _ = action_tx.send(
|
||||||
@ -206,7 +213,7 @@ impl Component for Transfer {
|
|||||||
KeyCode::Backspace => self.delete_char(),
|
KeyCode::Backspace => self.delete_char(),
|
||||||
KeyCode::Left => self.move_cursor_left(),
|
KeyCode::Left => self.move_cursor_left(),
|
||||||
KeyCode::Right => self.move_cursor_right(),
|
KeyCode::Right => self.move_cursor_right(),
|
||||||
KeyCode::Esc => self.is_active = false,
|
KeyCode::Esc => self.close_popup(),
|
||||||
_ => {},
|
_ => {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,7 @@ impl Network {
|
|||||||
predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||||
predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||||
predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||||
|
predefined_calls::get_account_payee(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||||
predefined_calls::get_slashing_spans(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
predefined_calls::get_slashing_spans(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||||
|
|
||||||
for era_index in self.eras_to_watch.iter() {
|
for era_index in self.eras_to_watch.iter() {
|
||||||
@ -128,6 +129,7 @@ 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_account_payee(&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_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?;
|
predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
|
||||||
}
|
}
|
||||||
@ -208,6 +210,10 @@ impl Network {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Action::GetStakingPayee(account_id, is_stash) => {
|
||||||
|
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||||
|
predefined_calls::get_account_payee(&self.action_tx, &self.online_client_api, &account_id).await
|
||||||
|
}
|
||||||
Action::GetValidatorLatestClaim(account_id, is_stash) => {
|
Action::GetValidatorLatestClaim(account_id, is_stash) => {
|
||||||
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||||
predefined_calls::get_validator_latest_claim(&self.action_tx, &self.online_client_api, &account_id).await
|
predefined_calls::get_validator_latest_claim(&self.action_tx, &self.online_client_api, &account_id).await
|
||||||
@ -283,7 +289,7 @@ impl Network {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Action::BondValidatorExtraFrom(sender, amount) => {
|
Action::BondValidatorExtraFrom(sender, amount, log_target) => {
|
||||||
let sender_str = hex::encode(sender);
|
let sender_str = hex::encode(sender);
|
||||||
let maybe_nonce = self.senders.get_mut(&sender_str);
|
let maybe_nonce = self.senders.get_mut(&sender_str);
|
||||||
|
|
||||||
@ -293,16 +299,17 @@ impl Network {
|
|||||||
&sender,
|
&sender,
|
||||||
&amount,
|
&amount,
|
||||||
maybe_nonce,
|
maybe_nonce,
|
||||||
|
log_target,
|
||||||
).await {
|
).await {
|
||||||
self.transactions_to_watch.push(TxToWatch {
|
self.transactions_to_watch.push(TxToWatch {
|
||||||
tx_progress,
|
tx_progress,
|
||||||
sender: sender_str,
|
sender: sender_str,
|
||||||
target: ActionTarget::ValidatorLog,
|
target: log_target,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Action::BondValidatorFrom(sender, amount) => {
|
Action::BondValidatorFrom(sender, amount, log_target) => {
|
||||||
let sender_str = hex::encode(sender);
|
let sender_str = hex::encode(sender);
|
||||||
let maybe_nonce = self.senders.get_mut(&sender_str);
|
let maybe_nonce = self.senders.get_mut(&sender_str);
|
||||||
if let Ok(tx_progress) = predefined_txs::bond(
|
if let Ok(tx_progress) = predefined_txs::bond(
|
||||||
@ -311,11 +318,12 @@ impl Network {
|
|||||||
&sender,
|
&sender,
|
||||||
&amount,
|
&amount,
|
||||||
maybe_nonce,
|
maybe_nonce,
|
||||||
|
log_target,
|
||||||
).await {
|
).await {
|
||||||
self.transactions_to_watch.push(TxToWatch {
|
self.transactions_to_watch.push(TxToWatch {
|
||||||
tx_progress,
|
tx_progress,
|
||||||
sender: sender_str,
|
sender: sender_str,
|
||||||
target: ActionTarget::ValidatorLog,
|
target: log_target,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -447,6 +455,25 @@ impl Network {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Action::SetPayee(sender, reward_destination, log_target) => {
|
||||||
|
let sender_str = hex::encode(sender);
|
||||||
|
let maybe_nonce = self.senders.get_mut(&sender_str);
|
||||||
|
if let Ok(tx_progress) = predefined_txs::set_payee(
|
||||||
|
&self.action_tx,
|
||||||
|
&self.online_client_api,
|
||||||
|
&sender,
|
||||||
|
reward_destination,
|
||||||
|
maybe_nonce,
|
||||||
|
log_target,
|
||||||
|
).await {
|
||||||
|
self.transactions_to_watch.push(TxToWatch {
|
||||||
|
tx_progress,
|
||||||
|
sender: sender_str,
|
||||||
|
target: log_target,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
_ => Ok(())
|
_ => Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ use subxt::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
action::Action,
|
action::Action,
|
||||||
casper_network::runtime_types::sp_consensus_slots,
|
casper_network::runtime_types::{pallet_staking::RewardDestination, sp_consensus_slots},
|
||||||
types::{EraInfo, EraRewardPoints, Nominator, SessionKeyInfo, UnlockChunk, SystemAccount},
|
types::{EraInfo, EraRewardPoints, Nominator, SessionKeyInfo, SystemAccount, UnlockChunk},
|
||||||
CasperAccountId, CasperConfig
|
CasperAccountId, CasperConfig
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -581,3 +581,22 @@ pub async fn get_validator_latest_claim(
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_account_payee(
|
||||||
|
action_tx: &UnboundedSender<Action>,
|
||||||
|
api: &OnlineClient<CasperConfig>,
|
||||||
|
account_id: &[u8; 32],
|
||||||
|
) -> Result<()> {
|
||||||
|
let payee = super::raw_calls::staking::payee(api, None, account_id)
|
||||||
|
.await?
|
||||||
|
.map(|payee| match payee {
|
||||||
|
RewardDestination::Stash => crate::types::RewardDestination::Stash,
|
||||||
|
RewardDestination::Staked => crate::types::RewardDestination::Staked,
|
||||||
|
RewardDestination::Account(account_id_32) => crate::types::RewardDestination::Account(account_id_32.0),
|
||||||
|
RewardDestination::Controller => crate::types::RewardDestination::Controller,
|
||||||
|
RewardDestination::None => crate::types::RewardDestination::None,
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
action_tx.send(Action::SetStakingPayee(payee, *account_id))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
@ -10,7 +10,7 @@ use crate::{
|
|||||||
action::Action,
|
action::Action,
|
||||||
casper::{CasperConfig, CasperExtrinsicParamsBuilder},
|
casper::{CasperConfig, CasperExtrinsicParamsBuilder},
|
||||||
casper_network::{self, runtime_types},
|
casper_network::{self, runtime_types},
|
||||||
types::{ActionLevel, ActionTarget},
|
types::{ActionLevel, ActionTarget, RewardDestination},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn transfer_balance(
|
pub async fn transfer_balance(
|
||||||
@ -40,6 +40,7 @@ pub async fn bond_extra(
|
|||||||
sender: &[u8; 32],
|
sender: &[u8; 32],
|
||||||
amount: &u128,
|
amount: &u128,
|
||||||
maybe_nonce: Option<&mut u32>,
|
maybe_nonce: Option<&mut u32>,
|
||||||
|
log_target: ActionTarget,
|
||||||
) -> Result<TxProgress<CasperConfig, OnlineClient<CasperConfig>>> {
|
) -> Result<TxProgress<CasperConfig, OnlineClient<CasperConfig>>> {
|
||||||
let bond_extra_tx = casper_network::tx().staking().bond_extra(*amount);
|
let bond_extra_tx = casper_network::tx().staking().bond_extra(*amount);
|
||||||
inner_sign_and_submit_then_watch(
|
inner_sign_and_submit_then_watch(
|
||||||
@ -49,7 +50,7 @@ pub async fn bond_extra(
|
|||||||
maybe_nonce,
|
maybe_nonce,
|
||||||
Box::new(bond_extra_tx),
|
Box::new(bond_extra_tx),
|
||||||
"bond extra",
|
"bond extra",
|
||||||
ActionTarget::ValidatorLog,
|
log_target,
|
||||||
).await
|
).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ pub async fn bond(
|
|||||||
sender: &[u8; 32],
|
sender: &[u8; 32],
|
||||||
amount: &u128,
|
amount: &u128,
|
||||||
maybe_nonce: Option<&mut u32>,
|
maybe_nonce: Option<&mut u32>,
|
||||||
|
log_target: ActionTarget,
|
||||||
) -> Result<TxProgress<CasperConfig, OnlineClient<CasperConfig>>> {
|
) -> Result<TxProgress<CasperConfig, OnlineClient<CasperConfig>>> {
|
||||||
// auto-stake everything by now
|
// auto-stake everything by now
|
||||||
let reward_destination = casper_network::runtime_types::pallet_staking::RewardDestination::Staked;
|
let reward_destination = casper_network::runtime_types::pallet_staking::RewardDestination::Staked;
|
||||||
@ -70,7 +72,7 @@ pub async fn bond(
|
|||||||
maybe_nonce,
|
maybe_nonce,
|
||||||
Box::new(bond_tx),
|
Box::new(bond_tx),
|
||||||
"bond",
|
"bond",
|
||||||
ActionTarget::ValidatorLog,
|
log_target,
|
||||||
).await
|
).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,6 +231,36 @@ pub async fn withdraw_unbonded(
|
|||||||
).await
|
).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn set_payee(
|
||||||
|
action_tx: &UnboundedSender<Action>,
|
||||||
|
api: &OnlineClient<CasperConfig>,
|
||||||
|
sender: &[u8; 32],
|
||||||
|
reward_destination: RewardDestination,
|
||||||
|
maybe_nonce: Option<&mut u32>,
|
||||||
|
log_target: ActionTarget,
|
||||||
|
) -> Result<TxProgress<CasperConfig, OnlineClient<CasperConfig>>> {
|
||||||
|
let reward_destination = match reward_destination {
|
||||||
|
RewardDestination::Staked => casper_network::runtime_types::pallet_staking::RewardDestination::Staked,
|
||||||
|
RewardDestination::Stash => casper_network::runtime_types::pallet_staking::RewardDestination::Stash,
|
||||||
|
RewardDestination::Controller => casper_network::runtime_types::pallet_staking::RewardDestination::Controller,
|
||||||
|
RewardDestination::None => casper_network::runtime_types::pallet_staking::RewardDestination::None,
|
||||||
|
RewardDestination::Account(account) => {
|
||||||
|
let account_id = subxt::utils::AccountId32::from(account);
|
||||||
|
casper_network::runtime_types::pallet_staking::RewardDestination::Account(account_id)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let set_payee_tx = casper_network::tx().staking().set_payee(reward_destination);
|
||||||
|
inner_sign_and_submit_then_watch(
|
||||||
|
action_tx,
|
||||||
|
api,
|
||||||
|
sender,
|
||||||
|
maybe_nonce,
|
||||||
|
Box::new(set_payee_tx),
|
||||||
|
"set payee",
|
||||||
|
log_target,
|
||||||
|
).await
|
||||||
|
}
|
||||||
|
|
||||||
async fn inner_sign_and_submit_then_watch(
|
async fn inner_sign_and_submit_then_watch(
|
||||||
action_tx: &UnboundedSender<Action>,
|
action_tx: &UnboundedSender<Action>,
|
||||||
api: &OnlineClient<CasperConfig>,
|
api: &OnlineClient<CasperConfig>,
|
||||||
|
@ -9,8 +9,7 @@ use crate::{
|
|||||||
self,
|
self,
|
||||||
runtime_types::{
|
runtime_types::{
|
||||||
pallet_staking::{
|
pallet_staking::{
|
||||||
slashing::SlashingSpans, ActiveEraInfo, EraRewardPoints,
|
slashing::SlashingSpans, ActiveEraInfo, EraRewardPoints, RewardDestination, StakingLedger, ValidatorPrefs
|
||||||
StakingLedger, ValidatorPrefs,
|
|
||||||
},
|
},
|
||||||
sp_arithmetic::per_things::Perbill,
|
sp_arithmetic::per_things::Perbill,
|
||||||
sp_staking::{Exposure, PagedExposureMetadata},
|
sp_staking::{Exposure, PagedExposureMetadata},
|
||||||
@ -195,6 +194,17 @@ pub async fn slashing_spans(
|
|||||||
Ok(maybe_slashing_spans)
|
Ok(maybe_slashing_spans)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn payee(
|
||||||
|
online_client: &OnlineClient<CasperConfig>,
|
||||||
|
at_hash: Option<&H256>,
|
||||||
|
account: &[u8; 32],
|
||||||
|
) -> Result<Option<RewardDestination<AccountId32>>> {
|
||||||
|
let account_id = super::convert_array_to_account_id(account);
|
||||||
|
let storage_key = casper_network::storage().staking().payee(account_id);
|
||||||
|
let maybe_payee = super::do_storage_call(online_client, &storage_key, at_hash).await?;
|
||||||
|
Ok(maybe_payee)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn history_depth(
|
pub fn history_depth(
|
||||||
online_client: &OnlineClient<CasperConfig>,
|
online_client: &OnlineClient<CasperConfig>,
|
||||||
) -> Result<u32> {
|
) -> Result<u32> {
|
||||||
|
@ -9,7 +9,7 @@ pub enum ActionLevel {
|
|||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Display, Serialize, Deserialize)]
|
||||||
pub enum ActionTarget {
|
pub enum ActionTarget {
|
||||||
#[default]
|
#[default]
|
||||||
WalletLog,
|
WalletLog,
|
||||||
|
@ -16,3 +16,4 @@ pub use peer::PeerInformation;
|
|||||||
pub use session::SessionKeyInfo;
|
pub use session::SessionKeyInfo;
|
||||||
pub use nominator::Nominator;
|
pub use nominator::Nominator;
|
||||||
pub use staking::UnlockChunk;
|
pub use staking::UnlockChunk;
|
||||||
|
pub use staking::RewardDestination;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
|
use strum::Display;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, Decode)]
|
||||||
@ -6,3 +7,13 @@ pub struct UnlockChunk {
|
|||||||
pub value: u128,
|
pub value: u128,
|
||||||
pub era: u32,
|
pub era: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
|
||||||
|
pub enum RewardDestination {
|
||||||
|
#[default]
|
||||||
|
None,
|
||||||
|
Staked,
|
||||||
|
Stash,
|
||||||
|
Account([u8; 32]),
|
||||||
|
Controller,
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user