// Copyright 2017-2026 @pezkuwi/react-components authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { DeriveAccountInfo } from '@pezkuwi/api-derive/types'; import type { AccountId, Address } from '@pezkuwi/types/interfaces'; import React, { useMemo } from 'react'; import { useDeriveAccountInfo, useSystemApi } from '@pezkuwi/react-hooks'; interface Props { children?: React.ReactNode; className?: string; defaultValue?: string; label?: React.ReactNode; value?: string | AccountId | Address | null | Uint8Array; } function extractIndex ({ accountIndex }: Partial = {}): string | null { return accountIndex ? accountIndex.toString() : null; } function AccountIndex ({ children, className = '', defaultValue, label, value }: Props): React.ReactElement | null { const api = useSystemApi(); const info = useDeriveAccountInfo(value); const accountIndex = useMemo( () => extractIndex(info), [info] ); if (!api?.query.indices) { return null; } return (
{label || ''}
{accountIndex || defaultValue || '-'}
{children}
); } export default React.memo(AccountIndex);