mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-06-13 21:01:06 +00:00
d21bfb1320
Rebranded terminology: - Polkadot → Pezkuwi - Kusama → Dicle - Westend → Zagros - Rococo → PezkuwiChain - Substrate → Bizinikiwi - parachain → teyrchain Custom logos with Kurdistan brand colors (#e6007a → #86e62a): - bizinikiwi-hexagon.svg - sora-bizinikiwi.svg - hezscanner.svg - heztreasury.svg - pezkuwiscan.svg - pezkuwistats.svg - pezkuwiassembly.svg - pezkuwiholic.svg
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
// Copyright 2017-2025 @pezkuwi/app-referenda authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { ApiPromise } from '@pezkuwi/api';
|
|
import type { BN } from '@pezkuwi/util';
|
|
import type { TrackDescription } from '../../types.js';
|
|
import type { TrackOption } from './types.js';
|
|
|
|
import React, { useMemo } from 'react';
|
|
|
|
import { createNamedHook, useApi } from '@pezkuwi/react-hooks';
|
|
import { bnToBn } from '@pezkuwi/util';
|
|
|
|
import { getTrackInfo, getTrackName } from '../../util.js';
|
|
|
|
function getTrackOptions (api: ApiPromise, specName: string, palletReferenda: string, tracks: TrackDescription[], include?: (BN | number)[], exclude?: (BN | number)[]): TrackOption[] {
|
|
const includeBn = include?.map((v) => bnToBn(v));
|
|
const excludeBn = exclude?.map((v) => bnToBn(v));
|
|
|
|
return tracks
|
|
.filter(({ id }) =>
|
|
(
|
|
!includeBn ||
|
|
includeBn.some((v) => v.eq(id))
|
|
) && (
|
|
!excludeBn ||
|
|
!excludeBn.some((v) => v.eq(id))
|
|
)
|
|
)
|
|
.map(({ id, info }): TrackOption => {
|
|
const trackInfo = getTrackInfo(api, specName, palletReferenda, tracks, id.toNumber());
|
|
const trackName = getTrackName(id, info);
|
|
|
|
return {
|
|
text: trackInfo?.text
|
|
? (
|
|
<div className='trackOption'>
|
|
<div className='normal'>{trackName}</div>
|
|
<div className='faded'>{trackInfo.text}</div>
|
|
</div>
|
|
)
|
|
: trackName,
|
|
value: id.toNumber()
|
|
};
|
|
});
|
|
}
|
|
|
|
function useTrackOptionsImpl (palletReferenda: string, tracks: TrackDescription[], include?: (BN | number)[], exclude?: (BN | number)[]): TrackOption[] {
|
|
const { api, specName } = useApi();
|
|
|
|
return useMemo(
|
|
() => getTrackOptions(api, specName, palletReferenda, tracks, include, exclude),
|
|
[api, exclude, include, palletReferenda, specName, tracks]
|
|
);
|
|
}
|
|
|
|
export default createNamedHook('useTrackOptions', useTrackOptionsImpl);
|