Skip to content

Commit

Permalink
L1-301: L1-302: Fix duplicated validators in Staking>Targets & in nom…
Browse files Browse the repository at this point in the history
…inator setup
  • Loading branch information
youPickItUp committed Oct 14, 2024
1 parent 3357504 commit 8a55c37
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions packages/page-staking/src/useSortedTargets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ function isWaitingDerive (derive: DeriveStakingElected | DeriveStakingWaiting):
return !(derive as DeriveStakingElected).nextElected;
}

function filterOutDuplicatedValidators (list: ValidatorInfo[]): ValidatorInfo[] {
const keyToIsPresent: Partial<Record<string, true>> = {};

return list.filter(({ accountId }): boolean => {
const key = accountId.toString();

if (keyToIsPresent[key]) {
return false;
}

keyToIsPresent[key] = true;

return true;
});
}

function sortValidators (list: ValidatorInfo[]): ValidatorInfo[] {
const existing: string[] = [];

Expand Down Expand Up @@ -247,7 +263,7 @@ function extractBaseInfo (api: ApiPromise, allAccounts: string[], electedDerive:
? value
: min;
}, BN_ZERO);
const validators = arrayFlatten([elected, waiting]);
const validators = filterOutDuplicatedValidators(arrayFlatten([elected, waiting]));
const commValues = validators.map(({ commissionPer }) => commissionPer).sort((a, b) => a - b);
const midIndex = Math.floor(commValues.length / 2);
const medianComm = commValues.length
Expand All @@ -258,14 +274,8 @@ function extractBaseInfo (api: ApiPromise, allAccounts: string[], electedDerive:

// ids
const waitingIds = waiting.map(({ key }) => key);
const validatorIds = arrayFlatten([
elected.map(({ key }) => key),
waitingIds
]);
const nominateIds = arrayFlatten([
elected.filter(({ isBlocking }) => !isBlocking).map(({ key }) => key),
waiting.filter(({ isBlocking }) => !isBlocking).map(({ key }) => key)
]);
const validatorIds = validators.map(({ key }) => key);
const nominateIds = validators.filter(({ isBlocking }) => !isBlocking).map(({ key }) => key);

return {
avgStaked,
Expand Down

0 comments on commit 8a55c37

Please sign in to comment.