Skip to content

Commit

Permalink
tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
piggydoughnut committed Oct 17, 2024
1 parent da7be71 commit a5de399
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 91 deletions.
51 changes: 26 additions & 25 deletions packages/page-broker/src/Overview/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CardSummary, styled, SummaryBox, UsageBar } from '@polkadot/react-compo
import { defaultHighlight } from '@polkadot/react-components/styles';
import { useApi, useBrokerConfig, useBrokerSalesInfo, useBrokerStatus } from '@polkadot/react-hooks';
import { type CoreWorkload } from '@polkadot/react-hooks/types';
import { BN } from '@polkadot/util';
import { BN, BN_ZERO } from '@polkadot/util';

import { useTranslation } from '../translate.js';
import { estimateTime, getStats } from '../utils.js';
Expand Down Expand Up @@ -39,7 +39,7 @@ interface Props {
workloadInfos?: CoreWorkload[]
}

function Summary ({ coreCount, workloadInfos }: Props): React.ReactElement {
function Summary({ coreCount, workloadInfos }: Props): React.ReactElement {

Check failure on line 42 in packages/page-broker/src/Overview/Summary.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

Missing space before function parentheses
const { t } = useTranslation();
const { api, apiEndpoint, isApiReady } = useApi();
const uiHighlight = apiEndpoint?.ui.color || defaultHighlight;
Expand Down Expand Up @@ -79,7 +79,7 @@ function Summary ({ coreCount, workloadInfos }: Props): React.ReactElement {
progress={{
isBlurred: false,
total: new BN(config?.regionLength || 0),
value: config?.regionLength && new BN(config?.regionLength - (currentRegionEnd - status?.lastTimeslice)),
value: config?.regionLength && currentRegionEnd && status && new BN(config?.regionLength - (currentRegionEnd - status?.lastTimeslice)) || BN_ZERO,

Check failure on line 82 in packages/page-broker/src/Overview/Summary.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations

Check failure on line 82 in packages/page-broker/src/Overview/Summary.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations
withTime: false
}}
/>
Expand All @@ -88,7 +88,7 @@ function Summary ({ coreCount, workloadInfos }: Props): React.ReactElement {

)}
<div
className='media--1200'
className='media--1400'
style={{ marginLeft: '2rem' }}
>
<UsageBar
Expand All @@ -102,30 +102,31 @@ function Summary ({ coreCount, workloadInfos }: Props): React.ReactElement {
</div>
</StyledSection>
<section>
{status &&
{status && currentRegionStart && currentRegionEnd &&
(
<CardSummary
className='media--1200'
label={t('cycle dates')}
>
<div>
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionStart, status?.lastTimeslice * 80)}</div>
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionEnd, status?.lastTimeslice * 80)}</div>
</div>
</CardSummary>
<>
<CardSummary
className='media--1200'
label={t('cycle dates')}
>
<div>
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionStart, status?.lastTimeslice * 80)}</div>
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionEnd, status?.lastTimeslice * 80)}</div>
</div>
</CardSummary>

<CardSummary

Check failure on line 118 in packages/page-broker/src/Overview/Summary.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

JSX element should not start in a new line
className='media--1200'
label={t('cycle ts')}
>
<div>
<div style={{ fontSize: '14px' }}>{currentRegionStart}</div>
<div style={{ fontSize: '14px' }}>{currentRegionEnd}</div>
</div>
</CardSummary>
</>
)
}
{status &&
<CardSummary
className='media--1200'
label={t('cycle ts')}
>
<div>
<div style={{ fontSize: '14px' }}>{currentRegionStart}</div>
<div style={{ fontSize: '14px' }}>{currentRegionEnd}</div>
</div>
</CardSummary>
}
</section>
</SummaryBox>
);
Expand Down
24 changes: 0 additions & 24 deletions packages/page-broker/src/Overview/Summary/Cores.tsx

This file was deleted.

28 changes: 18 additions & 10 deletions packages/react-hooks/src/useBrokerPotentialRenewals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ import type { ApiPromise } from '@polkadot/api';
import type { Option, StorageKey, u32 } from '@polkadot/types';
import type { PalletBrokerPotentialRenewalId, PalletBrokerPotentialRenewalRecord } from '@polkadot/types/lookup';
import type { PotentialRenewal } from './types.js';
import { BN_ZERO, } from '@polkadot/util';

import { useEffect, useState } from 'react';

import { createNamedHook, useCall, useMapKeys } from '@polkadot/react-hooks';

import { processHexMask } from './utils/dataProcessing.js';

function extractInfo (info: Option<PalletBrokerPotentialRenewalRecord>, item: PalletBrokerPotentialRenewalId): PotentialRenewal {
function extractInfo (info: Option<PalletBrokerPotentialRenewalRecord>, item: PalletBrokerPotentialRenewalId): PotentialRenewal | undefined {
const unwrapped: PalletBrokerPotentialRenewalRecord | null = info.isSome ? info.unwrap() : null;
let mask = [];
let task = null;
let mask: string[] = [];
let task = '';

if (!unwrapped) {
return
}
const completion = unwrapped?.completion;

if (completion?.isComplete) {
Expand All @@ -24,8 +29,8 @@ function extractInfo (info: Option<PalletBrokerPotentialRenewalRecord>, item: Pa
task = complete.assignment.isTask ? complete?.assignment.asTask.toString() : complete?.assignment.isPool ? 'Pool' : 'Idle';
mask = processHexMask(complete.mask);
} else if (completion?.isPartial) {
task = null;
mask = completion.asPartial[0];
mask = processHexMask(completion?.asPartial);
task = '';
} else {
mask = [];
}
Expand All @@ -36,10 +41,11 @@ function extractInfo (info: Option<PalletBrokerPotentialRenewalRecord>, item: Pa
core: item?.core.toNumber(),
mask,
maskBits: mask?.length,
price: unwrapped?.price.toBn(),
price: unwrapped?.price.toBn() || BN_ZERO,
task,
when: item?.when.toNumber()
};

}

const OPT_KEY = {
Expand All @@ -51,12 +57,14 @@ function useBrokerPotentialRenewalsImpl (api: ApiPromise, ready: boolean): Poten
const keys = useMapKeys(ready && api?.query.broker.potentialRenewals, [], OPT_KEY);
const potentialRenewals = useCall<[[PalletBrokerPotentialRenewalId[]], Option<PalletBrokerPotentialRenewalRecord>[]]>(ready && api?.query.broker.potentialRenewals.multi, [keys], { withParams: true });

const [state, setState] = useState<any[] | undefined>();
const [state, setState] = useState<PotentialRenewal[] | undefined>();

useEffect((): void => {
potentialRenewals &&
setState(potentialRenewals[0][0].map((info, index) => extractInfo(potentialRenewals[1][index], info))
);
if (!potentialRenewals) {
return
}
const renewals = potentialRenewals[0][0].map((info, index) => extractInfo(potentialRenewals[1][index], info))
setState(renewals.filter((renewal): renewal is PotentialRenewal => !!renewal));
}, [potentialRenewals]);

return state;
Expand Down
6 changes: 3 additions & 3 deletions packages/react-hooks/src/useCoretimeInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function useCoretimeInformationImpl (api: ApiPromise, ready: boolean): CoretimeI
const coreInfos = useCoreDescriptor(api, ready);

const potentialRenewalsCurrentRegion = useMemo(() => potentialRenewals?.filter((renewal: PotentialRenewal) => renewal.when === salesInfo?.regionEnd), [potentialRenewals, salesInfo]);
const [state, setState] = useState<CoretimeInformation[] | undefined>();
const [state, setState] = useState<CoretimeInformation | undefined>();

useEffect(() => {
if (workloads?.length) {
Expand All @@ -53,7 +53,7 @@ function useCoretimeInformationImpl (api: ApiPromise, ready: boolean): CoretimeI
) as CoreWorkloadInfo)
}));

setWorkloadData(parsedCoreInfos);
setWorkloadData(parsedCoreInfos as unknown as CoreWorkload[]);
}
}, [workloads, coreInfos]);

Expand All @@ -79,7 +79,7 @@ function useCoretimeInformationImpl (api: ApiPromise, ready: boolean): CoretimeI
};
});

if (chainInfo) {
if (chainInfo && config && region && salesInfo && status) {
setState({
chainInfo,
config,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-hooks/src/useRegions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const OPT_KEY = {
};

function useRegionsImpl (api: ApiPromise): RegionInfo[] | undefined {
const regionKeys = useMapKeys(api.query.broker.regions, [], OPT_KEY);
const regionKeys = useMapKeys(api?.query?.broker.regions, [], OPT_KEY);

const regionInfo = useCall<[[PalletBrokerRegionId[]], Option<PalletBrokerRegionRecord>[]]>(api?.query?.broker.regions.multi, [regionKeys], { withParams: true });

Expand Down
4 changes: 2 additions & 2 deletions packages/react-hooks/src/utils/dataProcessing.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright 2017-2024 @polkadot/react-hooks authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { PalletBrokerScheduleItem } from '@polkadot/types/lookup';
import type { PalletBrokerScheduleItem, PalletBrokerCoreMask } from '@polkadot/types/lookup';

import { BN } from '@polkadot/util';

export function hexToBin (hex: string): string {
return parseInt(hex, 16).toString(2);
}

export function processHexMask (mask: PalletBrokerScheduleItem['mask'] | undefined): string[] {
export function processHexMask (mask: PalletBrokerScheduleItem['mask'] | PalletBrokerCoreMask | undefined): string[] {
if (!mask) {
return [];
}
Expand Down
25 changes: 0 additions & 25 deletions packages/react-query/src/BrokerStatus.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/react-query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export { default as BestFinalized } from './BestFinalized.js';
export { default as BestNumber } from './BestNumber.js';
export { default as BlockToTime } from './BlockToTime.js';
export { default as Bonded } from './Bonded.js';
export { default as BrokerStatus } from './BrokerStatus.js';
export { default as Chain } from './Chain.js';
export { default as Elapsed } from './Elapsed.js';
export { default as FormatBalance } from './FormatBalance.js';
Expand Down

0 comments on commit a5de399

Please sign in to comment.