Files
pezkuwi-apps/packages/page-parachains/src/useProposals.ts
T
pezkuwichain d21bfb1320 feat: initial Pezkuwi Apps rebrand from polkadot-apps
Rebranded terminology:
- Polkadot → Pezkuwi
- Kusama → Dicle
- Westend → Zagros
- Rococo → PezkuwiChain
- Substrate → Bizinikiwi
- parachain → teyrchain

Custom logos with Kurdistan brand colors (#e6007a → #86e62a):
- bizinikiwi-hexagon.svg
- sora-bizinikiwi.svg
- hezscanner.svg
- heztreasury.svg
- pezkuwiscan.svg
- pezkuwistats.svg
- pezkuwiassembly.svg
- pezkuwiholic.svg
2026-01-07 13:05:27 +03:00

60 lines
2.0 KiB
TypeScript

// Copyright 2017-2025 @pezkuwi/app-teyrchains authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { StorageKey } from '@pezkuwi/types';
import type { ParaId, SessionIndex } from '@pezkuwi/types/interfaces';
import type { Proposals } from './types.js';
import { useMemo } from 'react';
import { createNamedHook, useApi, useCallMulti, useEventTrigger, useIsMountedRef, useMapEntries, useMapKeys } from '@pezkuwi/react-hooks';
type MultiQuery = [SessionIndex | undefined, ParaId[] | undefined];
interface Scheduled {
scheduledIds: ParaId[];
sessionIndex: SessionIndex;
}
const OPT_MULTI = {
defaultValue: [undefined, undefined] as MultiQuery
};
const OPT_IDS = {
transform: (keys: StorageKey<[ParaId]>[]): ParaId[] =>
keys.map(({ args: [id] }) => id)
};
const OPT_SCHED = {
transform: (entries: [StorageKey<[SessionIndex]>, ParaId[]][]): Scheduled[] =>
entries.map(([{ args: [sessionIndex] }, scheduledIds]) => ({
scheduledIds,
sessionIndex
}))
};
function useProposalsImpl (): Proposals | undefined {
const { api } = useApi();
const mountedRef = useIsMountedRef();
const trigger = useEventTrigger([api.events.proposeTeyrchain?.ProposeTeyrchain]);
const proposalIds = useMapKeys(api.query.proposeTeyrchain?.proposals, [], OPT_IDS, trigger.blockHash);
const scheduled = useMapEntries(api.query.proposeTeyrchain?.scheduledProposals, [], OPT_SCHED, trigger.blockHash);
const [sessionIndex, approvedIds] = useCallMulti<MultiQuery>([
api.query.session.currentIndex,
api.query.proposeTeyrchain?.approvedProposals
], OPT_MULTI);
return useMemo(
() => approvedIds && sessionIndex && proposalIds && scheduled && mountedRef.current
? {
approvedIds,
proposalIds,
scheduled: scheduled.filter((s) => s.sessionIndex.gt(sessionIndex))
}
: undefined,
[approvedIds, mountedRef, proposalIds, sessionIndex, scheduled]
);
}
export default createNamedHook('useProposals', useProposalsImpl);