mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-10-26 12:49:49 +00:00
- 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>
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/app-teyrchains authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Option } from '@pezkuwi/types';
|
|
import type { AccountId, BalanceOf, ParaId } from '@pezkuwi/types/interfaces';
|
|
import type { ITuple } from '@pezkuwi/types/types';
|
|
import type { LeaseInfo } from '../types.js';
|
|
|
|
import { useCallback } from 'react';
|
|
|
|
import { createNamedHook, useApi, useCall, useIsParasLinked } from '@pezkuwi/react-hooks';
|
|
|
|
type Result = [ParaId, LeaseInfo[]][];
|
|
|
|
function extractParaMap (hasLinksMap: Record<string, boolean>, paraIds: ParaId[], leases: Option<ITuple<[AccountId, BalanceOf]>>[][]): Result {
|
|
return paraIds
|
|
.reduce((all: Result, id, index): Result => {
|
|
all.push([
|
|
id,
|
|
leases[index]
|
|
.map((optLease, period): LeaseInfo | null => {
|
|
if (optLease.isNone) {
|
|
return null;
|
|
}
|
|
|
|
const [accountId, balance] = optLease.unwrap();
|
|
|
|
return {
|
|
accountId,
|
|
balance,
|
|
period
|
|
};
|
|
})
|
|
.filter((item): item is LeaseInfo => !!item)
|
|
]);
|
|
|
|
return all;
|
|
}, [])
|
|
.sort(([aId, aLeases], [bId, bLeases]): number => {
|
|
const aKnown = hasLinksMap[aId.toString()] || false;
|
|
const bKnown = hasLinksMap[bId.toString()] || false;
|
|
|
|
return aLeases.length && bLeases.length
|
|
? (aLeases[0].period - bLeases[0].period) || aId.cmp(bId)
|
|
: aLeases.length
|
|
? -1
|
|
: bLeases.length
|
|
? 1
|
|
: aKnown === bKnown
|
|
? aId.cmp(bId)
|
|
: aKnown
|
|
? -1
|
|
: 1;
|
|
});
|
|
}
|
|
|
|
function useParaMapImpl (ids?: ParaId[]): Result | undefined {
|
|
const { api } = useApi();
|
|
const hasLinksMap = useIsParasLinked(ids);
|
|
const transform = useCallback(
|
|
([[paraIds], leases]: [[ParaId[]], Option<ITuple<[AccountId, BalanceOf]>>[][]]): Result =>
|
|
extractParaMap(hasLinksMap, paraIds, leases),
|
|
[hasLinksMap]
|
|
);
|
|
|
|
return useCall<Result>(ids && api.query.slots.leases.multi, [ids], {
|
|
transform,
|
|
withParamsTransform: true
|
|
});
|
|
}
|
|
|
|
export default createNamedHook('useParaMap', useParaMapImpl);
|