correct reverse indexing in BTreeMap

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch 2025-02-21 13:30:07 +03:00
parent 3284d5d07e
commit 3557e5fa4e
Signed by: str3tch
GPG Key ID: 84F3190747EE79AA

View File

@ -64,19 +64,18 @@ impl History {
fn payout_by_era_index(&mut self) { fn payout_by_era_index(&mut self) {
if let Some(index) = self.table_state.selected() { if let Some(index) = self.table_state.selected() {
let length = self.rewards.len() as u32; let rev_index = self.rewards.len()
let era_index = self.rewards .saturating_sub(index)
.keys() .saturating_sub(1);
.nth(index)
.map(|i| length - i - 1) if let Some(era_index) = self.rewards.keys().nth(rev_index) {
.expect("BTreeMap of rewards is indexed; qed"); let is_claimed = self.rewards
let is_claimed = self.rewards .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 _ = action_tx.send( }
Action::PayoutValidatorPopup(era_index, is_claimed));
} }
} }
} }