* refactor: Rename InputStorage key to method to be consistent with InputExtrinsic
* fix: Add filter to both section and method that considers isHidden prop
* refactor: Move into meaningful private functions
* fix: Fix linting errors
* test: Add Unit Tests to check shouldDisplaySection function
* fix: Remove unnecessary import
* restore file naming
* refactor: Move shouldDisplaySection into utils folder
* refactor: Move more common functionality into util
* remove unused isObject
* restore by removing unnecessary types. propose private type for storage
* fix: Remove explicit passing through the type for storage since its default
* feat: Use shared logic for showing section and methods in InputRpc
* refactor: Move shared types into util folder with section visibility type
* fix: type is public or private
* WIP: methods[name] TypeScript error
Element implicitly has an 'any' type because type '{}' has no index signature
* fix: Fix TSLint errors using jacos solution
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
// Copyright 2017-2018 @polkadot/ui-app authors & contributors
|
|
// This software may be modified and distributed under the terms
|
|
// of the ISC license. See the LICENSE file for details.
|
|
|
|
import { SectionItem } from '@polkadot/params/types';
|
|
import { Extrinsics, Extrinsic$Sections } from '@polkadot/extrinsics/types';
|
|
import { I18nProps } from '../types';
|
|
import { DropdownOptions, SectionVisibilityAll } from '../util/types';
|
|
|
|
import React from 'react';
|
|
|
|
import extrinsics from '@polkadot/extrinsics';
|
|
|
|
import Dropdown from '../Dropdown';
|
|
import classes from '../util/classes';
|
|
import translate from '../translate';
|
|
|
|
type Props = I18nProps & {
|
|
isError?: boolean,
|
|
label?: string,
|
|
onChange: (value: SectionItem<Extrinsics>) => void,
|
|
options: DropdownOptions,
|
|
type: SectionVisibilityAll,
|
|
value: SectionItem<Extrinsics>,
|
|
withLabel?: boolean
|
|
};
|
|
|
|
// ({ className, isError, label = '', onChange, options, style, t, type, value: { name, section }, withLabel }: Props) {
|
|
class SelectMethod extends React.PureComponent<Props> {
|
|
|
|
render () {
|
|
const { className, isError, label = '', onChange, options, style, t, type, value: { name, section }, withLabel } = this.props;
|
|
|
|
if (!options.length) {
|
|
return null;
|
|
}
|
|
|
|
const transform = (name: Extrinsic$Sections): SectionItem<Extrinsics> =>
|
|
extrinsics[section][type][name];
|
|
|
|
return (
|
|
<Dropdown
|
|
className={classes('ui--DropdownLinked-Items', className)}
|
|
isError={isError}
|
|
label={label || t('input.extrinsic.method', {
|
|
defaultValue: 'with the extrinsic'
|
|
})}
|
|
onChange={onChange}
|
|
options={options}
|
|
style={style}
|
|
transform={transform}
|
|
value={name}
|
|
withLabel={withLabel}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default translate(SelectMethod);
|