From 87ead2bf39f8d3f459c35e02117899cee122be9a Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 11 Oct 2019 10:57:27 +0200 Subject: [PATCH] Democracy propose invalid Bytes disabled (#1715) --- .../app-democracy/src/Overview/Propose.tsx | 5 +-- packages/react-params/src/Param/BaseBytes.tsx | 34 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/packages/app-democracy/src/Overview/Propose.tsx b/packages/app-democracy/src/Overview/Propose.tsx index 3bcde41958..09ca196080 100644 --- a/packages/app-democracy/src/Overview/Propose.tsx +++ b/packages/app-democracy/src/Overview/Propose.tsx @@ -35,7 +35,8 @@ class Propose extends TxModal { protected txParams = (): [Call, BN] => { const { value, method } = this.state; - return [createType('Proposal', method), value]; + + return [createType('Proposal', method || undefined), value]; } protected isDisabled = (): boolean => { @@ -104,7 +105,7 @@ class Propose extends TxModal { private onChangeExtrinsic = (method?: Call): void => { if (!method) { - return; + return this.nextState({ method: null }); } this.nextState({ method }); diff --git a/packages/react-params/src/Param/BaseBytes.tsx b/packages/react-params/src/Param/BaseBytes.tsx index 628a893fd0..079b5efe84 100644 --- a/packages/react-params/src/Param/BaseBytes.tsx +++ b/packages/react-params/src/Param/BaseBytes.tsx @@ -4,7 +4,7 @@ import { Props as BaseProps, Size } from '../types'; -import React from 'react'; +import React, { useState } from 'react'; import { Compact } from '@polkadot/types'; import { Input } from '@polkadot/react-components'; import { hexToU8a, isHex, u8aToHex } from '@polkadot/util'; @@ -39,11 +39,20 @@ function convertInput (value: string): [boolean, Uint8Array] { // we continue } - return [false, new Uint8Array([])]; + return [value === '0x', new Uint8Array([])]; } -function onChange ({ asHex, length = -1, onChange, validate = defaultValidate, withLength }: Props): (_: string) => void { - return function (hex: string): void { +export default function BaseBytes ({ asHex, children, className, defaultValue: { value }, isDisabled, isError, label, length = -1, onChange, onEnter, size = 'full', style, validate = defaultValidate, withLabel, withLength }: Props): React.ReactElement { + const [isValid, setIsValid] = useState(false); + const defaultValue = value + ? ( + isHex(value) + ? value + : u8aToHex(value as Uint8Array, isDisabled ? 256 : -1) + ) + : undefined; + + const _onChange = (hex: string): void => { let [isValid, value] = convertInput(hex); isValid = isValid && validate(value) && ( @@ -62,18 +71,9 @@ function onChange ({ asHex, length = -1, onChange, validate = defaultValidate, w ? u8aToHex(value) : value }); - }; -} -export default function BaseBytes (props: Props): React.ReactElement { - const { children, className, defaultValue: { value }, isDisabled, isError, label, onEnter, size = 'full', style, withLabel } = props; - const defaultValue = value - ? ( - isHex(value) - ? value - : u8aToHex(value as Uint8Array, isDisabled ? 256 : -1) - ) - : undefined; + setIsValid(isValid); + }; return ( { defaultValue={defaultValue} isAction={!!children} isDisabled={isDisabled} - isError={isError} + isError={isError || !isValid} label={label} - onChange={onChange(props)} + onChange={_onChange} onEnter={onEnter} placeholder='0x...' type='text'