mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-06-13 19:51:07 +00:00
d21bfb1320
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
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
// Copyright 2017-2025 @pezkuwi/app-referenda authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Changes } from '@pezkuwi/react-hooks/useEventChanges';
|
|
import type { StorageKey, u32 } from '@pezkuwi/types';
|
|
import type { EventRecord } from '@pezkuwi/types/interfaces';
|
|
import type { BN } from '@pezkuwi/util';
|
|
import type { PalletReferenda } from './types.js';
|
|
|
|
import { createNamedHook, useApi, useEventChanges, useMapKeys } from '@pezkuwi/react-hooks';
|
|
|
|
const OPT_ID = {
|
|
transform: (keys: StorageKey<[u32]>[]): u32[] =>
|
|
keys.map(({ args: [id] }) => id)
|
|
};
|
|
|
|
function filter (records: EventRecord[]): Changes<u32> {
|
|
const added: u32[] = [];
|
|
const removed: u32[] = [];
|
|
|
|
records.forEach(({ event: { data: [id], method } }): void => {
|
|
if (method === 'Submitted') {
|
|
added.push(id as u32);
|
|
} else {
|
|
removed.push(id as u32);
|
|
}
|
|
});
|
|
|
|
return { added, removed };
|
|
}
|
|
|
|
function useReferendaIdsImpl (palletReferenda: PalletReferenda): BN[] | undefined {
|
|
const { api } = useApi();
|
|
const startValue = useMapKeys(api.query[palletReferenda].referendumInfoFor, [], OPT_ID);
|
|
|
|
return useEventChanges([
|
|
api.events[palletReferenda].Submitted
|
|
], filter, startValue);
|
|
}
|
|
|
|
export default createNamedHook('useReferendaIds', useReferendaIdsImpl);
|