Democracy propose invalid Bytes disabled (#1715)
This commit is contained in:
parent
5328d54294
commit
87ead2bf39
@ -35,7 +35,8 @@ class Propose extends TxModal<Props, State> {
|
||||
|
||||
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<Props, State> {
|
||||
|
||||
private onChangeExtrinsic = (method?: Call): void => {
|
||||
if (!method) {
|
||||
return;
|
||||
return this.nextState({ method: null });
|
||||
}
|
||||
|
||||
this.nextState({ method });
|
||||
|
||||
@ -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<Props> {
|
||||
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<Props> {
|
||||
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 (
|
||||
<Bare
|
||||
@ -85,9 +85,9 @@ export default function BaseBytes (props: Props): React.ReactElement<Props> {
|
||||
defaultValue={defaultValue}
|
||||
isAction={!!children}
|
||||
isDisabled={isDisabled}
|
||||
isError={isError}
|
||||
isError={isError || !isValid}
|
||||
label={label}
|
||||
onChange={onChange(props)}
|
||||
onChange={_onChange}
|
||||
onEnter={onEnter}
|
||||
placeholder='0x...'
|
||||
type='text'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user