Optional preImage & Proposal for democracy

This commit is contained in:
Jaco Greeff
2019-12-03 13:01:13 +01:00
parent d86c5be413
commit afbe072ad5
3 changed files with 31 additions and 19 deletions
+11 -7
View File
@@ -48,19 +48,23 @@ export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal
!!(_preImages[index]?.isSome) && !!(_depositors[index]?.isSome) && !proposer.isEmpty
)
.map(([propIndex, hash, proposer], index): DeriveProposal => {
const preImage = _preImages[index].unwrap();
const preImage = _preImages[index].unwrapOr(null);
const depositors = _depositors[index].unwrap();
return {
balance: depositors[0],
hash,
index: propIndex,
preimage: {
at: preImage[3],
balance: preImage[2],
proposer: preImage[1]
},
proposal: createType(api.registry, 'Proposal', preImage[0].toU8a(true)),
preimage: preImage
? {
at: preImage[3],
balance: preImage[2],
proposer: preImage[1]
}
: undefined,
proposal: preImage
? createType(api.registry, 'Proposal', preImage[0].toU8a(true))
: undefined,
proposer,
seconds: depositors[1]
};
@@ -15,12 +15,14 @@ import { Option, createType } from '@polkadot/types';
import { memo } from '../util';
function constructInfo (api: ApiInterfaceRx, index: BN | number, _info: Option<ReferendumInfo>, _preimage?: PreImage): DerivedReferendum | null {
console.log(JSON.stringify(_info), JSON.stringify(_preimage));
const preImage = _preimage?.isSome
? _preimage.unwrap()
: null;
const info = (_preimage && _info.unwrapOr(null)) || null;
const info = _info.unwrapOr(null);
if (!info || !preImage) {
if (!info) {
return null;
}
@@ -28,16 +30,22 @@ function constructInfo (api: ApiInterfaceRx, index: BN | number, _info: Option<R
index: createType(api.registry, 'PropIndex', index),
info,
hash: info.proposalHash,
proposal: createType(api.registry, 'Proposal', preImage[0].toU8a(true)),
preimage: {
at: preImage[3],
balance: preImage[2],
proposer: preImage[1]
}
proposal: preImage
? createType(api.registry, 'Proposal', preImage[0].toU8a(true))
: undefined,
preimage: preImage
? {
at: preImage[3],
balance: preImage[2],
proposer: preImage[1]
}
: undefined
};
}
export function retrieveInfo (api: ApiInterfaceRx, index: BN | number, info: Option<ReferendumInfo>): Observable<DerivedReferendum | null> {
console.log(JSON.stringify(info));
return ((
info?.isSome
? api.query.democracy.preimages<PreImage>(info.unwrap().proposalHash)
+4 -4
View File
@@ -89,8 +89,8 @@ export interface DeriveProposal {
balance?: Balance;
hash: Hash;
index: PropIndex;
preimage: DeriveProposalPreImage;
proposal: Proposal;
preimage?: DeriveProposalPreImage;
proposal?: Proposal;
proposer: AccountId;
seconds: Vec<AccountId>;
}
@@ -99,8 +99,8 @@ export interface DerivedReferendum {
hash: Hash;
index: PropIndex;
info: ReferendumInfo;
preimage: DeriveProposalPreImage;
proposal: Proposal;
preimage?: DeriveProposalPreImage;
proposal?: Proposal;
}
export type DerivedRecentlyOffline = Record<string, RecentlyOffline[]>;