From 7d6933ed39f4254b0107e88895cb4ca12d392928 Mon Sep 17 00:00:00 2001 From: Tarik Gul <47201679+TarikGul@users.noreply.github.com> Date: Fri, 10 May 2024 11:45:26 -0700 Subject: [PATCH] Dedupe nextElected accountIds (#5876) * Dedupe nextElected accountIds * remove consoles --- packages/api-derive/src/staking/validators.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/api-derive/src/staking/validators.ts b/packages/api-derive/src/staking/validators.ts index c266776e0e..e8561e904c 100644 --- a/packages/api-derive/src/staking/validators.ts +++ b/packages/api-derive/src/staking/validators.ts @@ -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']() );