Additional derive cleanups (#4299)
* Additional derive cleanups * map var * Apply suggestions from code review * Additional * Metadata cleanups * Adjust * Apply HexString to all Metadata init * typegen HexString * generator HexString * basepath
This commit is contained in:
@@ -40,15 +40,11 @@ function parseFlags (address: AccountId | Address | string | null | undefined, [
|
||||
*/
|
||||
export function flags (instanceId: string, api: ApiInterfaceRx): (address?: AccountId | Address | string | null) => Observable<DeriveAccountFlags> {
|
||||
return memo(instanceId, (address?: AccountId | Address | string | null): Observable<DeriveAccountFlags> => {
|
||||
const councilSection = api.query.phragmenElection
|
||||
? 'phragmenElection'
|
||||
: api.query.electionsPhragmen
|
||||
? 'electionsPhragmen'
|
||||
: 'elections';
|
||||
const elections = api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections;
|
||||
|
||||
return combineLatest([
|
||||
address && api.query[councilSection]?.members
|
||||
? api.query[councilSection].members<Vec<ITuple<[AccountId, Balance]>>>()
|
||||
address && elections?.members
|
||||
? elections.members<Vec<ITuple<[AccountId, Balance]>>>()
|
||||
: of(undefined),
|
||||
address && api.query.council?.members
|
||||
? api.query.council.members()
|
||||
@@ -63,7 +59,7 @@ export function flags (instanceId: string, api: ApiInterfaceRx): (address?: Acco
|
||||
? api.query.sudo.key()
|
||||
: of(undefined)
|
||||
]).pipe(
|
||||
map((result) => parseFlags(address, result))
|
||||
map((r) => parseFlags(address, r))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -165,9 +165,7 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId, balanceInstanc
|
||||
|
||||
return [
|
||||
vesting
|
||||
? Array.isArray(vesting)
|
||||
? vesting
|
||||
: [vesting]
|
||||
? Array.isArray(vesting) ? vesting : [vesting]
|
||||
: null,
|
||||
lockEmpty.map((e) => e ? api.registry.createType<Vec<PalletBalancesBalanceLock>>('Vec<BalanceLock>') : locks[++offset])
|
||||
];
|
||||
|
||||
@@ -42,14 +42,12 @@ export function bounties (instanceId: string, api: ApiInterfaceRx): () => Observ
|
||||
? api.query.council.proposalCount<ProposalIndex>()
|
||||
: of(0)
|
||||
]).pipe(
|
||||
switchMap(() =>
|
||||
combineLatest([
|
||||
bountyBase.bounties.keys<[BountyIndex]>(),
|
||||
api.derive.council
|
||||
? api.derive.council.proposals()
|
||||
: of([])
|
||||
])
|
||||
),
|
||||
switchMap(() => combineLatest([
|
||||
bountyBase.bounties.keys<[BountyIndex]>(),
|
||||
api.derive.council
|
||||
? api.derive.council.proposals()
|
||||
: of([])
|
||||
])),
|
||||
switchMap(([keys, proposals]): Observable<Result> => {
|
||||
const ids = keys.map(({ args: [id] }) => id);
|
||||
|
||||
|
||||
@@ -61,10 +61,8 @@ function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Opt
|
||||
// however we have had cases on Darwinia where the indices have moved around after an
|
||||
// upgrade, which results in invalid on-chain data
|
||||
combineLatest(blockNumbers.map((blockNumber) =>
|
||||
api.query.scheduler.agenda(blockNumber).pipe(
|
||||
// this does create an issue since it discards all at that block
|
||||
catchError(() => of(null))
|
||||
)
|
||||
// this does create an issue since it discards all at that block
|
||||
api.query.scheduler.agenda(blockNumber).pipe(catchError(() => of(null)))
|
||||
))
|
||||
])
|
||||
: of<[BlockNumber[], null[]]>([[], []]);
|
||||
@@ -78,30 +76,23 @@ function queryScheduler (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
|
||||
const result: SchedulerInfo[] = [];
|
||||
|
||||
blockNumbers.forEach((at, index): void => {
|
||||
(agendas[index] || [])
|
||||
.filter((opt) => opt.isSome)
|
||||
.forEach((optScheduled): void => {
|
||||
const scheduled = optScheduled.unwrap();
|
||||
(agendas[index] || []).filter((o) => o.isSome).forEach((o): void => {
|
||||
const scheduled = o.unwrap();
|
||||
|
||||
if (scheduled.maybeId.isSome) {
|
||||
const id = scheduled.maybeId.unwrap().toHex();
|
||||
if (scheduled.maybeId.isSome) {
|
||||
const id = scheduled.maybeId.unwrap().toHex();
|
||||
|
||||
if (id.startsWith(DEMOCRACY_ID)) {
|
||||
const [, index] = api.registry.createType('(u64, ReferendumIndex)', id);
|
||||
const imageHash = scheduled.call.args[0] as Hash;
|
||||
|
||||
result.push({ at, imageHash, index });
|
||||
}
|
||||
}
|
||||
});
|
||||
id.startsWith(DEMOCRACY_ID) && result.push({ at, imageHash: scheduled.call.args[0] as Hash, index: api.registry.createType('(u64, ReferendumIndex)', id)[1] });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return result.length
|
||||
? combineLatest([
|
||||
of(result),
|
||||
api.derive.democracy.preimages(result.map(({ imageHash }) => imageHash))
|
||||
])
|
||||
: of([[], []]);
|
||||
return combineLatest([
|
||||
of(result),
|
||||
result.length
|
||||
? api.derive.democracy.preimages(result.map(({ imageHash }) => imageHash))
|
||||
: of([])
|
||||
]);
|
||||
}),
|
||||
map(([infos, images]): DeriveDispatch[] =>
|
||||
infos.map((info, index) => ({ ...info, image: images[index] }))
|
||||
|
||||
@@ -42,6 +42,18 @@ function sortAccounts ([, balanceA]: [AccountId, Balance], [, balanceB]: [Accoun
|
||||
return balanceB.cmp(balanceA);
|
||||
}
|
||||
|
||||
function getConstants (api: ApiInterfaceRx, elections: string | null): Partial<DeriveElectionsInfo> {
|
||||
return elections
|
||||
? {
|
||||
candidacyBond: api.consts[elections].candidacyBond as Balance,
|
||||
desiredRunnersUp: api.consts[elections].desiredRunnersUp as u32,
|
||||
desiredSeats: api.consts[elections].desiredMembers as u32,
|
||||
termDuration: api.consts[elections].termDuration as BlockNumber,
|
||||
votingBond: api.consts[elections].votingBond as Balance
|
||||
}
|
||||
: {};
|
||||
}
|
||||
|
||||
function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> {
|
||||
const elections = api.query.phragmenElection
|
||||
? 'phragmenElection'
|
||||
@@ -68,17 +80,7 @@ function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> {
|
||||
])
|
||||
).pipe(
|
||||
map(([councilMembers, candidates, members, runnersUp]): DeriveElectionsInfo => ({
|
||||
...(
|
||||
elections
|
||||
? {
|
||||
candidacyBond: api.consts[elections].candidacyBond as Balance,
|
||||
desiredRunnersUp: api.consts[elections].desiredRunnersUp as u32,
|
||||
desiredSeats: api.consts[elections].desiredMembers as u32,
|
||||
termDuration: api.consts[elections].termDuration as BlockNumber,
|
||||
votingBond: api.consts[elections].votingBond as Balance
|
||||
}
|
||||
: {}
|
||||
),
|
||||
...getConstants(api, elections),
|
||||
candidateCount: api.registry.createType('u32', candidates.length),
|
||||
candidates: candidates.map(getCandidate),
|
||||
members: members.length
|
||||
|
||||
@@ -29,8 +29,8 @@ function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> |
|
||||
|
||||
function getLedgers (api: ApiInterfaceRx, optIds: (Option<AccountId> | null)[], { withLedger = false }: StakingQueryFlags): Observable<Option<PalletStakingStakingLedger>[]> {
|
||||
const ids = optIds
|
||||
.filter((opt): opt is Option<AccountId> => withLedger && !!opt && opt.isSome)
|
||||
.map((opt) => opt.unwrap());
|
||||
.filter((o): o is Option<AccountId> => withLedger && !!o && o.isSome)
|
||||
.map((o) => o.unwrap());
|
||||
const emptyLed = api.registry.createType<Option<PalletStakingStakingLedger>>('Option<StakingLedger>');
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user