mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-06-15 12:41:09 +00:00
fix: update extension packages and fix type compatibility for pezkuwi-sdk
- Update @pezkuwi/extension-inject to ^0.62.13 with proper /types exports - Update @pezkuwi/extension-dapp to ^0.62.13 - Update @pezkuwi/extension-compat-metamask to ^0.62.13 - Fix IconTheme type to include 'bizinikiwi' and 'pezkuwi' themes - Fix endpoint array issues (getTeleports -> direct array references) - Add type assertions for external package compatibility (acala, moonbeam, parallel) - Fix subspace.ts dynamic class typing - Fix conviction type in page-referenda - Update Pallet type names to Pezpallet prefix across codebase - Define InjectedExtension types locally for module resolution - Add styled-components DefaultTheme augmentation - Add react-copy-to-clipboard type declaration for React 18 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// Copyright 2017-2026 @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);
|
||||
Reference in New Issue
Block a user