// Copyright 2017-2019 @polkadot/react-components authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. import { TypeDef } from '@polkadot/types/types'; import { ParamDef, Props, RawParam } from '../types'; import React, { useEffect, useState } from 'react'; import Params from '../'; import Base from './Base'; import Static from './Static'; export default function StructParam (props: Props): React.ReactElement { const { className, isDisabled, label, onChange, style, type, withLabel } = props; const [params, setParams] = useState([]); useEffect((): void => { setParams((type.sub as TypeDef[]).map((subType): ParamDef => ({ name: subType.name, type: subType }))); }, [type]); if (isDisabled) { return ; } const _onChangeParams = (values: RawParam[]): void => { onChange && onChange({ isValid: values.reduce((result, { isValid }): boolean => result && isValid, true as boolean), value: params.reduce((value: Record, { name }, index): Record => { value[name as string] = values[index].value; return value; }, {}) }); }; return (
); }