Files
pezkuwi-apps/packages/page-teyrchains/src/useLeaseRanges.ts
T
Kurdistan Tech MinistryandClaude Opus 4.5 7a4bbeac25 fix: update extension packages and fix type compatibility for pezkuwi-sdk
- Update @pezkuwi/extension-inject to ^0.62.13 with proper /types exports
- Update @pezkuwi/extension-dapp to ^0.62.13
- Update @pezkuwi/extension-compat-metamask to ^0.62.13
- Fix IconTheme type to include 'bizinikiwi' and 'pezkuwi' themes
- Fix endpoint array issues (getTeleports -> direct array references)
- Add type assertions for external package compatibility (acala, moonbeam, parallel)
- Fix subspace.ts dynamic class typing
- Fix conviction type in page-referenda
- Update Pallet type names to Pezpallet prefix across codebase
- Define InjectedExtension types locally for module resolution
- Add styled-components DefaultTheme augmentation
- Add react-copy-to-clipboard type declaration for React 18

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-08 16:24:19 +03:00

57 lines
1.4 KiB
TypeScript

// Copyright 2017-2026 @pezkuwi/app-teyrchains authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { u32 } from '@pezkuwi/types';
import { useMemo } from 'react';
import { createNamedHook, useApi } from '@pezkuwi/react-hooks';
import { BN } from '@pezkuwi/util';
const RANGES_DEFAULT: [number, number][] = [
[0, 0], [0, 1], [0, 2], [0, 3],
[1, 1], [1, 2], [1, 3],
[2, 2], [2, 3],
[3, 3]
];
function isU32 (leasePeriodsPerSlot: unknown): leasePeriodsPerSlot is u32 {
return !!leasePeriodsPerSlot;
}
function useLeaseRangesImpl (): [number, number][] {
const { api } = useApi();
return useMemo(
(): [number, number][] => {
if (isU32(api.consts.auctions?.leasePeriodsPerSlot)) {
const ranges: [number, number][] = [];
for (let i = 0; api.consts.auctions.leasePeriodsPerSlot.gtn(i); i++) {
for (let j = i; api.consts.auctions.leasePeriodsPerSlot.gtn(j); j++) {
ranges.push([i, j]);
}
}
return ranges;
}
return RANGES_DEFAULT;
},
[api]
);
}
export const useLeaseRanges = createNamedHook('useLeaseRanges', useLeaseRangesImpl);
function useLeaseRangeMaxImpl (): BN {
const ranges = useLeaseRanges();
return useMemo(
() => new BN(ranges[ranges.length - 1][1]),
[ranges]
);
}
export const useLeaseRangeMax = createNamedHook('useLeaseRangeMax', useLeaseRangeMaxImpl);