ghost-portal/packages/page-crowdloan/src/useFundIndexes.ts
Jaco Greeff 9cb68cd08e
Bump deps (type for parachains, crowdloads, auctions) (#4815)
* Bump deps (type for parachains, crowdloads, auctions)

* indexes
2021-03-10 23:05:55 +01:00

25 lines
735 B
TypeScript

// Copyright 2017-2021 @polkadot/app-crowdloan authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ParaId } from '@polkadot/types/interfaces';
import { useEffect, useState } from 'react';
import { useApi, useEventTrigger } from '@polkadot/react-hooks';
export default function useFundIndexes (): ParaId[] {
const { api } = useApi();
const [indexes, setIndexes] = useState<ParaId[]>([]);
const trigger = useEventTrigger([api.events.crowdloan.Created]);
useEffect((): void => {
trigger &&
api.query.crowdloan.funds
.keys()
.then((indexes) => setIndexes(indexes.map(({ args }) => args[0] as ParaId)))
.catch(console.error);
}, [api, trigger]);
return indexes;
}