mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-07-19 13:45:40 +00:00
971df8edba
- Remove all 3rd party parachain configurations from endpoints: - productionRelayPolkadot.ts: Keep only system parachains - productionRelayDicle.ts: Keep only system parachains - testingRelayZagros.ts: Keep only system parachains - testingRelayTeyrChain.ts: Keep only system parachains - Update domain references: - polkadot.js.org → pezkuwichain.app - wiki.polkadot.network → wiki.pezkuwichain.io - dotapps.io → pezkuwichain.app - statement.polkadot.network → docs.pezkuwichain.io/statement - support.polkadot.network → docs.pezkuwichain.io - Update repository references: - github.com/pezkuwi-js/apps → github.com/pezkuwichain/pwap - Rename system parachains to Pezkuwi ecosystem: - PolkadotAssetHub → PezkuwiAssetHub - polkadotBridgeHub → pezkuwiBridgeHub - polkadotCollectives → pezkuwiCollectives - polkadotCoretime → pezkuwiCoretime - polkadotPeople → pezkuwiPeople - Update network name in claims utility: - Polkadot → Pezkuwi
118 lines
4.1 KiB
TypeScript
118 lines
4.1 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/app-scheduler authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { ApiPromise } from '@pezkuwi/api';
|
|
import type { Bytes, Option, u8, u32 } from '@pezkuwi/types';
|
|
import type { BlockNumber, Call, Hash, Scheduled } from '@pezkuwi/types/interfaces';
|
|
import type { PezframeSupportPreimagesBounded, PezpalletSchedulerScheduled } from '@pezkuwi/types/lookup';
|
|
import type { Codec, ITuple } from '@pezkuwi/types/types';
|
|
import type { ScheduledExt } from './types.js';
|
|
|
|
import React, { useMemo, useRef } from 'react';
|
|
|
|
import { Table } from '@pezkuwi/react-components';
|
|
import { useApi, useBestNumberRelay, useCall } from '@pezkuwi/react-hooks';
|
|
|
|
import ScheduledView from './Scheduled.js';
|
|
import { useTranslation } from './translate.js';
|
|
|
|
interface Props {
|
|
className?: string;
|
|
}
|
|
|
|
// included here for backwards compat
|
|
interface PezpalletSchedulerScheduledV3 extends Codec {
|
|
maybeId: Option<Bytes>;
|
|
priority: u8;
|
|
call: PezframeSupportScheduleMaybeHashed;
|
|
maybePeriodic: Option<ITuple<[u32, u32]>>;
|
|
origin: Codec;
|
|
}
|
|
|
|
// included here for backwards compat
|
|
interface PezframeSupportScheduleMaybeHashed extends Codec {
|
|
// added here since we use it for detection
|
|
inner: Codec;
|
|
// enum features
|
|
isHash: boolean;
|
|
isValue: boolean;
|
|
asValue: Call;
|
|
asHash: Hash;
|
|
}
|
|
|
|
const OPT_SCHED = {
|
|
transform: (entries: [{ args: [BlockNumber] }, Option<Scheduled | PezpalletSchedulerScheduled | PezpalletSchedulerScheduledV3>[]][], api: ApiPromise): ScheduledExt[] => {
|
|
return entries
|
|
.filter(([, all]) => all.some((o) => o.isSome))
|
|
.reduce((items: ScheduledExt[], [key, all]): ScheduledExt[] => {
|
|
const blockNumber = key.args[0];
|
|
|
|
return all
|
|
.filter((o) => o.isSome)
|
|
.map((o) => o.unwrap())
|
|
.reduce((items: ScheduledExt[], { call: callOrEnum, maybeId, maybePeriodic, priority }, index) => {
|
|
let call: Call | null = null;
|
|
let preimageHash: PezframeSupportPreimagesBounded | undefined;
|
|
|
|
if ((callOrEnum as unknown as PezframeSupportScheduleMaybeHashed).inner) {
|
|
if ((callOrEnum as unknown as PezframeSupportScheduleMaybeHashed).isValue) {
|
|
call = (callOrEnum as unknown as PezframeSupportScheduleMaybeHashed).asValue;
|
|
} else if ((callOrEnum as unknown as PezframeSupportPreimagesBounded).isInline) {
|
|
try {
|
|
call = api.registry.createType('Call', (callOrEnum as unknown as PezframeSupportPreimagesBounded).asInline.toHex());
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
} else if ((callOrEnum as unknown as PezframeSupportPreimagesBounded).isLookup) {
|
|
preimageHash = (callOrEnum as unknown as PezframeSupportPreimagesBounded);
|
|
}
|
|
} else {
|
|
call = callOrEnum as Call;
|
|
}
|
|
|
|
items.push({ blockNumber, call, key: `${blockNumber.toString()}-${index}`, maybeId, maybePeriodic, preimageHash, priority });
|
|
|
|
return items;
|
|
}, items);
|
|
}, []);
|
|
}
|
|
};
|
|
|
|
function Schedule ({ className = '' }: Props): React.ReactElement<Props> {
|
|
const { t } = useTranslation();
|
|
const { api } = useApi();
|
|
const bestNumber = useBestNumberRelay();
|
|
const items = useCall<ScheduledExt[]>(api.query.scheduler.agenda.entries, undefined, OPT_SCHED);
|
|
|
|
const filtered = useMemo(
|
|
() => bestNumber && items?.filter(({ blockNumber }) => blockNumber.gte(bestNumber)).sort((a, b) => a.blockNumber.cmp(b.blockNumber)),
|
|
[bestNumber, items]
|
|
);
|
|
|
|
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
|
|
[t('scheduled'), 'start'],
|
|
[t('id'), 'start'],
|
|
[t('remaining')],
|
|
[t('period')],
|
|
[t('count')]
|
|
]);
|
|
|
|
return (
|
|
<Table
|
|
className={className}
|
|
empty={filtered && t('No active schedules')}
|
|
header={headerRef.current}
|
|
>
|
|
{filtered?.map((value): React.ReactNode => (
|
|
<ScheduledView
|
|
bestNumber={bestNumber}
|
|
key={value.key}
|
|
value={value}
|
|
/>
|
|
))}
|
|
</Table>
|
|
);
|
|
}
|
|
|
|
export default React.memo(Schedule);
|