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) {
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));
}
}
}
}