ghost-portal/packages/react-hooks/src/useBrokerReservations.ts
Daria 859ba4800e
Coretime Broker on Coretime Chain - Update after Coretime Polkadot release (#10947)
* showing all cores, not relying on the core information in workload to show the cores

* swapped idles and pools to reflect correct values

* added start and end for bulk coretime, taking into account timeslice from the workplan

* checked and updated the time estimation function

* added cores offerred vs sold in summary

* filters turned back on

* lint

* reversed a change in a file from .github folder

* removed some extra checks

* minor refactor
2024-09-26 17:25:22 +08:00

39 lines
1.3 KiB
TypeScript

// Copyright 2017-2024 @polkadot/react-hooks authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiPromise } from '@polkadot/api';
import type { Vec } from '@polkadot/types';
import type { PalletBrokerScheduleItem } from '@polkadot/types/lookup';
import type { Reservation } from './types.js';
import { useEffect, useState } from 'react';
import { createNamedHook, useCall } from '@polkadot/react-hooks';
import { processHexMask } from './utils/dataProcessing.js';
function useBrokerReservationsImpl (api: ApiPromise, ready: boolean): Reservation[] | undefined {
const reservations = useCall<[any, Vec<Vec<PalletBrokerScheduleItem>>[]]>(ready && api.query.broker.reservations);
const [state, setState] = useState<Reservation[]>();
useEffect((): void => {
if (!reservations) {
return;
}
setState(
reservations.map((info: PalletBrokerScheduleItem[]) => {
return {
mask: processHexMask(info[0]?.mask),
maskBits: processHexMask(info[0]?.mask)?.length ?? 0,
task: info[0]?.assignment?.isTask ? info[0]?.assignment?.asTask.toString() : info[0]?.assignment?.isPool ? 'Pool' : ''
};
}
));
}, [reservations]);
return state;
}
export const useBrokerReservations = createNamedHook('useBrokerReservations', useBrokerReservationsImpl);