ghost-portal/packages/react-hooks/src/useProxies.ts
Jaco 5174f5ffbe
Bump API & common (#6797)
* Bump API & common

* BN imports

* Root imports

* Bump
2022-01-07 17:37:36 +02:00

32 lines
1.3 KiB
TypeScript

// Copyright 2017-2022 @polkadot/react-hooks authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { AccountId } from '@polkadot/types/interfaces';
import { NodeRuntimeProxyType, PalletProxyProxyDefinition } from '@polkadot/types/lookup';
import { BN } from '@polkadot/util';
import { createNamedHook } from './createNamedHook';
import { useAccounts } from './useAccounts';
import { useApi } from './useApi';
import { useCall } from './useCall';
function useProxiesImpl (): [PalletProxyProxyDefinition[], BN][] | undefined {
const { api } = useApi();
const { allAccounts } = useAccounts();
return useCall<[PalletProxyProxyDefinition[], BN][]>(api.query.proxy?.proxies.multi, [allAccounts], {
transform: (result: [([AccountId, NodeRuntimeProxyType] | PalletProxyProxyDefinition)[], BN][]): [PalletProxyProxyDefinition[], BN][] =>
api.tx.proxy.addProxy.meta.args.length === 3
? result as [PalletProxyProxyDefinition[], BN][]
: (result as [[AccountId, NodeRuntimeProxyType][], BN][]).map(([arr, bn]): [PalletProxyProxyDefinition[], BN] =>
[arr.map(([delegate, proxyType]): PalletProxyProxyDefinition =>
api.createType('ProxyDefinition', {
delegate,
proxyType
})), bn]
)
});
}
export const useProxies = createNamedHook('useProxies', useProxiesImpl);