diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d4169f9d0..c005a8b2e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Add typings for `api.tx.*.*` - the `polkadot-types-from-chain` now also generates these - Remove additional V1-only derives `(staking.recentlyOffline`, `balances.nominatorsFor`) - Add `.isMax()` on int values, an opposite of `isZero()` (e.g. `u128`, as well as derived, e.g. `Balances`) -- Add `.keyPrefix()` to all `api.query.*` complimenting the `.key()` call, both returning a hex string +- Add `.keyPrefix()` to all `api.query.*` complementing the `.key()` call, both returning a hex string # 1.0.1 diff --git a/packages/api-derive/src/elections/info.ts b/packages/api-derive/src/elections/info.ts index f72368a716..6f68befc29 100644 --- a/packages/api-derive/src/elections/info.ts +++ b/packages/api-derive/src/elections/info.ts @@ -13,21 +13,28 @@ import { createType, Vec, u32 } from '@polkadot/types'; import { DerivedElectionsInfo } from '../types'; import { memo } from '../util'; +function sortAccounts ([, balanceA]: ITuple<[AccountId, Balance]>, [, balanceB]: ITuple<[AccountId, Balance]>): number { + return balanceB.cmp(balanceA); +} + function queryElections (api: ApiInterfaceRx): Observable { const section = api.query.electionsPhragmen ? 'electionsPhragmen' : 'elections'; - return api.queryMulti<[Vec, Vec>, Vec>]>([ + return api.queryMulti<[Vec, Vec, Vec>, Vec>]>([ + api.query.council.members, api.query[section].candidates, api.query[section].members, api.query[section].runnersUp ]).pipe( - map(([candidates, members, runnersUp]): DerivedElectionsInfo => ({ + map(([councilMembers, candidates, members, runnersUp]): DerivedElectionsInfo => ({ candidates, candidateCount: createType(api.registry, 'u32', candidates.length), candidacyBond: api.consts[section].candidacyBond as Balance, desiredSeats: api.consts[section].desiredMembers as u32, - members: members.sort((a, b): number => b[1].cmp(a[1])), - runnersUp: runnersUp.sort((a, b): number => b[1].cmp(a[1])), + members: members.length + ? members.sort(sortAccounts) + : councilMembers.map((accountId): [AccountId, Balance] => [accountId, createType(api.registry, 'Balance')]), + runnersUp: runnersUp.sort(sortAccounts), termDuration: api.consts[section].termDuration as BlockNumber, votingBond: api.consts[section].votingBond as Balance }))