ghost-portal/packages/page-staking/src/useIdentities.ts
Jaco ba90464cb3
Rename staking validators page to Validators (#7378)
* Rename staking validators page to Validators

* Adjust

* Dedupe summary

* Cleanups
2022-04-15 09:25:42 +03:00

29 lines
1004 B
TypeScript

// Copyright 2017-2022 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DeriveHasIdentity } from '@polkadot/api-derive/types';
import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks';
type Result = Record<string, DeriveHasIdentity>;
const OPT_CALL = {
transform: ([[validatorIds], hasIdentities]: [[string[]], DeriveHasIdentity[]]): Record<string, DeriveHasIdentity> => {
return validatorIds.reduce((result: Record<string, DeriveHasIdentity>, validatorId, index): Record<string, DeriveHasIdentity> => {
result[validatorId] = hasIdentities[index];
return result;
}, {});
},
withParamsTransform: true
};
function useIdentitiesImpl (validatorIds: string[] = []): Result | undefined {
const { api } = useApi();
const allIdentity = useCall<Result>(api.derive.accounts.hasIdentityMulti, [validatorIds], OPT_CALL);
return allIdentity;
}
export default createNamedHook('useIdentities', useIdentitiesImpl);