@polkadot/types/interfaces#ParaValidatorIndex TypeScript Examples
The following examples show how to use
@polkadot/types/interfaces#ParaValidatorIndex.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Parachains.tsx From crust-apps with Apache License 2.0 | 6 votes |
function mapValidators (ids?: ParaId[], validators?: AccountId[] | null, validatorGroups?: ParaValidatorIndex[][] | null): AccountId[][] {
return validators && validatorGroups && ids && ids.length === validatorGroups.length
? validatorGroups.map((ids) =>
ids
.map((id) => validators[id.toNumber()])
.filter((a) => a)
)
: [];
}
Example #2
Source File: Parachains.tsx From crust-apps with Apache License 2.0 | 5 votes |
function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const bestNumber = useBestNumber();
const lastBlock = useCall<SignedBlockExtended>(api.derive.chain.subscribeNewBlocks);
const [{ lastBacked, lastIncluded, lastTimeout }, setLastEvents] = useState<LastEvents>(EMPTY_EVENTS);
const [validators, validatorGroups] = useCallMulti<[AccountId[] | null, ParaValidatorIndex[][] | null]>([
api.query.session?.validators,
api.query.paraScheduler?.validatorGroups || api.query.scheduler?.validatorGroups
], optionsMulti);
const headerRef = useRef([
[t('parachains'), 'start', 2],
['', 'media--1500'],
[t('head'), 'start'],
[t('lifecycle'), 'start media--1100'],
[],
[t('included'), undefined, 2],
[t('backed'), 'no-pad-left'],
[t('timeout'), 'no-pad-left'],
[t('chain best'), 'media--900 no-pad-left'],
[t('upgrade'), 'media--1300'],
[t('ump/dmp/hrmp'), 'media--1200']
]);
const scheduledIds = useMemo(
() => extractScheduledIds(scheduled),
[scheduled]
);
const validatorMap = useMemo(
() => mapValidators(ids, validators, validatorGroups),
[ids, validators, validatorGroups]
);
const knownIds = useMemo(
() => ids?.map((id): [ParaId, string] => [id, id.toString()]),
[ids]
);
const nextActions = useMemo(
() => extractActions(actionsQueue, knownIds),
[actionsQueue, knownIds]
);
useEffect((): void => {
lastBlock && setLastEvents((prev) =>
extractEvents(api, lastBlock, prev)
);
}, [api, lastBlock]);
return (
<Table
empty={knownIds && t<string>('There are no registered parachains')}
header={headerRef.current}
>
{knownIds?.map(([id, key], index): React.ReactNode => (
<Parachain
bestNumber={bestNumber}
id={id}
isScheduled={scheduledIds[key]}
key={key}
lastBacked={lastBacked[key]}
lastInclusion={lastIncluded[key]}
lastTimeout={lastTimeout[key]}
nextAction={nextActions[key]}
sessionValidators={validators}
validators={validatorMap[index]}
/>
))}
</Table>
);
}
Example #3
Source File: Parachains.tsx From crust-apps with Apache License 2.0 | 5 votes |
optionsMulti = {
defaultValue: [null, null] as [AccountId[] | null, ParaValidatorIndex[][] | null]
}