mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-08-06 16:25:49 +00:00
1295c36241
- 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
55 lines
1.6 KiB
TypeScript
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);
|