@polkadot/types/interfaces#FundInfo TypeScript Examples

The following examples show how to use @polkadot/types/interfaces#FundInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useFunds.ts    From crust-apps with Apache License 2.0 6 votes vote down vote up
export default function useFunds (): Result {
  const { api } = useApi();
  const bestNumber = useBestNumber();
  const [paraIds, setParaIds] = useState<ParaId[]>([]);
  const trigger = useEventTrigger([api.events.crowdloan.Created]);
  const optFunds = useCallMulti<Option<FundInfo>[]>(paraIds.map((id) => [api.query.crowdloan.funds, id]));
  const [result, setResult] = useState<Result>(EMPTY);

  // we actually want to split this further info completed and ongoing
  const campaigns = useMemo(
    () => extractCampaigns(optFunds, paraIds),
    [optFunds, paraIds]
  );

  // on event triggers, update the available paraIds
  useEffect((): void => {
    trigger &&
      api.query.crowdloan.funds
        .keys<[ParaId]>()
        .then((indexes) => setParaIds(
          indexes.map(({ args: [paraId] }) => paraId))
        )
        .catch(console.error);
  }, [api, trigger]);

  // here we manually add the actual ending status and calculate the totals
  useEffect((): void => {
    bestNumber && campaigns && setResult((prev) =>
      createResult(bestNumber, campaigns, prev)
    );
  }, [bestNumber, campaigns]);

  return result;
}
Example #2
Source File: useFunds.ts    From crust-apps with Apache License 2.0 5 votes vote down vote up
// extract fund info from the available paraIds
function extractCampaigns (optFunds: Option<FundInfo>[], paraIds: ParaId[]): Campaign[] | null {
  return optFunds && paraIds.length === optFunds.length
    ? paraIds
      .map((paraId, i) => ({ info: optFunds[i].unwrapOr(null), key: paraId.toString(), paraId }))
      .filter((fund): fund is Campaign => !!fund.info)
    : null;
}