ghost-portal/packages/react-components/src/InputExtrinsic/SelectMethod.tsx
2021-01-03 11:33:39 +01:00

47 lines
1.2 KiB
TypeScript

// Copyright 2017-2021 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { SubmittableExtrinsicFunction } from '@polkadot/api/types';
import type { DropdownOptions } from '../util/types';
import React, { useCallback } from 'react';
import { ApiPromise } from '@polkadot/api';
import Dropdown from '../Dropdown';
interface Props {
api: ApiPromise;
className?: string;
isError?: boolean;
onChange: (value: SubmittableExtrinsicFunction<'promise'>) => void;
options: DropdownOptions;
value: SubmittableExtrinsicFunction<'promise'>;
}
function SelectMethod ({ api, className = '', isError, onChange, options, value }: Props): React.ReactElement<Props> | null {
const transform = useCallback(
(method: string): SubmittableExtrinsicFunction<'promise'> =>
api.tx[value.section][method],
[api, value]
);
if (!options.length) {
return null;
}
return (
<Dropdown
className={`ui--DropdownLinked-Items ${className}`}
isError={isError}
onChange={onChange}
options={options}
transform={transform}
value={value.method}
withLabel={false}
/>
);
}
export default React.memo(SelectMethod);