mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-06-14 02:51:09 +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
58 lines
1.8 KiB
TypeScript
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);
|