@polkadot/types/interfaces#LeasePeriodOf TypeScript Examples

The following examples show how to use @polkadot/types/interfaces#LeasePeriodOf. 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: index.tsx    From crust-apps with Apache License 2.0 6 votes vote down vote up
optionsMulti = {
  defaultValue: {
    auctionInfo: null,
    numAuctions: null
  },
  transform: ([numAuctions, optInfo]: [AuctionIndex, Option<ITuple<[LeasePeriodOf, BlockNumber]>>]) => ({
    auctionInfo: optInfo.unwrapOr(null),
    numAuctions
  })
}
Example #2
Source File: useWinningData.ts    From crust-apps with Apache License 2.0 5 votes vote down vote up
export default function useWinningData (auctionInfo: [LeasePeriodOf, BlockNumber] | null): Winning[] | null {
  const { api } = useApi();
  const [result, setResult] = useState<Winning[] | null>(null);
  const bestNumber = useBestNumber();
  const trigger = useEventTrigger([api.events.auctions?.BidAccepted]);
  const triggerRef = useRef(trigger);
  const allEntries = useCall<[StorageKey<[BlockNumber]>, Option<WinningData>][]>(api.query.auctions?.winning.entries);
  const optFirstData = useCall<Option<WinningData>>(api.query.auctions?.winning, FIRST_PARAM);

  // should be fired once, all entries as an initial round
  useEffect((): void => {
    allEntries && setResult(
      extractData(auctionInfo && auctionInfo[1], allEntries)
    );
  }, [allEntries, auctionInfo]);

  // when block 0 changes, update (typically in non-ending-period, static otherwise)
  useEffect((): void => {
    optFirstData && setResult((prev) =>
      mergeFirst(prev, optFirstData)
    );
  }, [optFirstData]);

  // on a bid event, get the new entry (assuming the event really triggered, i.e. not just a block)
  // and add it to the list when not duplicated. Additionally we cleanup after ourselves when endBlock
  // gets cleared
  useEffect((): void => {
    const [, endBlock] = auctionInfo || [null, null];

    if (!endBlock) {
      setResult((prev) => prev && prev.length ? [] : prev);
    } else if (bestNumber && bestNumber.gt(endBlock) && triggerRef.current !== trigger) {
      const blockOffset = bestNumber.sub(endBlock).iadd(BN_ONE);

      triggerRef.current = trigger;

      api.query.auctions
        ?.winning<Option<WinningData>>(blockOffset)
        .then((optCurrent) => setResult((prev) =>
          mergeCurrent(prev, optCurrent, endBlock, blockOffset)
        ))
        .catch(console.error);
    }
  }, [api, bestNumber, auctionInfo, trigger, triggerRef]);

  return result;
}