mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-08-08 16:55:40 +00:00
c71ddb6e0d
- Clone Polkadot.js Apps repository - Update package.json with Pezkuwi branding - Add Pezkuwi endpoint to production chains (wss://pezkuwichain.app:9944) - Create comprehensive README for SDK UI - Set up project structure with all packages Next steps: - Apply Kurdistan colors (Kesk, Sor, Zer, Spi + Black) to UI theme - Replace logos with Pezkuwi branding - Test build and deployment
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
// Copyright 2017-2025 @polkadot/app-nfts authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Changes } from '@polkadot/react-hooks/useEventChanges';
|
|
import type { StorageKey, u32 } from '@polkadot/types';
|
|
import type { EventRecord } from '@polkadot/types/interfaces';
|
|
|
|
import { createNamedHook, useApi, useEventChanges, useMapKeys } from '@polkadot/react-hooks';
|
|
|
|
const OPT_KEYS = {
|
|
transform: (keys: StorageKey<[u32]>[]): u32[] =>
|
|
keys
|
|
.map(({ args: [id] }) => id)
|
|
.sort((a, b) => a.cmp(b))
|
|
};
|
|
|
|
function filter (records: EventRecord[]): Changes<u32> {
|
|
const added: u32[] = [];
|
|
const removed: u32[] = [];
|
|
|
|
records.forEach(({ event: { data: [id], method } }): void => {
|
|
if (method === 'Created' || method === 'ForceCreated') {
|
|
added.push(id as u32);
|
|
} else {
|
|
removed.push(id as u32);
|
|
}
|
|
});
|
|
|
|
return { added, removed };
|
|
}
|
|
|
|
function useCollectionIdsImpl (): u32[] | undefined {
|
|
const { api } = useApi();
|
|
const startValue = useMapKeys(api.query.uniques.class, [], OPT_KEYS);
|
|
|
|
return useEventChanges([
|
|
api.events.uniques.Created,
|
|
api.events.uniques.Destroyed,
|
|
api.events.uniques.ForceCreated
|
|
], filter, startValue);
|
|
}
|
|
|
|
export default createNamedHook('useCollectionIds', useCollectionIdsImpl);
|