ghost-portal/packages/react-hooks/src/useMembers.ts
Jaco 0e72723b7b
Enable Statemine <-> Kusama (w/ fees) (#5495)
* Enable Statemine <-> Kusama (w/ fees)

* Retrievals

* text
2021-06-08 11:08:15 +02:00

35 lines
1018 B
TypeScript

// Copyright 2017-2021 @polkadot/app-democracy authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AccountId } from '@polkadot/types/interfaces';
import { useMemo } from 'react';
import { useAccounts } from './useAccounts';
import { useApi } from './useApi';
import { useCall } from './useCall';
interface Result {
isMember: boolean;
members: string[];
}
const transformMembers = {
transform: (accounts: AccountId[]) =>
accounts.map((accountId) => accountId.toString())
};
export function useMembers (collective: 'council' | 'membership' | 'technicalCommittee' = 'council'): Result {
const { api } = useApi();
const { allAccounts, hasAccounts } = useAccounts();
const retrieved = useCall<string[]>(hasAccounts && api.query[collective]?.members, undefined, transformMembers);
return useMemo(
() => ({
isMember: (retrieved || []).some((accountId) => allAccounts.includes(accountId)),
members: (retrieved || [])
}),
[allAccounts, retrieved]
);
}