@polkadot/types/interfaces#ParaLifecycle TypeScript Examples

The following examples show how to use @polkadot/types/interfaces#ParaLifecycle. 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: Upcoming.tsx    From crust-apps with Apache License 2.0 6 votes vote down vote up
optMulti = {
  defaultValue: {
    headHex: null,
    leases: null,
    lifecycle: null,
    manager: null
  },
  transform: ([optHead, optGenesis, optLifecycle, optInfo, leases]: [Option<HeadData>, Option<ParaGenesisArgs>, Option<ParaLifecycle>, Option<ParaInfo>, Vec<Option<ITuple<[AccountId, BalanceOf]>>>]): MultiState => ({
    headHex: optHead.isSome
      ? sliceHex(optHead.unwrap())
      : optGenesis.isSome
        ? sliceHex(optGenesis.unwrap().genesisHead)
        : null,
    leases: leases
      ? leases
        .map((optLease, period): LeaseInfo | null => {
          if (optLease.isNone) {
            return null;
          }

          const [accountId, balance] = optLease.unwrap();

          return {
            accountId,
            balance,
            period
          };
        })
        .filter((item): item is LeaseInfo => !!item)
      : [],
    lifecycle: optLifecycle.unwrapOr(null),
    manager: optInfo.isSome
      ? optInfo.unwrap().manager
      : null
  })
}
Example #2
Source File: useUpcomingIds.ts    From crust-apps with Apache License 2.0 6 votes vote down vote up
export default function useUpomingIds (): ParaId[] | undefined {
  const { api } = useApi();
  const trigger = useEventTrigger([api.events.session.NewSession, api.events.registrar?.Registered]);
  const [result, setResult] = useState<ParaId[] | undefined>();

  useEffect((): void => {
    trigger &&
      api.query.paras.paraLifecycles
        .entries<Option<ParaLifecycle>, [ParaId]>()
        .then((entries) => setResult(() =>
          entries
            .map(([{ args: [paraId] }, optValue]): ParaId | null => {
              const value = optValue.unwrap();

              return value && (
                value.isParathread ||
                value.isUpgradingToParachain ||
                value.isOutgoingParathread ||
                value.isOnboarding
              )
                ? paraId
                : null;
            })
            .filter((paraId): paraId is ParaId => !!paraId)
            .sort((a, b) => a.cmp(b))
        ))
        .catch(console.error);
  }, [api, trigger]);

  return result;
}