From 3557e5fa4e279656cd15faf5a7558d79676df927 Mon Sep 17 00:00:00 2001 From: Uncle Stretch Date: Fri, 21 Feb 2025 13:30:07 +0300 Subject: [PATCH] correct reverse indexing in BTreeMap Signed-off-by: Uncle Stretch --- src/components/validator/history.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/components/validator/history.rs b/src/components/validator/history.rs index 178447b..be3e4da 100644 --- a/src/components/validator/history.rs +++ b/src/components/validator/history.rs @@ -64,19 +64,18 @@ impl History { fn payout_by_era_index(&mut self) { if let Some(index) = self.table_state.selected() { - let length = self.rewards.len() as u32; - let era_index = self.rewards - .keys() - .nth(index) - .map(|i| length - i - 1) - .expect("BTreeMap of rewards is indexed; qed"); - let is_claimed = self.rewards - .get(&era_index) - .map(|x| x.is_claimed) - .expect("BTreeMap of rewards is indexed; qed"); - if let Some(action_tx) = &self.action_tx { - let _ = action_tx.send( - Action::PayoutValidatorPopup(era_index, is_claimed)); + let rev_index = self.rewards.len() + .saturating_sub(index) + .saturating_sub(1); + + if let Some(era_index) = self.rewards.keys().nth(rev_index) { + let is_claimed = self.rewards + .get(&era_index) + .map(|x| x.is_claimed) + .expect("BTreeMap of rewards is indexed; qed"); + if let Some(action_tx) = &self.action_tx { + let _ = action_tx.send(Action::PayoutValidatorPopup(*era_index, is_claimed)); + } } } }