diff --git a/packages/ui-app/src/Params/Param/BaseBytes.tsx b/packages/ui-app/src/Params/Param/BaseBytes.tsx index 8253395aa3..60629798d2 100644 --- a/packages/ui-app/src/Params/Param/BaseBytes.tsx +++ b/packages/ui-app/src/Params/Param/BaseBytes.tsx @@ -5,8 +5,9 @@ import { Props as BaseProps, Size } from '../types'; import React from 'react'; - import hexToU8a from '@polkadot/util/hex/toU8a'; +import bnToU8a from '@polkadot/util/bn/toU8a'; +import u8aConcat from '@polkadot/util/u8a/concat'; import Input from '../../Input'; import Bare from './Bare'; @@ -14,7 +15,8 @@ import Bare from './Bare'; type Props = BaseProps & { length?: number, size?: Size, - validate?: (u8a: Uint8Array) => boolean + validate?: (u8a: Uint8Array) => boolean, + withLength?: boolean }; const defaultValidate = (u8a: Uint8Array): boolean => @@ -44,9 +46,9 @@ export default class BaseBytes extends React.PureComponent { } onChange = (hex: string): void => { - const { length = -1, onChange, validate = defaultValidate } = this.props; + const { length = -1, onChange, validate = defaultValidate, withLength = false } = this.props; - let u8a; + let u8a: Uint8Array; try { u8a = hexToU8a(hex); @@ -57,10 +59,16 @@ export default class BaseBytes extends React.PureComponent { const isValidLength = length !== -1 ? u8a.length === length : u8a.length !== 0; + const isValid = isValidLength && validate(u8a); onChange({ - isValid: isValidLength && validate(u8a), - value: u8a + isValid, + value: u8aConcat( + withLength + ? bnToU8a(u8a.length, 32, true) + : new Uint8Array([]), + u8a + ) }); } } diff --git a/packages/ui-app/src/Params/Param/Bytes.tsx b/packages/ui-app/src/Params/Param/Bytes.tsx index 34dc6715e3..273d103ac7 100644 --- a/packages/ui-app/src/Params/Param/Bytes.tsx +++ b/packages/ui-app/src/Params/Param/Bytes.tsx @@ -8,20 +8,25 @@ import React from 'react'; import BaseBytes from './BaseBytes'; -export default function Bytes ({ className, defaultValue, isDisabled, isError, label, name, onChange, style, withLabel }: Props) { - return ( - - ); +export default class Bytes extends React.PureComponent { + render () { + const { className, defaultValue, isDisabled, isError, label, name, onChange, style, withLabel } = this.props; + + return ( + + ); + } }