Skip to content

Commit

Permalink
Dedupe nextElected accountIds (#5876)
Browse files Browse the repository at this point in the history
* Dedupe nextElected accountIds

* remove consoles
  • Loading branch information
TarikGul authored May 10, 2024
1 parent 32a04fd commit 7d6933e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/api-derive/src/staking/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ export function nextElected (instanceId: string, api: DeriveApi): () => Observab
// only populate for next era in the last session, so track both here - entries are not
// subscriptions, so we need a trigger - currentIndex acts as that trigger to refresh
switchMap(({ currentEra }) => api.query.staking.erasStakersPaged.keys(currentEra)),
map((keys) => keys.map(({ args: [, accountId] }) => accountId))
// Dedupe any duplicates
map((keys) => [...new Set(keys.map(({ args: [, accountId] }) => accountId.toString()))].map((a) => api.registry.createType('AccountId', a)))
)
: api.query.staking.erasStakers
? api.derive.session.indexes().pipe(
// only populate for next era in the last session, so track both here - entries are not
// subscriptions, so we need a trigger - currentIndex acts as that trigger to refresh
switchMap(({ currentEra }) => api.query.staking.erasStakers.keys(currentEra)),
map((keys) => keys.map(({ args: [, accountId] }) => accountId))
// Dedupe any duplicates
map((keys) => [...new Set(keys.map(({ args: [, accountId] }) => accountId.toString()))].map((a) => api.registry.createType('AccountId', a)))
)
: api.query.staking['currentElected']<AccountId[]>()
);
Expand Down

0 comments on commit 7d6933e

Please sign in to comment.