mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-06-13 22:11:08 +00:00
7a4bbeac25
- 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>
81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/app-teyrchains authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Option, StorageKey } from '@pezkuwi/types';
|
|
import type { Hash, ParaId } from '@pezkuwi/types/interfaces';
|
|
import type { PezkuwiRuntimeCommonParasRegistrarParaInfo } from '@pezkuwi/types/lookup';
|
|
import type { OwnedId, OwnedIdPartial } from './types.js';
|
|
|
|
import { useMemo } from 'react';
|
|
|
|
import { createNamedHook, useAccounts, useApi, useCall, useEventTrigger, useMapEntries } from '@pezkuwi/react-hooks';
|
|
|
|
interface CodeHash {
|
|
hash: Hash | null;
|
|
paraId: ParaId;
|
|
}
|
|
|
|
interface Owned {
|
|
ids: ParaId[];
|
|
owned: OwnedIdPartial[];
|
|
}
|
|
|
|
const OPT_ENTRIES = {
|
|
transform: (entries: [StorageKey<[ParaId]>, Option<PezkuwiRuntimeCommonParasRegistrarParaInfo>][]): Owned => {
|
|
const owned = entries
|
|
.map(([{ args: [paraId] }, optInfo]): OwnedIdPartial | null => {
|
|
if (optInfo.isNone) {
|
|
return null;
|
|
}
|
|
|
|
const paraInfo = optInfo.unwrap();
|
|
|
|
return {
|
|
manager: paraInfo.manager.toString(),
|
|
paraId,
|
|
paraInfo
|
|
};
|
|
})
|
|
.filter((id): id is OwnedIdPartial => !!id);
|
|
|
|
return {
|
|
ids: owned.map(({ paraId }) => paraId),
|
|
owned
|
|
};
|
|
}
|
|
};
|
|
|
|
const OPT_HASHES = {
|
|
transform: ([[paraIds], optHashes]: [[ParaId[]], Option<Hash>[]]) =>
|
|
paraIds.map((paraId, index): CodeHash => ({
|
|
hash: optHashes[index].unwrapOr(null),
|
|
paraId
|
|
})),
|
|
withParamsTransform: true
|
|
};
|
|
|
|
function useOwnedIdsImpl (): OwnedId[] {
|
|
const { api } = useApi();
|
|
const { allAccounts } = useAccounts();
|
|
const trigger = useEventTrigger([
|
|
api.events.registrar.Registered,
|
|
api.events.registrar.Reserved
|
|
]);
|
|
const unfiltered = useMapEntries<Owned>(api.query.registrar.paras, [], OPT_ENTRIES, trigger.blockHash);
|
|
const hashes = useCall(api.query.paras.currentCodeHash.multi, [unfiltered ? unfiltered.ids : []], OPT_HASHES);
|
|
|
|
return useMemo(
|
|
() => unfiltered && hashes
|
|
? unfiltered.owned
|
|
.filter((id) => allAccounts.some((a) => a === id.manager))
|
|
.map((data): OwnedId => ({
|
|
...data,
|
|
hasCode: hashes.some((h) => !!h.hash && h.paraId.eq(data.paraId))
|
|
}))
|
|
: [],
|
|
[allAccounts, hashes, unfiltered]
|
|
);
|
|
}
|
|
|
|
export default createNamedHook('useOwnedIds', useOwnedIdsImpl);
|