* updated parsing for brokerConfig and brokerSalesInfo * renamed file * updated parsing for brokerConfig and brokerSalesInfo * better type conversion for BN * BN type change * lint
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
// Copyright 2017-2024 @polkadot/react-hooks authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { PalletBrokerConfigRecord } from '@polkadot/types/lookup';
|
|
import type { PalletBrokerConfigRecord as SimplifiedPalletBrokerConfigRecord } from './types.js';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks';
|
|
|
|
function parseConfig (config: PalletBrokerConfigRecord): SimplifiedPalletBrokerConfigRecord {
|
|
return {
|
|
advanceNotice: config.advanceNotice.toNumber(),
|
|
contributionTimeout: config.contributionTimeout.toNumber(),
|
|
idealBulkProportion: config.idealBulkProportion,
|
|
interludeLength: config.interludeLength.toNumber(),
|
|
leadinLength: config.leadinLength.toNumber(),
|
|
limitCoresOffered: config.limitCoresOffered.isSome ? config.limitCoresOffered.unwrap().toNumber() : 0,
|
|
regionLength: config.regionLength.toNumber(),
|
|
renewalBump: config.renewalBump
|
|
};
|
|
}
|
|
|
|
function useBrokerConfigImpl () {
|
|
const { api, isApiReady } = useApi();
|
|
|
|
const config = useCall<PalletBrokerConfigRecord>(isApiReady && api.query.broker.configuration);
|
|
|
|
const [state, setState] = useState<SimplifiedPalletBrokerConfigRecord>();
|
|
|
|
useEffect((): void => {
|
|
!!config && !!config.toJSON() &&
|
|
setState(
|
|
parseConfig(config)
|
|
);
|
|
}, [config]);
|
|
|
|
return state;
|
|
}
|
|
|
|
export const useBrokerConfig = createNamedHook('useBrokerConfig', useBrokerConfigImpl);
|