Decode scheduler Lookup entries (#8487)

* Decode scheduler Lookup entries

* short hashes
This commit is contained in:
Jaco 2022-12-06 07:36:44 +02:00 committed by GitHub
parent 86f62e09c9
commit ddfe4ba9c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 10 deletions

View File

@ -6,6 +6,8 @@ import type { ScheduledExt } from './types';
import React from 'react';
import Hash from '@polkadot/app-preimages/Preimages/Hash';
import usePreimage from '@polkadot/app-preimages/usePreimage';
import { CallExpander } from '@polkadot/react-components';
import { BlockToTime } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';
@ -16,22 +18,23 @@ interface Props {
value: ScheduledExt;
}
function Scheduled ({ bestNumber, className = '', value: { blockNumber, call, maybeId, maybePeriodic } }: Props): React.ReactElement<Props> {
function Scheduled ({ bestNumber, className = '', value: { blockNumber, call, maybeId, maybePeriodic, preimageHash } }: Props): React.ReactElement<Props> {
const preimage = usePreimage(preimageHash);
const period = maybePeriodic.unwrapOr(null);
const name = maybeId.unwrapOr(null);
return (
<tr className={className}>
<td className='all'>
<CallExpander value={call} />
</td>
<td className='start'>
{name && (
name.isAscii
? name.toUtf8()
: name.toHex()
)}
<CallExpander value={call || preimage?.proposal} />
</td>
{name
? name.isAscii
? <td className='start'>{name.toUtf8()}</td>
: <Hash value={name.toHex()} />
: <td />
}
<td className='number together'>
{bestNumber && (
<>

View File

@ -52,6 +52,7 @@ const OPT_SCHED = {
.map((o) => o.unwrap())
.reduce((items: ScheduledExt[], { call: callOrEnum, maybeId, maybePeriodic, priority }, index) => {
let call: Call | null = null;
let preimageHash: FrameSupportPreimagesBounded | undefined;
if ((callOrEnum as unknown as FrameSupportScheduleMaybeHashed).inner) {
if ((callOrEnum as unknown as FrameSupportScheduleMaybeHashed).isValue) {
@ -62,12 +63,14 @@ const OPT_SCHED = {
} catch (error) {
console.error(error);
}
} else if ((callOrEnum as unknown as FrameSupportPreimagesBounded).isLookup) {
preimageHash = (callOrEnum as unknown as FrameSupportPreimagesBounded);
}
} else {
call = callOrEnum as Call;
}
items.push({ blockNumber, call, key: `${blockNumber.toString()}-${index}`, maybeId, maybePeriodic, priority });
items.push({ blockNumber, call, key: `${blockNumber.toString()}-${index}`, maybeId, maybePeriodic, preimageHash, priority });
return items;
}, items);

View File

@ -3,6 +3,7 @@
import type { Bytes, Option } from '@polkadot/types';
import type { BlockNumber, Call, SchedulePeriod, SchedulePriority } from '@polkadot/types/interfaces';
import type { FrameSupportPreimagesBounded } from '@polkadot/types/lookup';
export interface ScheduledExt {
blockNumber: BlockNumber;
@ -11,4 +12,5 @@ export interface ScheduledExt {
maybeId: Option<Bytes>;
maybePeriodic: Option<SchedulePeriod>;
priority: SchedulePriority;
preimageHash?: FrameSupportPreimagesBounded;
}