* Bump deps w/ eslint * Additional cleanups * Additional * @polkadot/types done * Additional * @polkadot/typegen done * Additional * @polkadot/rpc-core done * Additional * Additional * Additional * docs * @polkadot/api-derive done * @polkadot/api done * @polkadot/api-contracts done * Update tests
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
|
// This software may be modified and distributed under the terms
|
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
|
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
|
import { ReferendumIndex } from '@polkadot/types/interfaces';
|
|
|
|
import BN from 'bn.js';
|
|
import { Observable, of } from 'rxjs';
|
|
import { map } from 'rxjs/operators';
|
|
|
|
import { memo } from '../util';
|
|
|
|
export function referendumIds (api: ApiInterfaceRx): () => Observable<BN[]> {
|
|
return memo((): Observable<BN[]> =>
|
|
api.query.democracy?.lowestUnbaked
|
|
? api.queryMulti<[ReferendumIndex, ReferendumIndex]>([
|
|
api.query.democracy.lowestUnbaked,
|
|
api.query.democracy.referendumCount
|
|
]).pipe(
|
|
map(([first, total]): BN[] =>
|
|
total.gt(first)
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
? [...Array(total.sub(first).toNumber())].map((_, i): BN => first.addn(i))
|
|
: []
|
|
)
|
|
)
|
|
: of([])
|
|
);
|
|
}
|