diff --git a/packages/api-derive/src/balances/account.ts b/packages/api-derive/src/balances/account.ts index 8db57f7fb0..a8b5097c79 100644 --- a/packages/api-derive/src/balances/account.ts +++ b/packages/api-derive/src/balances/account.ts @@ -4,7 +4,7 @@ import { AccountId, AccountData, AccountIndex, AccountInfo, Address, Balance, Index } from '@polkadot/types/interfaces'; import { ITuple } from '@polkadot/types/types'; -import { DerivedBalancesAccount } from '../types'; +import { DeriveBalancesAccount } from '../types'; import { Observable, combineLatest, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; @@ -14,7 +14,7 @@ import { memo } from '../util'; type Result = [Balance, Balance, Balance, Balance, Index]; -function calcBalances (api: ApiInterfaceRx, [accountId, [freeBalance, reservedBalance, frozenFee, frozenMisc, accountNonce]]: [AccountId, Result]): DerivedBalancesAccount { +function calcBalances (api: ApiInterfaceRx, [accountId, [freeBalance, reservedBalance, frozenFee, frozenMisc, accountNonce]]: [AccountId, Result]): DeriveBalancesAccount { return { accountId, accountNonce, @@ -79,8 +79,8 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable Observable { - return memo((address: AccountIndex | AccountId | Address | string): Observable => +export function account (api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable { + return memo((address: AccountIndex | AccountId | Address | string): Observable => api.derive.accounts.info(address).pipe( switchMap(({ accountId }): Observable<[AccountId, Result]> => (accountId @@ -95,6 +95,6 @@ export function account (api: ApiInterfaceRx): (address: AccountIndex | AccountI : of([api.registry.createType('AccountId'), [api.registry.createType('Balance'), api.registry.createType('Balance'), api.registry.createType('Balance'), api.registry.createType('Balance'), api.registry.createType('Index')]]) ) ), - map((result): DerivedBalancesAccount => calcBalances(api, result)) + map((result): DeriveBalancesAccount => calcBalances(api, result)) )); } diff --git a/packages/api-derive/src/balances/all.ts b/packages/api-derive/src/balances/all.ts index 45ea030bb7..0a2d812e14 100644 --- a/packages/api-derive/src/balances/all.ts +++ b/packages/api-derive/src/balances/all.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { AccountId, AccountIndex, Address, Balance, BalanceLock, BalanceLockTo212, BlockNumber, VestingInfo, VestingSchedule } from '@polkadot/types/interfaces'; -import { DerivedBalancesAccount, DerivedBalancesAll } from '../types'; +import { DeriveBalancesAccount, DeriveBalancesAll } from '../types'; import BN from 'bn.js'; import { Observable, combineLatest, of } from 'rxjs'; @@ -15,9 +15,9 @@ import { bnMax } from '@polkadot/util'; import { memo } from '../util'; type ResultBalance = [VestingInfo | null, (BalanceLock | BalanceLockTo212)[]]; -type Result = [DerivedBalancesAccount, BlockNumber, ResultBalance]; +type Result = [DeriveBalancesAccount, BlockNumber, ResultBalance]; -function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBalance, frozenFee, frozenMisc, reservedBalance, votingBalance }, bestNumber, [vesting, locks]]: Result): DerivedBalancesAll { +function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBalance, frozenFee, frozenMisc, reservedBalance, votingBalance }, bestNumber, [vesting, locks]]: Result): DeriveBalancesAll { let lockedBalance = api.registry.createType('Balance'); let lockedBreakdown: (BalanceLock | BalanceLockTo212)[] = []; let allLocked = false; @@ -127,8 +127,8 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable Observable { - return memo((address: AccountIndex | AccountId | Address | string): Observable => +export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable { + return memo((address: AccountIndex | AccountId | Address | string): Observable => api.derive.balances.account(address).pipe( switchMap((account): Observable => (!account.accountId.isEmpty @@ -142,6 +142,6 @@ export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId | : of([account, api.registry.createType('BlockNumber'), [null, api.registry.createType('Vec')]]) ) ), - map((result): DerivedBalancesAll => calcBalances(api, result)) + map((result): DeriveBalancesAll => calcBalances(api, result)) )); } diff --git a/packages/api-derive/src/balances/fees.ts b/packages/api-derive/src/balances/fees.ts index 5335375ae0..062414ba2e 100644 --- a/packages/api-derive/src/balances/fees.ts +++ b/packages/api-derive/src/balances/fees.ts @@ -4,7 +4,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { Balance } from '@polkadot/types/interfaces'; -import { DerivedFees } from '../types'; +import { DeriveFees } from '../types'; import { Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; @@ -24,8 +24,8 @@ import { memo } from '../util'; * }); * ``` */ -export function fees (api: ApiInterfaceRx): () => Observable { - return memo((): Observable => +export function fees (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => of([ // deprecated - remove (api.consts.balances?.creationFee as Balance) || api.registry.createType('Balance'), @@ -36,7 +36,7 @@ export function fees (api: ApiInterfaceRx): () => Observable { (api.consts.transactionPayment?.transactionBaseFee as Balance) || api.registry.createType('Balance'), (api.consts.transactionPayment?.transactionByteFee as Balance) || api.registry.createType('Balance') ]).pipe( - map(([creationFee, transferFee, existentialDeposit, transactionBaseFee, transactionByteFee]): DerivedFees => ({ + map(([creationFee, transferFee, existentialDeposit, transactionBaseFee, transactionByteFee]): DeriveFees => ({ creationFee, existentialDeposit, transactionBaseFee, diff --git a/packages/api-derive/src/balances/votingBalances.ts b/packages/api-derive/src/balances/votingBalances.ts index ff18be1d7f..909882d9c3 100644 --- a/packages/api-derive/src/balances/votingBalances.ts +++ b/packages/api-derive/src/balances/votingBalances.ts @@ -3,19 +3,19 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces'; -import { DerivedBalancesAccount } from '../types'; +import { DeriveBalancesAccount } from '../types'; import { Observable, combineLatest, of } from 'rxjs'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { memo } from '../util'; -export function votingBalances (api: ApiInterfaceRx): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable { - return memo((addresses?: (AccountId | AccountIndex | Address | string)[]): Observable => +export function votingBalances (api: ApiInterfaceRx): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable { + return memo((addresses?: (AccountId | AccountIndex | Address | string)[]): Observable => !addresses || !addresses.length - ? of([] as DerivedBalancesAccount[]) + ? of([] as DeriveBalancesAccount[]) : combineLatest( - addresses.map((accountId): Observable => + addresses.map((accountId): Observable => api.derive.balances.account(accountId) ) ) diff --git a/packages/api-derive/src/collective/proposals.ts b/packages/api-derive/src/collective/proposals.ts index bbc51681e0..52c3b78baa 100644 --- a/packages/api-derive/src/collective/proposals.ts +++ b/packages/api-derive/src/collective/proposals.ts @@ -4,7 +4,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { Hash, Proposal, Votes } from '@polkadot/types/interfaces'; -import { DerivedCollectiveProposal } from '../types'; +import { DeriveCollectiveProposal } from '../types'; import { Observable, combineLatest, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; @@ -12,9 +12,9 @@ import { Option } from '@polkadot/types'; type Result = [Hash[], Option[], Option[]]; -function parse ([hashes, proposals, votes]: Result): DerivedCollectiveProposal[] { +function parse ([hashes, proposals, votes]: Result): DeriveCollectiveProposal[] { return proposals - .map((proposalOpt, index): DerivedCollectiveProposal | null => + .map((proposalOpt, index): DeriveCollectiveProposal | null => proposalOpt.isSome ? { hash: hashes[index], @@ -23,11 +23,11 @@ function parse ([hashes, proposals, votes]: Result): DerivedCollectiveProposal[] } : null ) - .filter((proposal): proposal is DerivedCollectiveProposal => !!proposal); + .filter((proposal): proposal is DeriveCollectiveProposal => !!proposal); } -export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalCommittee'): () => Observable { - return (): Observable => +export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalCommittee'): () => Observable { + return (): Observable => api.query[section]?.proposals ? api.query[section].proposals().pipe( switchMap((hashes: Hash[]): Observable => @@ -41,5 +41,5 @@ export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalC ), map(parse) ) - : of([] as DerivedCollectiveProposal[]); + : of([] as DeriveCollectiveProposal[]); } diff --git a/packages/api-derive/src/contracts/fees.ts b/packages/api-derive/src/contracts/fees.ts index 115aa667fb..f93e098882 100644 --- a/packages/api-derive/src/contracts/fees.ts +++ b/packages/api-derive/src/contracts/fees.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ApiInterfaceRx } from '@polkadot/api/types'; -import { DerivedContractFees } from '../types'; +import { DeriveContractFees } from '../types'; import BN from 'bn.js'; import { Observable, of } from 'rxjs'; @@ -44,10 +44,10 @@ function queryConstants (api: ApiInterfaceRx): Observable { * }); * ``` */ -export function fees (api: ApiInterfaceRx): () => Observable { - return memo((): Observable => { +export function fees (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => { return queryConstants(api).pipe( - map(([creationFee, transferFee, callBaseFee, contractFee, rentByteFee, rentDepositOffset, tombstoneDeposit, transactionBaseFee, transactionByteFee]): DerivedContractFees => ({ + map(([creationFee, transferFee, callBaseFee, contractFee, rentByteFee, rentDepositOffset, tombstoneDeposit, transactionBaseFee, transactionByteFee]): DeriveContractFees => ({ callBaseFee, contractFee, creationFee, diff --git a/packages/api-derive/src/council/proposals.ts b/packages/api-derive/src/council/proposals.ts index faee798a3c..0cfef25a06 100644 --- a/packages/api-derive/src/council/proposals.ts +++ b/packages/api-derive/src/council/proposals.ts @@ -3,12 +3,12 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ApiInterfaceRx } from '@polkadot/api/types'; -import { DerivedCollectiveProposals } from '../types'; +import { DeriveCollectiveProposals } from '../types'; import { Observable } from 'rxjs'; import { proposals as collectiveProposals } from '../collective'; import { memo } from '../util'; -export function proposals (api: ApiInterfaceRx): () => Observable { +export function proposals (api: ApiInterfaceRx): () => Observable { return memo(collectiveProposals(api, 'council')); } diff --git a/packages/api-derive/src/democracy/_referendumInfo.ts b/packages/api-derive/src/democracy/_referendumInfo.ts index a83635b81f..4c0422121c 100644 --- a/packages/api-derive/src/democracy/_referendumInfo.ts +++ b/packages/api-derive/src/democracy/_referendumInfo.ts @@ -4,7 +4,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { ReferendumInfo, ReferendumInfoTo239, ReferendumStatus } from '@polkadot/types/interfaces'; -import { DerivedReferendum } from '../types'; +import { DeriveReferendum } from '../types'; import BN from 'bn.js'; import { Observable, of } from 'rxjs'; @@ -15,7 +15,7 @@ import { memo } from '../util'; import { PreImage } from './proposals'; import { getStatus } from './util'; -function constructInfo (api: ApiInterfaceRx, index: BN | number, status: ReferendumStatus | ReferendumInfoTo239, _preimage?: PreImage): DerivedReferendum | null { +function constructInfo (api: ApiInterfaceRx, index: BN | number, status: ReferendumStatus | ReferendumInfoTo239, _preimage?: PreImage): DeriveReferendum | null { const preImage = _preimage?.isSome ? _preimage.unwrap() : null; @@ -36,13 +36,13 @@ function constructInfo (api: ApiInterfaceRx, index: BN | number, status: Referen status }; } -export function _referendumInfo (api: ApiInterfaceRx): (id: BN, info: Option) => Observable { - return memo((id: BN, info: Option): Observable => { +export function _referendumInfo (api: ApiInterfaceRx): (id: BN, info: Option) => Observable { + return memo((id: BN, info: Option): Observable => { const status = getStatus(info); return status ? api.query.democracy.preimages(status.proposalHash).pipe( - map((preimage?: PreImage): DerivedReferendum | null => + map((preimage?: PreImage): DeriveReferendum | null => constructInfo(api, id, status, preimage) ) ) diff --git a/packages/api-derive/src/democracy/_referendumVotes.ts b/packages/api-derive/src/democracy/_referendumVotes.ts index 62555dab67..7ccdf8550d 100644 --- a/packages/api-derive/src/democracy/_referendumVotes.ts +++ b/packages/api-derive/src/democracy/_referendumVotes.ts @@ -4,7 +4,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { AccountId, Vote, Voting, VotingDirectVote } from '@polkadot/types/interfaces'; -import { DerivedBalancesAccount, DerivedReferendum, DerivedReferendumVote, DerivedReferendumVotes } from '../types'; +import { DeriveBalancesAccount, DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes } from '../types'; import BN from 'bn.js'; import { Observable, of, combineLatest } from 'rxjs'; @@ -14,9 +14,9 @@ import { Vec } from '@polkadot/types'; import { memo } from '../util'; import { calcVotes } from './util'; -function votesPrev (api: ApiInterfaceRx, referendumId: BN): Observable { +function votesPrev (api: ApiInterfaceRx, referendumId: BN): Observable { return api.query.democracy.votersFor>(referendumId).pipe( - switchMap((votersFor): Observable<[Vec, Vote[], DerivedBalancesAccount[]]> => + switchMap((votersFor): Observable<[Vec, Vote[], DeriveBalancesAccount[]]> => combineLatest([ of(votersFor), votersFor.length @@ -29,8 +29,8 @@ function votesPrev (api: ApiInterfaceRx, referendumId: BN): Observable - votersFor.map((accountId, index): DerivedReferendumVote => ({ + map(([votersFor, votes, balances]): DeriveReferendumVote[] => + votersFor.map((accountId, index): DeriveReferendumVote => ({ accountId, balance: balances[index].votingBalance || api.registry.createType('Balance'), vote: votes[index] || api.registry.createType('Vote') @@ -39,9 +39,9 @@ function votesPrev (api: ApiInterfaceRx, referendumId: BN): Observable { +function votesCurr (api: ApiInterfaceRx, referendumId: BN): Observable { return api.query.democracy.votingOf.entries().pipe( - map((allVoting): DerivedReferendumVote[] => + map((allVoting): DeriveReferendumVote[] => allVoting .map(([key, voting]): [AccountId, Voting] => [key.args[0] as AccountId, voting]) // FIXME We are ignoring delegated votes @@ -51,9 +51,9 @@ function votesCurr (api: ApiInterfaceRx, referendumId: BN): Observable idx.eq(referendumId)) ]) .filter(([, directVotes]) => !!directVotes.length) - .reduce((result: DerivedReferendumVote[], [accountId, votes]) => + .reduce((result: DeriveReferendumVote[], [accountId, votes]) => // FIXME We are ignoring split votes - votes.reduce((result: DerivedReferendumVote[], [, vote]): DerivedReferendumVote[] => { + votes.reduce((result: DeriveReferendumVote[], [, vote]): DeriveReferendumVote[] => { if (vote.isStandard) { result.push({ accountId, @@ -68,8 +68,8 @@ function votesCurr (api: ApiInterfaceRx, referendumId: BN): Observable Observable { - return memo((referendum: DerivedReferendum): Observable => +export function _referendumVotes (api: ApiInterfaceRx): (referendum: DeriveReferendum) => Observable { + return memo((referendum: DeriveReferendum): Observable => combineLatest([ api.derive.democracy.sqrtElectorate(), api.query.democracy.votingOf diff --git a/packages/api-derive/src/democracy/_referendumsVotes.ts b/packages/api-derive/src/democracy/_referendumsVotes.ts index 0bac4d1a87..112203b2b9 100644 --- a/packages/api-derive/src/democracy/_referendumsVotes.ts +++ b/packages/api-derive/src/democracy/_referendumsVotes.ts @@ -3,17 +3,17 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ApiInterfaceRx } from '@polkadot/api/types'; -import { DerivedReferendum, DerivedReferendumVotes } from '../types'; +import { DeriveReferendum, DeriveReferendumVotes } from '../types'; import { Observable, of, combineLatest } from 'rxjs'; import { memo } from '../util'; -export function _referendumsVotes (api: ApiInterfaceRx): (referendums: DerivedReferendum[]) => Observable { - return memo((referendums: DerivedReferendum[]): Observable => +export function _referendumsVotes (api: ApiInterfaceRx): (referendums: DeriveReferendum[]) => Observable { + return memo((referendums: DeriveReferendum[]): Observable => referendums.length ? combineLatest( - referendums.map((referendum): Observable => + referendums.map((referendum): Observable => api.derive.democracy._referendumVotes(referendum) ) ) diff --git a/packages/api-derive/src/democracy/referendums.ts b/packages/api-derive/src/democracy/referendums.ts index cb140a8de2..d278fdd950 100644 --- a/packages/api-derive/src/democracy/referendums.ts +++ b/packages/api-derive/src/democracy/referendums.ts @@ -3,15 +3,15 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ApiInterfaceRx } from '@polkadot/api/types'; -import { DerivedReferendumExt } from '../types'; +import { DeriveReferendumExt } from '../types'; import { Observable, combineLatest, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { memo } from '../util'; -export function referendums (api: ApiInterfaceRx): () => Observable { - return memo((): Observable => +export function referendums (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => api.derive.democracy.referendumsActive().pipe( switchMap((referendums) => combineLatest([ @@ -20,7 +20,7 @@ export function referendums (api: ApiInterfaceRx): () => Observable - referendums.map((referendum, index): DerivedReferendumExt => ({ + referendums.map((referendum, index): DeriveReferendumExt => ({ ...referendum, ...votes[index] })) diff --git a/packages/api-derive/src/democracy/referendumsActive.ts b/packages/api-derive/src/democracy/referendumsActive.ts index 47dcad0c85..c16f915ac1 100644 --- a/packages/api-derive/src/democracy/referendumsActive.ts +++ b/packages/api-derive/src/democracy/referendumsActive.ts @@ -4,7 +4,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { ReferendumIndex } from '@polkadot/types/interfaces'; -import { DerivedReferendum } from '../types'; +import { DeriveReferendum } from '../types'; import BN from 'bn.js'; import { Observable, of } from 'rxjs'; @@ -12,14 +12,14 @@ import { switchMap } from 'rxjs/operators'; import { memo } from '../util'; -export function referendumsActive (api: ApiInterfaceRx): () => Observable { - return memo((): Observable => +export function referendumsActive (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => api.query.democracy?.lowestUnbaked ? api.queryMulti<[ReferendumIndex, ReferendumIndex]>([ api.query.democracy.lowestUnbaked, api.query.democracy.referendumCount ]).pipe( - switchMap(([first, total]): Observable => + switchMap(([first, total]): Observable => total.gt(first) ? api.derive.democracy.referendumsInfo( [...Array(total.sub(first).toNumber())].map((_, i): BN => first.addn(i)) diff --git a/packages/api-derive/src/democracy/referendumsInfo.ts b/packages/api-derive/src/democracy/referendumsInfo.ts index 593507e9ee..e7398a0329 100644 --- a/packages/api-derive/src/democracy/referendumsInfo.ts +++ b/packages/api-derive/src/democracy/referendumsInfo.ts @@ -4,7 +4,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { ReferendumInfo } from '@polkadot/types/interfaces'; -import { DerivedReferendum } from '../types'; +import { DeriveReferendum } from '../types'; import BN from 'bn.js'; import { Observable, of, combineLatest } from 'rxjs'; @@ -13,19 +13,19 @@ import { Option } from '@polkadot/types'; import { memo } from '../util'; -export function referendumsInfo (api: ApiInterfaceRx): (ids: BN[]) => Observable { - return memo((ids: BN[]): Observable => +export function referendumsInfo (api: ApiInterfaceRx): (ids: BN[]) => Observable { + return memo((ids: BN[]): Observable => ids.length ? api.query.democracy.referendumInfoOf.multi>(ids).pipe( - switchMap((infos): Observable<(DerivedReferendum | null)[]> => + switchMap((infos): Observable<(DeriveReferendum | null)[]> => combineLatest( - ids.map((id, index): Observable => + ids.map((id, index): Observable => api.derive.democracy._referendumInfo(id, infos[index]) ) ) ), map((infos) => - infos.filter((referendum): referendum is DerivedReferendum => !!referendum) + infos.filter((referendum): referendum is DeriveReferendum => !!referendum) ) ) : of([]) diff --git a/packages/api-derive/src/democracy/types.ts b/packages/api-derive/src/democracy/types.ts index 734e9fa730..947d472ed4 100644 --- a/packages/api-derive/src/democracy/types.ts +++ b/packages/api-derive/src/democracy/types.ts @@ -23,7 +23,7 @@ export interface DeriveProposal { seconds: Vec; } -export interface DerivedReferendum { +export interface DeriveReferendum { hash: Hash; index: PropIndex; preimage?: DeriveProposalPreImage; @@ -31,15 +31,15 @@ export interface DerivedReferendum { status: ReferendumStatus | ReferendumInfoTo239; } -export interface DerivedReferendumVote { +export interface DeriveReferendumVote { accountId: AccountId; balance: Balance; vote: Vote; } -export interface DerivedReferendumVoteState { - allAye: DerivedReferendumVote[]; - allNay: DerivedReferendumVote[]; +export interface DeriveReferendumVoteState { + allAye: DeriveReferendumVote[]; + allNay: DeriveReferendumVote[]; voteCount: number; voteCountAye: number; voteCountNay: number; @@ -48,10 +48,10 @@ export interface DerivedReferendumVoteState { votedTotal: BN; } -export interface DerivedReferendumVotes extends DerivedReferendumVoteState { +export interface DeriveReferendumVotes extends DeriveReferendumVoteState { isPassing: boolean; - votes: DerivedReferendumVote[]; + votes: DeriveReferendumVote[]; } -export interface DerivedReferendumExt extends DerivedReferendum, DerivedReferendumVotes { +export interface DeriveReferendumExt extends DeriveReferendum, DeriveReferendumVotes { } diff --git a/packages/api-derive/src/democracy/util.ts b/packages/api-derive/src/democracy/util.ts index c7601b9ffa..f78e3c8112 100644 --- a/packages/api-derive/src/democracy/util.ts +++ b/packages/api-derive/src/democracy/util.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ReferendumInfo, ReferendumInfoTo239, ReferendumStatus, Tally, VoteThreshold } from '@polkadot/types/interfaces'; -import { DerivedReferendum, DerivedReferendumVote, DerivedReferendumVotes, DerivedReferendumVoteState } from '../types'; +import { DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes, DeriveReferendumVoteState } from '../types'; import BN from 'bn.js'; import { Option } from '@polkadot/types'; @@ -44,7 +44,7 @@ export function compareRationals (n1: BN, d1: BN, n2: BN, d2: BN): boolean { } } -function isPassing (threshold: VoteThreshold, sqrtElectorate: BN, { votedAye, votedNay, votedTotal }: DerivedReferendumVoteState): boolean { +function isPassing (threshold: VoteThreshold, sqrtElectorate: BN, { votedAye, votedNay, votedTotal }: DeriveReferendumVoteState): boolean { const sqrtVoters = bnSqrt(votedTotal); return sqrtVoters.isZero() @@ -56,8 +56,8 @@ function isPassing (threshold: VoteThreshold, sqrtElectorate: BN, { votedAye, vo : compareRationals(votedNay, sqrtElectorate, votedAye, sqrtVoters); } -function calcVotesPrev (votesFor: DerivedReferendumVote[]): DerivedReferendumVoteState { - return votesFor.reduce((state: DerivedReferendumVoteState, derived): DerivedReferendumVoteState => { +function calcVotesPrev (votesFor: DeriveReferendumVote[]): DeriveReferendumVoteState { + return votesFor.reduce((state: DeriveReferendumVoteState, derived): DeriveReferendumVoteState => { const { balance, vote } = derived; const isDefault = vote.conviction.index === 0; const counted = balance @@ -90,9 +90,9 @@ function calcVotesPrev (votesFor: DerivedReferendumVote[]): DerivedReferendumVot }); } -function calcVotesCurrent (tally: Tally, votes: DerivedReferendumVote[]): DerivedReferendumVoteState { - const allAye: DerivedReferendumVote[] = []; - const allNay: DerivedReferendumVote[] = []; +function calcVotesCurrent (tally: Tally, votes: DeriveReferendumVote[]): DeriveReferendumVoteState { + const allAye: DeriveReferendumVote[] = []; + const allNay: DeriveReferendumVote[] = []; votes.forEach((derived): void => { if (derived.vote.isAye) { @@ -114,7 +114,7 @@ function calcVotesCurrent (tally: Tally, votes: DerivedReferendumVote[]): Derive }; } -export function calcVotes (sqrtElectorate: BN, referendum: DerivedReferendum, votes: DerivedReferendumVote[]): DerivedReferendumVotes { +export function calcVotes (sqrtElectorate: BN, referendum: DeriveReferendum, votes: DeriveReferendumVote[]): DeriveReferendumVotes { const state = isCurrentStatus(referendum.status) ? calcVotesCurrent(referendum.status.tally, votes) : calcVotesPrev(votes); diff --git a/packages/api-derive/src/elections/info.ts b/packages/api-derive/src/elections/info.ts index bffdff3f1e..850c34c71e 100644 --- a/packages/api-derive/src/elections/info.ts +++ b/packages/api-derive/src/elections/info.ts @@ -10,14 +10,14 @@ import { map } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { Vec, u32 } from '@polkadot/types'; -import { DerivedElectionsInfo } from '../types'; +import { DeriveElectionsInfo } 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 { +function queryElections (api: ApiInterfaceRx): Observable { const section = api.query.electionsPhragmen ? 'electionsPhragmen' : 'elections'; return api.queryMulti<[Vec, Vec, Vec>, Vec>]>([ @@ -26,7 +26,7 @@ function queryElections (api: ApiInterfaceRx): Observable api.query[section].members, api.query[section].runnersUp ]).pipe( - map(([councilMembers, candidates, members, runnersUp]): DerivedElectionsInfo => ({ + map(([councilMembers, candidates, members, runnersUp]): DeriveElectionsInfo => ({ candidates, candidateCount: api.registry.createType('u32', candidates.length), candidacyBond: api.consts[section].candidacyBond as Balance, @@ -54,6 +54,6 @@ function queryElections (api: ApiInterfaceRx): Observable * }); * ``` */ -export function info (api: ApiInterfaceRx): () => Observable { - return memo((): Observable => queryElections(api)); +export function info (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => queryElections(api)); } diff --git a/packages/api-derive/src/imOnline/receivedHeartbeats.ts b/packages/api-derive/src/imOnline/receivedHeartbeats.ts index 7024ba4622..363d600aac 100644 --- a/packages/api-derive/src/imOnline/receivedHeartbeats.ts +++ b/packages/api-derive/src/imOnline/receivedHeartbeats.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { AccountId } from '@polkadot/types/interfaces'; -import { DerivedHeartbeats } from '../types'; +import { DeriveHeartbeats } from '../types'; import { Observable, of, combineLatest } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; @@ -15,8 +15,8 @@ import { memo } from '../util'; /** * @description Return a boolean array indicating whether the passed accounts had received heartbeats in the current session */ -export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable { - return memo((): Observable => +export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => api.query.imOnline?.receivedHeartbeats ? api.derive.staking.overview().pipe( switchMap(({ currentIndex, validators }): Observable<[AccountId[], Option[], u32[]]> => @@ -28,8 +28,8 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable [currentIndex, address])) ]) ), - map(([validators, heartbeats, numBlocks]): DerivedHeartbeats => - validators.reduce((result: DerivedHeartbeats, validator, index): DerivedHeartbeats => ({ + map(([validators, heartbeats, numBlocks]): DeriveHeartbeats => + validators.reduce((result: DeriveHeartbeats, validator, index): DeriveHeartbeats => ({ ...result, [validator.toString()]: { blockCount: numBlocks[index], diff --git a/packages/api-derive/src/session/info.ts b/packages/api-derive/src/session/info.ts index 629c7b417b..b9f29bd4e5 100644 --- a/packages/api-derive/src/session/info.ts +++ b/packages/api-derive/src/session/info.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { SessionIndex } from '@polkadot/types/interfaces'; -import { DerivedSessionInfo, DeriveSessionIndexes } from '../types'; +import { DeriveSessionInfo, DeriveSessionIndexes } from '../types'; import { Observable, combineLatest, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; @@ -17,7 +17,7 @@ type ResultSlotsFlat = [u64, u64, u64, SessionIndex]; type ResultType = [boolean, u64, SessionIndex]; type Result = [ResultType, DeriveSessionIndexes, ResultSlotsFlat]; -function createDerived (api: ApiInterfaceRx, [[hasBabe, epochDuration, sessionsPerEra], { activeEra, activeEraStart, currentEra, currentIndex, validatorCount }, [currentSlot, epochIndex, epochOrGenesisStartSlot, activeEraStartSessionIndex]]: Result): DerivedSessionInfo { +function createDerive (api: ApiInterfaceRx, [[hasBabe, epochDuration, sessionsPerEra], { activeEra, activeEraStart, currentEra, currentIndex, validatorCount }, [currentSlot, epochIndex, epochOrGenesisStartSlot, activeEraStartSessionIndex]]: Result): DeriveSessionInfo { const epochStartSlot = epochIndex.mul(epochDuration).add(epochOrGenesisStartSlot); const sessionProgress = currentSlot.sub(epochStartSlot); const eraProgress = currentIndex.sub(activeEraStartSessionIndex).mul(epochDuration).add(sessionProgress); @@ -37,10 +37,10 @@ function createDerived (api: ApiInterfaceRx, [[hasBabe, epochDuration, sessionsP }; } -function queryAura (api: ApiInterfaceRx): Observable { +function queryAura (api: ApiInterfaceRx): Observable { return api.derive.session.indexes().pipe( - map((indexes): DerivedSessionInfo => - createDerived(api, [ + map((indexes): DeriveSessionInfo => + createDerive(api, [ [ false, api.registry.createType('u64', 1), @@ -92,15 +92,15 @@ function queryBabeNoHistory (api: ApiInterfaceRx): Observable<[DeriveSessionInde /** * @description Retrieves all the session and era query and calculates specific values on it as the length of the session and eras */ -export function info (api: ApiInterfaceRx): () => Observable { - return memo((): Observable => +export function info (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => api.consts.babe ? (api.query.staking.erasStartSessionIndex ? queryBabe(api) // 2.x with Babe : queryBabeNoHistory(api) ).pipe( - map(([indexes, slots]: [DeriveSessionIndexes, ResultSlotsFlat]): DerivedSessionInfo => - createDerived(api, [ + map(([indexes, slots]: [DeriveSessionIndexes, ResultSlotsFlat]): DeriveSessionInfo => + createDerive(api, [ [true, api.consts.babe.epochDuration, api.consts.staking.sessionsPerEra], indexes, slots diff --git a/packages/api-derive/src/session/types.ts b/packages/api-derive/src/session/types.ts index 73b4c6abf4..b883d83e5a 100644 --- a/packages/api-derive/src/session/types.ts +++ b/packages/api-derive/src/session/types.ts @@ -14,7 +14,7 @@ export interface DeriveSessionIndexes { validatorCount: u32; } -export interface DerivedSessionInfo extends DeriveSessionIndexes { +export interface DeriveSessionInfo extends DeriveSessionIndexes { eraLength: BlockNumber; eraProgress: BlockNumber; isEpoch: boolean; diff --git a/packages/api-derive/src/staking/account.ts b/packages/api-derive/src/staking/account.ts index 4ce5647ba9..05fd9ac1b8 100644 --- a/packages/api-derive/src/staking/account.ts +++ b/packages/api-derive/src/staking/account.ts @@ -4,7 +4,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { Balance, BlockNumber, StakingLedger, UnlockChunk } from '@polkadot/types/interfaces'; -import { DerivedSessionInfo, DerivedStakingAccount, DerivedStakingQuery, DerivedUnlocking } from '../types'; +import { DeriveSessionInfo, DeriveStakingAccount, DeriveStakingQuery, DeriveUnlocking } from '../types'; import BN from 'bn.js'; import { Observable, combineLatest } from 'rxjs'; @@ -28,7 +28,7 @@ function groupByEra (list: UnlockChunk[]): Record { } // calculate the remaining blocks in a specific unlock era -function remainingBlocks (api: ApiInterfaceRx, era: BN, sessionInfo: DerivedSessionInfo): BlockNumber { +function remainingBlocks (api: ApiInterfaceRx, era: BN, sessionInfo: DeriveSessionInfo): BlockNumber { const remaining = era.sub(sessionInfo.currentEra); // on the Rust side the current-era >= era-for-unlock (removal done on >) @@ -41,7 +41,7 @@ function remainingBlocks (api: ApiInterfaceRx, era: BN, sessionInfo: DerivedSess ); } -function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DerivedSessionInfo): DerivedUnlocking[] | undefined { +function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DeriveSessionInfo): DeriveUnlocking[] | undefined { if (isUndefined(stakingLedger)) { return undefined; } @@ -56,7 +56,7 @@ function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger | // group the unlock chunks that have the same era and sum their values const groupedResult = groupByEra(unlockingChunks); - const results = Object.entries(groupedResult).map(([eraString, value]): DerivedUnlocking => ({ + const results = Object.entries(groupedResult).map(([eraString, value]): DeriveUnlocking => ({ value: api.registry.createType('Balance', value), remainingBlocks: remainingBlocks(api, new BN(eraString), sessionInfo) })); @@ -64,7 +64,7 @@ function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger | return results.length ? results : undefined; } -function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DerivedSessionInfo): Balance { +function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DeriveSessionInfo): Balance { if (isUndefined(stakingLedger)) { return api.registry.createType('Balance'); } @@ -76,7 +76,7 @@ function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | unde }, new BN(0))); } -function parseResult (api: ApiInterfaceRx, sessionInfo: DerivedSessionInfo, query: DerivedStakingQuery): DerivedStakingAccount { +function parseResult (api: ApiInterfaceRx, sessionInfo: DeriveSessionInfo, query: DeriveStakingQuery): DeriveStakingAccount { return { ...query, redeemable: redeemableSum(api, query.stakingLedger, sessionInfo), @@ -87,13 +87,13 @@ function parseResult (api: ApiInterfaceRx, sessionInfo: DerivedSessionInfo, quer /** * @description From a stash, retrieve the controllerId and fill in all the relevant staking details */ -export function account (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable { - return memo((accountId: Uint8Array | string): Observable => +export function account (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable { + return memo((accountId: Uint8Array | string): Observable => combineLatest([ api.derive.session.info(), api.derive.staking.query(accountId) ]).pipe( - map(([sessionInfo, query]: [DerivedSessionInfo, DerivedStakingQuery]) => + map(([sessionInfo, query]: [DeriveSessionInfo, DeriveStakingQuery]) => parseResult(api, sessionInfo, query)) )); } diff --git a/packages/api-derive/src/staking/electedInfo.ts b/packages/api-derive/src/staking/electedInfo.ts index cad7315960..546edb4220 100644 --- a/packages/api-derive/src/staking/electedInfo.ts +++ b/packages/api-derive/src/staking/electedInfo.ts @@ -4,27 +4,27 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { AccountId } from '@polkadot/types/interfaces'; -import { DerivedStakingQuery, DerivedStakingElected } from '../types'; +import { DeriveStakingQuery, DeriveStakingElected } from '../types'; import { Observable, combineLatest, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { memo } from '../util'; -export function electedInfo (api: ApiInterfaceRx): () => Observable { - return memo((): Observable => +export function electedInfo (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => api.derive.staking.validators().pipe( - switchMap(({ nextElected }): Observable<[AccountId[], DerivedStakingQuery[]]> => + switchMap(({ nextElected }): Observable<[AccountId[], DeriveStakingQuery[]]> => combineLatest([ of(nextElected), combineLatest( - nextElected.map((accountId): Observable => + nextElected.map((accountId): Observable => api.derive.staking.query(accountId) ) ) ]) ), - map(([nextElected, info]): DerivedStakingElected => ({ + map(([nextElected, info]): DeriveStakingElected => ({ info, nextElected })) diff --git a/packages/api-derive/src/staking/overview.ts b/packages/api-derive/src/staking/overview.ts index 48a2df3830..11dbea5975 100644 --- a/packages/api-derive/src/staking/overview.ts +++ b/packages/api-derive/src/staking/overview.ts @@ -4,7 +4,7 @@ import { AccountId, EraPoints, EraRewardPoints, RewardPoint } from '@polkadot/types/interfaces'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { DerivedStakingOverview } from '../types'; +import { DeriveStakingOverview } from '../types'; import { Observable, combineLatest, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; @@ -29,8 +29,8 @@ function retrievePointsPrev (api: ApiInterfaceRx, currentElected: AccountId[]): /** * @description Retrieve the staking overview, including elected and points earned */ -export function overview (api: ApiInterfaceRx): () => Observable { - return memo((): Observable => +export function overview (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => combineLatest([ api.derive.session.indexes(), api.derive.staking.validators() @@ -45,7 +45,7 @@ export function overview (api: ApiInterfaceRx): () => Observable ({ + map(([info, eraPoints]): DeriveStakingOverview => ({ ...info, eraPoints })) )); diff --git a/packages/api-derive/src/staking/query.ts b/packages/api-derive/src/staking/query.ts index 9999a6a848..7ffc05978b 100644 --- a/packages/api-derive/src/staking/query.ts +++ b/packages/api-derive/src/staking/query.ts @@ -5,7 +5,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { AccountId, Exposure, Keys, Nominations, RewardDestination, ValidatorPrefs } from '@polkadot/types/interfaces'; import { ITuple } from '@polkadot/types/types'; -import { DerivedStakingQuery } from '../types'; +import { DeriveStakingQuery } from '../types'; import { Observable, combineLatest, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; @@ -55,13 +55,13 @@ function retrieveCurr (api: ApiInterfaceRx, stashId: AccountId): Observable>, MultiResult]): Observable { +function retrieveController (api: ApiInterfaceRx, stashId: AccountId, [queuedKeys, [controllerIdOpt, nominatorsOpt, rewardDestination, validatorPrefs, nextKeys, exposure]]: [Vec>, MultiResult]): Observable { const controllerId = controllerIdOpt.unwrapOr(null); const nominators = nominatorsOpt.unwrapOr(null); return controllerId ? api.query.staking.ledger(controllerId).pipe( - map((stakingLedgerOpt): DerivedStakingQuery => ({ + map((stakingLedgerOpt): DeriveStakingQuery => ({ accountId: stashId, controllerId, exposure, @@ -85,8 +85,8 @@ function retrieveController (api: ApiInterfaceRx, stashId: AccountId, [queuedKey /** * @description From a stash, retrieve the controllerId and all relevant details */ -export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable { - return memo((accountId: Uint8Array | string): Observable => { +export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable { + return memo((accountId: Uint8Array | string): Observable => { const stashId = api.registry.createType('AccountId', accountId); return combineLatest([ @@ -95,15 +95,15 @@ export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) => ? retrieveCurr(api, stashId) : retrievePrev(api, stashId) ]).pipe( - switchMap((result): Observable => + switchMap((result): Observable => retrieveController(api, stashId, result) ) ); }); } -export function queryMulti (api: ApiInterfaceRx): (...accountIds: (Uint8Array | string)[]) => Observable { - return memo((...accountIds: (Uint8Array | string)[]): Observable => +export function queryMulti (api: ApiInterfaceRx): (...accountIds: (Uint8Array | string)[]) => Observable { + return memo((...accountIds: (Uint8Array | string)[]): Observable => combineLatest( accountIds.map((accountId) => api.derive.staking.query(accountId)) ) diff --git a/packages/api-derive/src/staking/types.ts b/packages/api-derive/src/staking/types.ts index a896f1259d..344f0f7955 100644 --- a/packages/api-derive/src/staking/types.ts +++ b/packages/api-derive/src/staking/types.ts @@ -79,9 +79,9 @@ export interface DeriveStakerSlashes { total: Balance; } -export interface DerivedStakingElected { +export interface DeriveStakingElected { nextElected: AccountId[]; - info: DerivedStakingQuery[]; + info: DeriveStakingQuery[]; } export interface DeriveStakingValidators { @@ -89,7 +89,7 @@ export interface DeriveStakingValidators { validators: AccountId[]; } -export interface DerivedStakingStash { +export interface DeriveStakingStash { controllerId?: AccountId; exposure?: Exposure; nominators?: AccountId[]; @@ -100,25 +100,25 @@ export interface DerivedStakingStash { validatorPrefs?: ValidatorPrefs; } -export interface DerivedStakingQuery extends DerivedStakingStash { +export interface DeriveStakingQuery extends DeriveStakingStash { accountId: AccountId; nextSessionIds: AccountId[]; sessionIds: AccountId[]; stakingLedger?: StakingLedger; } -export interface DerivedStakingAccount extends DerivedStakingQuery { +export interface DeriveStakingAccount extends DeriveStakingQuery { redeemable?: Balance; - unlocking?: DerivedUnlocking[]; + unlocking?: DeriveUnlocking[]; } -export interface DerivedStakingOverview extends DeriveSessionIndexes { +export interface DeriveStakingOverview extends DeriveSessionIndexes { eraPoints: EraRewardPoints; nextElected: AccountId[]; validators: AccountId[]; } -export type DerivedUnlocking = { +export type DeriveUnlocking = { remainingBlocks: BlockNumber; value: Balance; }; diff --git a/packages/api-derive/src/technicalCommittee/proposals.ts b/packages/api-derive/src/technicalCommittee/proposals.ts index 7eab5b1309..66e1bbae31 100644 --- a/packages/api-derive/src/technicalCommittee/proposals.ts +++ b/packages/api-derive/src/technicalCommittee/proposals.ts @@ -3,12 +3,12 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ApiInterfaceRx } from '@polkadot/api/types'; -import { DerivedCollectiveProposals } from '../types'; +import { DeriveCollectiveProposals } from '../types'; import { Observable } from 'rxjs'; import { proposals as collectiveProposals } from '../collective'; import { memo } from '../util'; -export function proposals (api: ApiInterfaceRx): () => Observable { +export function proposals (api: ApiInterfaceRx): () => Observable { return memo(collectiveProposals(api, 'technicalCommittee')); } diff --git a/packages/api-derive/src/treasury/proposals.ts b/packages/api-derive/src/treasury/proposals.ts index bb60779a3f..5cda8187f9 100644 --- a/packages/api-derive/src/treasury/proposals.ts +++ b/packages/api-derive/src/treasury/proposals.ts @@ -4,7 +4,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { ProposalIndex, TreasuryProposal } from '@polkadot/types/interfaces'; -import { DerivedCollectiveProposals, DerivedTreasuryProposal, DerivedTreasuryProposals } from '../types'; +import { DeriveCollectiveProposals, DeriveTreasuryProposal, DeriveTreasuryProposals } from '../types'; import { Observable, combineLatest, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; @@ -16,13 +16,13 @@ interface Result { allIds: ProposalIndex[]; allProposals: Option[]; approvalIds: ProposalIndex[]; - councilProposals: DerivedCollectiveProposals; + councilProposals: DeriveCollectiveProposals; proposalCount: ProposalIndex; } -function parseResult (_api: ApiInterfaceRx, { allIds, allProposals, approvalIds, councilProposals, proposalCount }: Result): DerivedTreasuryProposals { - const approvals: DerivedTreasuryProposal[] = []; - const proposals: DerivedTreasuryProposal[] = []; +function parseResult (_api: ApiInterfaceRx, { allIds, allProposals, approvalIds, councilProposals, proposalCount }: Result): DeriveTreasuryProposals { + const approvals: DeriveTreasuryProposal[] = []; + const proposals: DeriveTreasuryProposal[] = []; const councilTreasury = councilProposals.filter(({ proposal: { methodName, sectionName } }): boolean => sectionName === 'treasury' && ['approveProposal', 'rejectProposal'].includes(methodName) @@ -47,7 +47,7 @@ function parseResult (_api: ApiInterfaceRx, { allIds, allProposals, approvalIds, return { approvals, proposalCount, proposals }; } -function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, approvalIds: ProposalIndex[]): Observable { +function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, approvalIds: ProposalIndex[]): Observable { const proposalIds: ProposalIndex[] = []; const count = proposalCount.toNumber(); @@ -65,7 +65,7 @@ function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, a api.query.treasury.proposals.multi>(allIds), api.derive.council.proposals() ]).pipe( - map(([allProposals, councilProposals]: [Option[], DerivedCollectiveProposals]): DerivedTreasuryProposals => + map(([allProposals, councilProposals]: [Option[], DeriveCollectiveProposals]): DeriveTreasuryProposals => parseResult(api, { allIds, allProposals, approvalIds, councilProposals, proposalCount }) ) ); @@ -74,8 +74,8 @@ function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, a /** * @description Retrieve all active and approved treasury proposals, along with their info */ -export function proposals (api: ApiInterfaceRx): () => Observable { - return memo((): Observable => +export function proposals (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => api.query.treasury ? combineLatest([ api.query.treasury.proposalCount(), @@ -89,6 +89,6 @@ export function proposals (api: ApiInterfaceRx): () => Observable; +export type DeriveBalancesMap = Record; -export interface DerivedContractFees { +export interface DeriveContractFees { callBaseFee: BN; contractFee: BN; creationFee: BN; @@ -77,15 +77,15 @@ export interface DerivedContractFees { transferFee: BN; } -export interface DerivedCollectiveProposal { +export interface DeriveCollectiveProposal { hash: Hash; proposal: Proposal; votes: Votes | null; } -export type DerivedCollectiveProposals = DerivedCollectiveProposal[]; +export type DeriveCollectiveProposals = DeriveCollectiveProposal[]; -export interface DerivedElectionsInfo { +export interface DeriveElectionsInfo { candidates: AccountId[]; candidateCount: u32; candidacyBond?: Balance; @@ -99,7 +99,7 @@ export interface DerivedElectionsInfo { votingBond?: Balance; } -export interface DerivedFees { +export interface DeriveFees { creationFee: Balance; existentialDeposit: Balance; transactionBaseFee: Balance; @@ -107,20 +107,20 @@ export interface DerivedFees { transferFee: Balance; } -export interface DerivedHeartbeatAuthor { +export interface DeriveHeartbeatAuthor { blockCount: u32; hasMessage: boolean; isOnline: boolean; } -export type DerivedHeartbeats = Record; +export type DeriveHeartbeats = Record; export interface RecentlyOffline { blockNumber: BlockNumber; count: BN; } -export type DerivedRecentlyOffline = Record; +export type DeriveRecentlyOffline = Record; export interface DeriveSociety { bids: Bid[]; @@ -148,16 +148,16 @@ export interface DeriveSocietyMember { vouching?: VouchingStatus; } -export interface DerivedTreasuryProposal { - council: DerivedCollectiveProposal[]; +export interface DeriveTreasuryProposal { + council: DeriveCollectiveProposal[]; id: ProposalIndex; proposal: TreasuryProposal; } -export interface DerivedTreasuryProposals { - approvals: DerivedTreasuryProposal[]; +export interface DeriveTreasuryProposals { + approvals: DeriveTreasuryProposal[]; proposalCount: ProposalIndex; - proposals: DerivedTreasuryProposal[]; + proposals: DeriveTreasuryProposal[]; } export interface VoterPosition { @@ -166,4 +166,4 @@ export interface VoterPosition { setIndex: SetIndex; } -export type DerivedVoterPositions = Record; +export type DeriveVoterPositions = Record;