Optional preImage & Proposal for democracy
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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[]>;
|
||||
|
||||
Reference in New Issue
Block a user