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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@
|
||||
"@polkadot/jsonrpc": "^0.35.7",
|
||||
"@polkadot/rpc-provider": "^0.35.7",
|
||||
"@polkadot/types": "^0.35.7",
|
||||
"@polkadot/util": "^0.33.24"
|
||||
"@polkadot/util": "^0.33.25"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/keyring": "^0.33.24",
|
||||
"@polkadot/keyring": "^0.33.25",
|
||||
"@polkadot/storage": "^0.35.7",
|
||||
"@polkadot/util": "^0.33.24",
|
||||
"@polkadot/util-crypto": "^0.33.24",
|
||||
"@polkadot/util": "^0.33.25",
|
||||
"@polkadot/util-crypto": "^0.33.25",
|
||||
"@types/nock": "^9.3.0",
|
||||
"eventemitter3": "^3.1.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
|
||||
@@ -12,6 +12,6 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/types": "^0.35.7",
|
||||
"@polkadot/util": "^0.33.24"
|
||||
"@polkadot/util": "^0.33.25"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-storage#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/keyring": "^0.33.24",
|
||||
"@polkadot/keyring": "^0.33.25",
|
||||
"@polkadot/types": "^0.35.7",
|
||||
"@polkadot/util": "^0.33.24",
|
||||
"@polkadot/util-crypto": "^0.33.24"
|
||||
"@polkadot/util": "^0.33.25",
|
||||
"@polkadot/util-crypto": "^0.33.25"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/keyring": "^0.33.24",
|
||||
"@polkadot/util": "^0.33.24",
|
||||
"@polkadot/keyring": "^0.33.25",
|
||||
"@polkadot/util": "^0.33.25",
|
||||
"core-js": "^2.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1417,14 +1417,14 @@
|
||||
typedoc-plugin-no-inherit "^1.0.2"
|
||||
typescript "^3.2.2"
|
||||
|
||||
"@polkadot/keyring@^0.33.24":
|
||||
version "0.33.24"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.33.24.tgz#7c68dc06dd53b70f7c3e6bf3ec0acce4486da206"
|
||||
integrity sha512-D1Dtrp4f/S8IRa9ZaSjbnWQ4PjJWK+bs8AOfgqoaHLlrFvXf31ipE8MYgODB0EMFDNCf8RLqr8ftG3vVsRF+vw==
|
||||
"@polkadot/keyring@^0.33.25":
|
||||
version "0.33.25"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.33.25.tgz#382a7a863e90bd3ad8f683afc291dd1ffb04cf84"
|
||||
integrity sha512-LtRZSTL0Qk74QZeGTbBvuOK09tlgzI0zI0zccvfH7dhp8CnCGundicAe/5v9MPYNyGeap5Ur5nOnT3E/vFxhtw==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.2.0"
|
||||
"@polkadot/util" "^0.33.24"
|
||||
"@polkadot/util-crypto" "^0.33.24"
|
||||
"@polkadot/util" "^0.33.25"
|
||||
"@polkadot/util-crypto" "^0.33.25"
|
||||
"@types/bs58" "^3.0.30"
|
||||
bs58 "^4.0.1"
|
||||
|
||||
@@ -1433,13 +1433,13 @@
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.44.tgz#2fb28215f10b869bfa544fd8df8fccb4932d64f2"
|
||||
integrity sha512-tor7vSd3ZsRBO9FIuKZQ9hfqEGkNZnanAFVGmoL1iSmdhcoKtYTlQe0BQafjIynqIMOfXdJ7Zes9PlorPtw6yw==
|
||||
|
||||
"@polkadot/util-crypto@^0.33.24":
|
||||
version "0.33.24"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.33.24.tgz#9b29f4aaeb2c475b38c3007816c9f0ffb74892ca"
|
||||
integrity sha512-obs13hyBtO9TZ3MkleMvlWinDZUSj+59DkVndbfD8HX9hEzcs6LBWGwzKYh3Ad8wsbfpeebY/cugvtGXswzF3g==
|
||||
"@polkadot/util-crypto@^0.33.25":
|
||||
version "0.33.25"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.33.25.tgz#efb9912373c7ae40d3572e03a40da38e546ca244"
|
||||
integrity sha512-nNggPMJjcWMmO3TbbKw/cColel1rCN7S6yz6DlB0UNPqsLIW7APXLWW/LtrrbTSpyMDn+nCE5aLtyMoJPqKnvA==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.2.0"
|
||||
"@polkadot/util" "^0.33.24"
|
||||
"@polkadot/util" "^0.33.25"
|
||||
"@types/bip39" "^2.4.1"
|
||||
bip39 "^2.5.0"
|
||||
blakejs "^1.1.0"
|
||||
@@ -1447,10 +1447,10 @@
|
||||
tweetnacl "^1.0.0"
|
||||
xxhashjs "^0.2.2"
|
||||
|
||||
"@polkadot/util@^0.33.24":
|
||||
version "0.33.24"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.33.24.tgz#c8d3a765b65e99dca3bc0f8d44f5b0e21a926e92"
|
||||
integrity sha512-AKBmNjwdidJ95DG2alSibO4tDFBuLjYCpPSLWmb5CfU6UFO70vpsskaoBpJPSrvJaT+EgvgcDpDewSUCb4GLbQ==
|
||||
"@polkadot/util@^0.33.25":
|
||||
version "0.33.25"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.33.25.tgz#18c29b1696c0e28eec85b9abd3e9b6cfabeea4dc"
|
||||
integrity sha512-pVhnKpLSYNxwL58hPAcIrF0SbJttZdFX3N6RkuQ3sEO2fnGVn993jc0RGKo29TNJD8RM5PBbnmM56W/rpm6Wpw==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.2.0"
|
||||
"@types/bn.js" "^4.11.3"
|
||||
|
||||
Reference in New Issue
Block a user