Files
pwap/pezkuwi-sdk-ui/packages/react-components/src/InputStorage/SelectKey.tsx
T
pezkuwichain 1295c36241 Rebrand: polkadot → pezkuwi build fixes
- Fixed TypeScript type assertion issues
- Updated imports from api-augment/substrate to api-augment/bizinikiwi
- Fixed imgConvert.mjs header and imports
- Added @ts-expect-error for runtime-converted types
- Fixed all @polkadot copyright headers to @pezkuwi
2026-01-07 02:32:54 +03:00

55 lines
1.6 KiB
TypeScript

// Copyright 2017-2025 @pezkuwi/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiPromise } from '@pezkuwi/api';
import type { QueryableStorageEntry } from '@pezkuwi/api/types';
import type { DropdownOptions } from '../util/types.js';
import React from 'react';
import { useApi } from '@pezkuwi/react-hooks';
import Dropdown from '../Dropdown.js';
import { filterDropdownItems } from '../util/index.js';
interface Props {
className?: string;
isError?: boolean;
onChange: (value: QueryableStorageEntry<'promise'>) => void;
options: DropdownOptions;
value: QueryableStorageEntry<'promise'>;
}
function transform (api: ApiPromise, { value }: Props): (method: string) => QueryableStorageEntry<'promise'> {
return function (method: string): QueryableStorageEntry<'promise'> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return api.query[value.creator.section]
? api.query[value.creator.section][method] as any
: value;
};
}
function SelectKey (props: Props): React.ReactElement<Props> | null {
const { api } = useApi();
const { className = '', isError, onChange, options, value } = props;
if (!options.length) {
return null;
}
return (
<Dropdown
className={`${className} ui--DropdownLinked-Items`}
isError={isError}
onChange={onChange}
onSearch={filterDropdownItems}
options={options}
transform={transform(api, props)}
value={value.creator.method}
withLabel={false}
/>
);
}
export default React.memo(SelectKey);