From 1cf7b5e6297717a21e7a2ea5d375e6c6ca7bd98e Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 17 Dec 2020 11:07:08 +0100 Subject: [PATCH] Allow InputAddress with no options (#4227) * Allow InputAddress with no options * Update packages/react-params/src/Param/index.tsx --- .../react-components/src/InputAddress/index.tsx | 8 +------- packages/react-params/src/Param/index.tsx | 13 ++++++++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/react-components/src/InputAddress/index.tsx b/packages/react-components/src/InputAddress/index.tsx index 4c7b3d732f..8e07add269 100644 --- a/packages/react-components/src/InputAddress/index.tsx +++ b/packages/react-components/src/InputAddress/index.tsx @@ -133,14 +133,8 @@ class InputAddress extends React.PureComponent { } public render (): React.ReactNode { - const { className = '', defaultValue, help, hideAddress = false, isDisabled = false, isError, isMultiple, label, labelExtra, options, optionsAll, placeholder, type = DEFAULT_TYPE, withEllipsis, withLabel } = this.props; + const { className = '', defaultValue, help, hideAddress = false, isDisabled = false, isError, isMultiple, label, labelExtra, options, placeholder, withEllipsis, withLabel } = this.props; const { lastValue, value } = this.state; - const hasOptions = (options && options.length !== 0) || (optionsAll && Object.keys(optionsAll[type]).length !== 0); - - if (!hasOptions && !isDisabled) { - return null; - } - const lastOption = this.getLastOptionValue(); const actualValue = transformToAddress( isDisabled || (defaultValue && this.hasValue(defaultValue)) diff --git a/packages/react-params/src/Param/index.tsx b/packages/react-params/src/Param/index.tsx index f45060a1dc..1d9d651990 100644 --- a/packages/react-params/src/Param/index.tsx +++ b/packages/react-params/src/Param/index.tsx @@ -1,9 +1,9 @@ // Copyright 2017-2020 @polkadot/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Props as CProps, Props } from '../types'; +import type { Props } from '../types'; -import React, { useMemo, useRef } from 'react'; +import React, { useMemo } from 'react'; import { encodeTypeDef } from '@polkadot/types/create'; import { isUndefined } from '@polkadot/util'; @@ -12,7 +12,10 @@ import findComponent from './findComponent'; import Static from './Static'; function Param ({ className = '', defaultValue, isDisabled, isInOption, isOptional, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement | null { - const compRef = useRef | null>(findComponent(registry, type, overrides)); + const Component = useMemo( + () => findComponent(registry, type, overrides), + [registry, type, overrides] + ); const label = useMemo( () => isUndefined(name) @@ -21,7 +24,7 @@ function Param ({ className = '', defaultValue, isDisabled, isInOption, isOption [name, type] ); - if (!compRef.current) { + if (!Component) { return null; } @@ -34,7 +37,7 @@ function Param ({ className = '', defaultValue, isDisabled, isInOption, isOption /> ) : ( -