mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-06-09 20:11:10 +00:00
feat: initial Pezkuwi Apps rebrand from polkadot-apps
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
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-staking authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Changes } from '@pezkuwi/react-hooks/useEventChanges';
|
||||
import type { StorageKey } from '@pezkuwi/types';
|
||||
import type { AccountId32, EventRecord } from '@pezkuwi/types/interfaces';
|
||||
import type { SessionInfo, Validator } from './types.js';
|
||||
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { createNamedHook, useApi, useEventChanges, useMapKeys } from '@pezkuwi/react-hooks';
|
||||
|
||||
import { useCacheValue } from './useCache.js';
|
||||
import useTaggedValidators from './useTaggedValidators.js';
|
||||
|
||||
const EMPTY_PARAMS: unknown[] = [];
|
||||
|
||||
const OPT_VALIDATORS = {
|
||||
transform: (keys: StorageKey<[AccountId32]>[]): AccountId32[] =>
|
||||
keys.map(({ args: [id] }) => id)
|
||||
};
|
||||
|
||||
function eventFilter (records: EventRecord[]): Changes<AccountId32> {
|
||||
const added: AccountId32[] = [];
|
||||
const removed: AccountId32[] = [];
|
||||
|
||||
records.forEach(({ event: { data: [id], method } }): void => {
|
||||
if (method === 'Bonded') {
|
||||
added.push(id as AccountId32);
|
||||
} else {
|
||||
removed.push(id as AccountId32);
|
||||
}
|
||||
});
|
||||
|
||||
return { added, removed };
|
||||
}
|
||||
|
||||
function mapValidators (validators?: AccountId32[]): Validator[] | undefined {
|
||||
return validators?.map((a) => {
|
||||
const stashId = a.toString();
|
||||
|
||||
return {
|
||||
isElected: false,
|
||||
isFavorite: false,
|
||||
isOwned: false,
|
||||
key: `${stashId}::-1`,
|
||||
stashId,
|
||||
stashIndex: -1
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function useValidatorsAllImpl (favorites: string[], sessionInfo: SessionInfo): Validator[] | undefined {
|
||||
const { api } = useApi();
|
||||
const startValue = useMapKeys(api.query.staking.validators, EMPTY_PARAMS, OPT_VALIDATORS);
|
||||
|
||||
const validators = useEventChanges([
|
||||
api.events.staking.Bonded
|
||||
], eventFilter, startValue);
|
||||
|
||||
const validatorsIndexed = useMemo(
|
||||
() => mapValidators(validators),
|
||||
[validators]
|
||||
);
|
||||
|
||||
const tagged = useTaggedValidators(favorites, sessionInfo, validatorsIndexed);
|
||||
|
||||
return useCacheValue('useValidatorsAll', tagged);
|
||||
}
|
||||
|
||||
export default createNamedHook('useValidatorsAll', useValidatorsAllImpl);
|
||||
Reference in New Issue
Block a user