Files
pezkuwi-apps/packages/page-referenda/src/Referenda/Delegate/useSuperIds.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

58 lines
1.8 KiB
TypeScript

// Copyright 2017-2025 @pezkuwi/app-referenda authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Option } from '@pezkuwi/types';
import type { AccountId } from '@pezkuwi/types/interfaces';
import type { ITuple } from '@pezkuwi/types/types';
import { useMemo } from 'react';
import { createNamedHook, useApi, useCall } from '@pezkuwi/react-hooks';
import { isFunction } from '@pezkuwi/util';
const SUPEROF_OPT = {
transform: ([[ids], optSupers]: [[string[]], Option<ITuple<[AccountId]>>[]]): string[] =>
optSupers
.map((opt, index) =>
// if we have a super, use that, otherwise we default to
// the actual passed-in identity (which is top-level)
opt.isSome
? opt.unwrap()[0].toString()
: ids[index]
)
.reduce((all: string[], who): string[] => {
// deupe all entries since we may have multiple nominees
if (!all.includes(who)) {
all.push(who);
}
return all;
}, []),
withParamsTransform: true
};
function useSuperIdsImpl (accountIds?: string[] | null): string[] | null | undefined {
const { apiIdentity } = useApi();
// for the supplied accounts, retrieve the de-dupes parent identity
const identityParam = useMemo(
() => accountIds && [accountIds],
[accountIds]
);
const identities = useCall(identityParam && !!identityParam[0].length && apiIdentity.query.identity?.superOf?.multi, identityParam, SUPEROF_OPT);
return useMemo(
() => identityParam
? identityParam[0].length
? isFunction(apiIdentity.query.identity?.superOf)
? identities
: accountIds
: []
: null,
[apiIdentity, accountIds, identities, identityParam]
);
}
export default createNamedHook('useSuperIds', useSuperIdsImpl);