Use ReferendumInfo from Tuple (#513)
* Use ReferendumInfo from Tuple * Cleanup linting * Bump deps
This commit is contained in:
@@ -8,12 +8,12 @@ import BN from 'bn.js';
|
||||
import { EMPTY, Observable, from } from 'rxjs';
|
||||
import { switchMap, defaultIfEmpty, map } from 'rxjs/operators';
|
||||
import { decodeAddress } from '@polkadot/keyring';
|
||||
import { AccountId, AccountIndex, Balance, bool as Bool, BlockNumber, Moment, ReferendumIndex } from '@polkadot/types/index';
|
||||
import { AccountId, AccountIndex, Balance, bool as Bool, BlockNumber, Moment, ReferendumIndex, ReferendumInfo } from '@polkadot/types/index';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/AccountIndex';
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import ApiCalls from './Calls';
|
||||
import { RxProposal, RxReferendum } from './classes';
|
||||
import { RxProposal } from './classes';
|
||||
|
||||
// Combines API calls and queries into single results. This allows for the exposed API to have
|
||||
// useful extensions, i.e. queries can be made that returns the results from multiple observables,
|
||||
@@ -122,12 +122,12 @@ export default class ApiCombined extends ApiCalls {
|
||||
);
|
||||
}
|
||||
|
||||
referendumsInfo = (referendumIds: Array<ReferendumIndex | BN | number>): Observable<Array<RxReferendum>> => {
|
||||
referendumsInfo = (referendumIds: Array<ReferendumIndex | BN | number>): Observable<Array<ReferendumInfo>> => {
|
||||
return this.combine(
|
||||
referendumIds.map((referendumId) =>
|
||||
this.referendumInfo(referendumId)
|
||||
),
|
||||
(referendums: Array<RxReferendum> = []): Array<RxReferendum> =>
|
||||
(referendums: Array<ReferendumInfo> = []): Array<ReferendumInfo> =>
|
||||
referendums.filter((referendum) =>
|
||||
referendum
|
||||
)
|
||||
@@ -150,7 +150,7 @@ export default class ApiCombined extends ApiCalls {
|
||||
);
|
||||
}
|
||||
|
||||
referendums = (): Observable<Array<RxReferendum>> => {
|
||||
referendums = (): Observable<Array<ReferendumInfo>> => {
|
||||
return this.combine(
|
||||
[
|
||||
this.referendumCount(),
|
||||
|
||||
@@ -7,11 +7,11 @@ import { RxFees } from './types';
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { AccountId, AccountIndex, Balance, bool as Bool, BlockNumber, EventRecord, Index, Moment, Perbill, PropIndex, ReferendumIndex, u32 } from '@polkadot/types/index';
|
||||
import { AccountId, AccountIndex, Balance, bool as Bool, BlockNumber, EventRecord, Index, Moment, Perbill, PropIndex, ReferendumIndex, ReferendumInfo, u32 } from '@polkadot/types/index';
|
||||
import { Tuple } from '@polkadot/types/codec';
|
||||
|
||||
import ApiBase from './Base';
|
||||
import { RxProposal, RxProposalDeposits, RxReferendum } from './classes';
|
||||
import { RxProposal, RxProposalDeposits } from './classes';
|
||||
|
||||
// Perform storage queries to the API endpoints.
|
||||
export default class ApiQueries extends ApiBase {
|
||||
@@ -94,14 +94,14 @@ export default class ApiQueries extends ApiBase {
|
||||
return this.rawStorage(ApiBase.storage.democracy.referendumCount);
|
||||
}
|
||||
|
||||
referendumInfo = (referendumId: ReferendumIndex | BN | number): Observable<RxReferendum | undefined> => {
|
||||
referendumInfo = (referendumId: ReferendumIndex | BN | number): Observable<ReferendumInfo | undefined> => {
|
||||
return this
|
||||
.rawStorage(ApiBase.storage.democracy.referendumInfoOf, referendumId)
|
||||
.pipe(
|
||||
// @ts-ignore After upgrade to 6.3.2
|
||||
map((result: Tuple): RxReferendum | undefined =>
|
||||
map((result: Tuple) =>
|
||||
result
|
||||
? new RxReferendum(result, referendumId)
|
||||
? result[0]
|
||||
: undefined
|
||||
)
|
||||
);
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { AccountId, Balance, BlockNumber, PropIndex, Proposal, ReferendumIndex, VoteThreshold } from '@polkadot/types/index';
|
||||
import { AccountId, Balance, PropIndex, Proposal } from '@polkadot/types/index';
|
||||
import { Constructor } from '@polkadot/types/types';
|
||||
import { Struct, Tuple, Vector } from '@polkadot/types/codec';
|
||||
|
||||
@@ -49,32 +48,3 @@ export class RxProposalDeposits extends DepositStruct {
|
||||
return this.get('balance') as Balance;
|
||||
}
|
||||
}
|
||||
|
||||
const ReferendumStruct: Constructor<Struct<any>> = Struct.with({ blockNumber: BlockNumber, proposal: Proposal, voteThreshold: VoteThreshold, id: ReferendumIndex });
|
||||
|
||||
export class RxReferendum extends ReferendumStruct {
|
||||
constructor (value: Tuple, id: ReferendumIndex | BN | number) {
|
||||
super({
|
||||
blockNumber: value[0],
|
||||
proposal: value[1],
|
||||
voteThreshold: value[2],
|
||||
id
|
||||
});
|
||||
}
|
||||
|
||||
get blockNumber (): BlockNumber {
|
||||
return this.get('blockNumber') as BlockNumber;
|
||||
}
|
||||
|
||||
get id (): ReferendumIndex {
|
||||
return this.get('id') as ReferendumIndex;
|
||||
}
|
||||
|
||||
get proposal (): Proposal {
|
||||
return this.get('proposal') as Proposal;
|
||||
}
|
||||
|
||||
get voteThreshold (): VoteThreshold {
|
||||
return this.get('voteThreshold') as VoteThreshold;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user