diff --git a/packages/page-storage/src/Selection/Modules.tsx b/packages/page-storage/src/Selection/Modules.tsx index 862af6ae8d..b2be8813dd 100644 --- a/packages/page-storage/src/Selection/Modules.tsx +++ b/packages/page-storage/src/Selection/Modules.tsx @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 import type { QueryableStorageEntry } from '@polkadot/api/types'; -import type { RawParams } from '@polkadot/react-params/types'; +import type { RawParams, TypeDefExt } from '@polkadot/react-params/types'; import type { StorageEntryTypeLatest } from '@polkadot/types/interfaces'; -import type { Inspect, Registry, TypeDef } from '@polkadot/types/types'; +import type { Inspect, Registry } from '@polkadot/types/types'; import type { ComponentProps as Props } from '../types'; import React, { useCallback, useMemo, useState } from 'react'; @@ -21,10 +21,6 @@ import { compactStripLength, isHex, isNull, isUndefined, u8aToHex } from '@polka import { useTranslation } from '../translate'; -interface TypeDefExt extends TypeDef { - withOptionActive?: boolean; -} - type ParamsType = { type: TypeDefExt }[]; interface KeyState { @@ -70,6 +66,7 @@ function expandParams (registry: Registry, st: StorageEntryTypeLatest, isIterabl if (isIterable && index === (types.length - 1)) { type = getTypeDef(`Option<${str}>`); type.withOptionActive = true; + type.withOptionNaked = true; } else { type = getTypeDef(str); } diff --git a/packages/page-storage/src/Selection/index.tsx b/packages/page-storage/src/Selection/index.tsx index 25181c7e63..21afd127f4 100644 --- a/packages/page-storage/src/Selection/index.tsx +++ b/packages/page-storage/src/Selection/index.tsx @@ -40,7 +40,7 @@ function Selection ({ basePath, onAdd }: Props): React.ReactElement { ]); const _onAdd = useCallback( - (query: ParitalQueryTypes): void => onAdd({ ...query, id: ++id }), + (query: ParitalQueryTypes) => onAdd({ ...query, id: ++id }), [onAdd] ); diff --git a/packages/react-params/src/Holder.tsx b/packages/react-params/src/Holder.tsx index ffd013b424..35775eb133 100644 --- a/packages/react-params/src/Holder.tsx +++ b/packages/react-params/src/Holder.tsx @@ -13,7 +13,7 @@ interface Props { function Holder ({ children, className = '', withBorder, withPadding }: Props): React.ReactElement { return ( -
+
{children}
); @@ -21,16 +21,15 @@ function Holder ({ children, className = '', withBorder, withPadding }: Props): export default React.memo(styled(Holder)` &.withBorder { - padding-left: 0.25rem; + padding-left: 1.5rem; .ui--Params-Content { border-left: 0.25rem solid #f2f2f2; - } - } - &.withoutBorder { - margin-left: -1.75rem; - padding: 0; + .ui--Params.withBorder { + padding-left: 0.25rem; + } + } } &.withPadding { diff --git a/packages/react-params/src/Param/BaseBytes.tsx b/packages/react-params/src/Param/BaseBytes.tsx index 4e628ddf6c..ffc8f0b2a4 100644 --- a/packages/react-params/src/Param/BaseBytes.tsx +++ b/packages/react-params/src/Param/BaseBytes.tsx @@ -1,8 +1,7 @@ // Copyright 2017-2022 @polkadot/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { TypeDef } from '@polkadot/types/types'; -import type { RawParam, RawParamOnChange, RawParamOnEnter, RawParamOnEscape, Size } from '../types'; +import type { RawParam, RawParamOnChange, RawParamOnEnter, RawParamOnEscape, Size, TypeDefExt } from '../types'; import React, { useCallback, useState } from 'react'; import styled from 'styled-components'; @@ -29,11 +28,12 @@ interface Props { onEnter?: RawParamOnEnter; onEscape?: RawParamOnEscape; size?: Size; - type: TypeDef & { withOptionActive?: boolean }; + type: TypeDefExt; validate?: (u8a: Uint8Array) => boolean; withCopy?: boolean; withLabel?: boolean; withLength?: boolean; + withOptionNaked?: boolean; } interface Validity { @@ -68,7 +68,7 @@ function convertInput (value: string): [boolean, boolean, Uint8Array] { : [value === '0x', false, new Uint8Array([])]; } -function BaseBytes ({ asHex, children, className = '', defaultValue: { value }, isDisabled, isError, isInOption, label, length = -1, onChange, onEnter, onEscape, size = 'full', validate = defaultValidate, withCopy, withLabel, withLength }: Props): React.ReactElement { +function BaseBytes ({ asHex, children, className = '', defaultValue: { value }, isDisabled, isError, isInOption, label, length = -1, onChange, onEnter, onEscape, size = 'full', type: { withOptionNaked }, validate = defaultValidate, withCopy, withLabel, withLength }: Props): React.ReactElement { const { t } = useTranslation(); const [defaultValue] = useState( (): string | undefined => { @@ -102,7 +102,7 @@ function BaseBytes ({ asHex, children, className = '', defaultValue: { value }, value = compactAddLength(value); } - if (isInOption && isValid) { + if (isInOption && isValid && !withOptionNaked) { value = u8aConcat([1], value); } @@ -115,7 +115,7 @@ function BaseBytes ({ asHex, children, className = '', defaultValue: { value }, setValidity({ isAddress, isValid, lastValue: value }); }, - [asHex, length, onChange, validate, withLength, isInOption] + [asHex, isInOption, length, onChange, validate, withLength, withOptionNaked] ); return ( diff --git a/packages/react-params/src/Param/Option.tsx b/packages/react-params/src/Param/Option.tsx index abc5b2b0ce..c00ebe8846 100644 --- a/packages/react-params/src/Param/Option.tsx +++ b/packages/react-params/src/Param/Option.tsx @@ -4,18 +4,19 @@ import type { Codec, TypeDef } from '@polkadot/types/types'; import type { Props } from '../types'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import styled from 'styled-components'; import { Toggle } from '@polkadot/react-components'; import { Option } from '@polkadot/types'; +import { objectSpread } from '@polkadot/util'; import { useTranslation } from '../translate'; import Param from './index'; const DEF_VALUE = { isValid: true, value: undefined }; -function OptionDisplay ({ className = '', defaultValue: _defaultValue, isDisabled, name, onChange, onEnter, onEscape, registry, type: { sub, withOptionActive } }: Props): React.ReactElement { +function OptionDisplay ({ className = '', defaultValue: _defaultValue, isDisabled, name, onChange, onEnter, onEscape, registry, type: { sub, withOptionActive, withOptionNaked } }: Props): React.ReactElement { const { t } = useTranslation(); const [isActive, setIsActive] = useState(() => withOptionActive || !!(_defaultValue && _defaultValue.value instanceof Option && _defaultValue.value.isSome) || false); const [defaultValue] = useState( @@ -27,6 +28,10 @@ function OptionDisplay ({ className = '', defaultValue: _defaultValue, isDisable ) : DEF_VALUE ); + const subType = useMemo( + () => objectSpread({}, sub, { withOptionNaked }), + [sub, withOptionNaked] + ); useEffect((): void => { !isActive && onChange && onChange({ @@ -47,7 +52,7 @@ function OptionDisplay ({ className = '', defaultValue: _defaultValue, isDisable onEnter={onEnter} onEscape={onEscape} registry={registry} - type={sub as TypeDef} + type={subType} /> {!isDisabled && ( { onEnter={onEnter} onEscape={onEscape} type={type} - withLength={false} /> ); } diff --git a/packages/react-params/src/types.ts b/packages/react-params/src/types.ts index 46f98ba869..f589f9820a 100644 --- a/packages/react-params/src/types.ts +++ b/packages/react-params/src/types.ts @@ -44,7 +44,7 @@ export interface Props { // eslint-disable-next-line no-use-before-define overrides?: ComponentMap; registry: Registry; - type: TypeDef & { withOptionActive?: boolean }; + type: TypeDefExt; withLabel?: boolean; } @@ -66,3 +66,8 @@ export interface ExpandedCid { }; version: 0 | 1; } + +export interface TypeDefExt extends TypeDef { + withOptionActive?: boolean; + withOptionNaked?: boolean; +}