fixing payout action and add pending state
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
a24a35aa51
commit
ddc598a8a4
@ -35,7 +35,7 @@ pub enum Action {
|
|||||||
|
|
||||||
ClosePopup,
|
ClosePopup,
|
||||||
RotateSessionKeys,
|
RotateSessionKeys,
|
||||||
PayoutValidatorPopup(u32, bool),
|
PayoutValidatorPopup(u32),
|
||||||
WithdrawValidatorPopup,
|
WithdrawValidatorPopup,
|
||||||
|
|
||||||
BalanceRequest([u8; 32], bool),
|
BalanceRequest([u8; 32], bool),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::{HashSet, BTreeMap};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
@ -18,6 +18,7 @@ use ratatui::{
|
|||||||
use tokio::sync::mpsc::UnboundedSender;
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
|
||||||
use super::{PartialComponent, Component, CurrentTab};
|
use super::{PartialComponent, Component, CurrentTab};
|
||||||
|
use crate::types::{ActionLevel, ActionTarget};
|
||||||
use crate::{
|
use crate::{
|
||||||
action::Action,
|
action::Action,
|
||||||
config::Config,
|
config::Config,
|
||||||
@ -38,6 +39,7 @@ pub struct History {
|
|||||||
scroll_state: ScrollbarState,
|
scroll_state: ScrollbarState,
|
||||||
table_state: TableState,
|
table_state: TableState,
|
||||||
rewards: BTreeMap<u32, EraStakingInfo>,
|
rewards: BTreeMap<u32, EraStakingInfo>,
|
||||||
|
pending_payout: HashSet<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for History {
|
impl Default for History {
|
||||||
@ -57,7 +59,8 @@ impl History {
|
|||||||
action_tx: None,
|
action_tx: None,
|
||||||
scroll_state: ScrollbarState::new(0),
|
scroll_state: ScrollbarState::new(0),
|
||||||
table_state: TableState::new(),
|
table_state: TableState::new(),
|
||||||
rewards: BTreeMap::new(),
|
rewards: Default::default(),
|
||||||
|
pending_payout: Default::default(),
|
||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,8 +76,22 @@ impl History {
|
|||||||
.get(&era_index)
|
.get(&era_index)
|
||||||
.map(|x| x.is_claimed)
|
.map(|x| x.is_claimed)
|
||||||
.expect("BTreeMap of rewards is indexed; qed");
|
.expect("BTreeMap of rewards is indexed; qed");
|
||||||
|
|
||||||
if let Some(action_tx) = &self.action_tx {
|
if let Some(action_tx) = &self.action_tx {
|
||||||
let _ = action_tx.send(Action::PayoutValidatorPopup(*era_index, is_claimed));
|
let _ = match (is_claimed, self.pending_payout.contains(era_index)) {
|
||||||
|
(false, false) => {
|
||||||
|
self.pending_payout.insert(*era_index);
|
||||||
|
action_tx.send(Action::PayoutValidatorPopup(*era_index))
|
||||||
|
}
|
||||||
|
(false, true) => action_tx.send(Action::EventLog(
|
||||||
|
format!("payout for era #{} is in-flight already", era_index),
|
||||||
|
ActionLevel::Warn,
|
||||||
|
ActionTarget::ValidatorLog)),
|
||||||
|
(true, _) => action_tx.send(Action::EventLog(
|
||||||
|
format!("staking rewards for era index #{} already claimed", era_index),
|
||||||
|
ActionLevel::Warn,
|
||||||
|
ActionTarget::ValidatorLog)),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,6 +160,7 @@ impl History {
|
|||||||
match self.rewards.get_mut(&era_index) {
|
match self.rewards.get_mut(&era_index) {
|
||||||
Some(reward_item) => {
|
Some(reward_item) => {
|
||||||
if reward_item.is_claimed == false && is_claimed == true {
|
if reward_item.is_claimed == false && is_claimed == true {
|
||||||
|
self.pending_payout.remove(&era_index);
|
||||||
if let Some(network_tx) = &self.network_tx {
|
if let Some(network_tx) = &self.network_tx {
|
||||||
let _ = network_tx.send(Action::RemoveEraToWatch(era_index));
|
let _ = network_tx.send(Action::RemoveEraToWatch(era_index));
|
||||||
}
|
}
|
||||||
@ -183,10 +201,7 @@ impl PartialComponent for History {
|
|||||||
fn set_active(&mut self, current_tab: CurrentTab) {
|
fn set_active(&mut self, current_tab: CurrentTab) {
|
||||||
match current_tab {
|
match current_tab {
|
||||||
CurrentTab::History => self.is_active = true,
|
CurrentTab::History => self.is_active = true,
|
||||||
_ => {
|
_ => self.is_active = false,
|
||||||
self.table_state.select(None);
|
|
||||||
self.is_active = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,6 +278,12 @@ impl Component for History {
|
|||||||
Cell::from(reward_text),
|
Cell::from(reward_text),
|
||||||
]).style(self.palette.create_highlight_style())
|
]).style(self.palette.create_highlight_style())
|
||||||
} else {
|
} else {
|
||||||
|
if self.pending_payout.contains(key) {
|
||||||
|
era_index_text = era_index_text.add_modifier(Modifier::SLOW_BLINK);
|
||||||
|
slash_text = slash_text.add_modifier(Modifier::SLOW_BLINK);
|
||||||
|
reward_text = reward_text.add_modifier(Modifier::SLOW_BLINK);
|
||||||
|
}
|
||||||
|
|
||||||
Row::new(vec![
|
Row::new(vec![
|
||||||
Cell::from(era_index_text),
|
Cell::from(era_index_text),
|
||||||
Cell::from(slash_text),
|
Cell::from(slash_text),
|
||||||
|
@ -240,7 +240,7 @@ impl Component for Validator {
|
|||||||
self.previous_tab = CurrentTab::NominatorsByValidator;
|
self.previous_tab = CurrentTab::NominatorsByValidator;
|
||||||
self.current_tab = CurrentTab::NominatorsByValidator;
|
self.current_tab = CurrentTab::NominatorsByValidator;
|
||||||
}
|
}
|
||||||
Action::PayoutValidatorPopup(_, _) => {
|
Action::PayoutValidatorPopup(_) => {
|
||||||
self.previous_tab = self.current_tab;
|
self.previous_tab = self.current_tab;
|
||||||
self.current_tab = CurrentTab::PayoutPopup;
|
self.current_tab = CurrentTab::PayoutPopup;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ use crate::{
|
|||||||
action::Action,
|
action::Action,
|
||||||
config::Config,
|
config::Config,
|
||||||
palette::StylePalette,
|
palette::StylePalette,
|
||||||
types::{ActionLevel, ActionTarget},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -24,7 +23,6 @@ pub struct PayoutPopup {
|
|||||||
secret_seed: [u8; 32],
|
secret_seed: [u8; 32],
|
||||||
stash_account_id: [u8; 32],
|
stash_account_id: [u8; 32],
|
||||||
era_index: u32,
|
era_index: u32,
|
||||||
is_claimed: bool,
|
|
||||||
palette: StylePalette
|
palette: StylePalette
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,18 +39,12 @@ impl PayoutPopup {
|
|||||||
secret_seed: [0u8; 32],
|
secret_seed: [0u8; 32],
|
||||||
stash_account_id: [0u8; 32],
|
stash_account_id: [0u8; 32],
|
||||||
era_index: 0u32,
|
era_index: 0u32,
|
||||||
is_claimed: false,
|
|
||||||
action_tx: None,
|
action_tx: None,
|
||||||
network_tx: None,
|
network_tx: None,
|
||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store_era_to_claim(&mut self, era_index: u32, is_claimed: bool) {
|
|
||||||
self.is_claimed = is_claimed;
|
|
||||||
self.era_index = era_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn close_popup(&mut self) {
|
fn close_popup(&mut self) {
|
||||||
self.is_active = false;
|
self.is_active = false;
|
||||||
if let Some(action_tx) = &self.action_tx {
|
if let Some(action_tx) = &self.action_tx {
|
||||||
@ -61,20 +53,11 @@ impl PayoutPopup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start_payout(&mut self) {
|
fn start_payout(&mut self) {
|
||||||
if self.is_claimed {
|
if let Some(network_tx) = &self.network_tx {
|
||||||
if let Some(action_tx) = &self.action_tx {
|
let _ = network_tx.send(Action::PayoutStakers(
|
||||||
let _ = action_tx.send(Action::EventLog(
|
self.secret_seed,
|
||||||
format!("staking rewards for era index #{} already claimed", self.era_index),
|
self.stash_account_id,
|
||||||
ActionLevel::Warn,
|
self.era_index));
|
||||||
ActionTarget::ValidatorLog));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if let Some(network_tx) = &self.network_tx {
|
|
||||||
let _ = network_tx.send(Action::PayoutStakers(
|
|
||||||
self.secret_seed,
|
|
||||||
self.stash_account_id,
|
|
||||||
self.era_index));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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);
|
||||||
@ -126,8 +109,7 @@ impl Component for PayoutPopup {
|
|||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
match action {
|
match action {
|
||||||
Action::PayoutValidatorPopup(era_index, is_claimed) =>
|
Action::PayoutValidatorPopup(era_index) => self.era_index = era_index,
|
||||||
self.store_era_to_claim(era_index, is_claimed),
|
|
||||||
Action::SetStashSecret(secret_seed) => self.secret_seed = secret_seed,
|
Action::SetStashSecret(secret_seed) => self.secret_seed = secret_seed,
|
||||||
Action::SetStashAccount(account_id) => self.stash_account_id = account_id,
|
Action::SetStashAccount(account_id) => self.stash_account_id = account_id,
|
||||||
_ => {}
|
_ => {}
|
||||||
|
Loading…
Reference in New Issue
Block a user