Display Bytes with ASCII as text (#3155)

This commit is contained in:
Jaco Greeff 2020-07-10 11:01:13 +02:00 committed by GitHub
parent b1d9f8c2f5
commit cf5b279110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,7 +8,7 @@ import { RawParam, RawParamOnChange, RawParamOnEnter, RawParamOnEscape, Size } f
import React, { useCallback, useState } from 'react';
import { Compact } from '@polkadot/types';
import { Input } from '@polkadot/react-components';
import { hexToU8a, isHex, u8aToHex } from '@polkadot/util';
import { hexToU8a, isAscii, isHex, isU8a, u8aToHex, u8aToString } from '@polkadot/util';
import { decodeAddress } from '@polkadot/util-crypto';
import Bare from './Bare';
@ -57,9 +57,11 @@ function convertInput (value: string): [boolean, Uint8Array] {
function BaseBytes ({ asHex, children, className = '', defaultValue: { value }, isDisabled, isError, label, length = -1, onChange, onEnter, onEscape, size = 'full', validate = defaultValidate, withLabel, withLength }: Props): React.ReactElement<Props> {
const [defaultValue] = useState(
value
? isHex(value)
? value
: u8aToHex(value as Uint8Array, isDisabled ? 256 : -1)
? isDisabled && isU8a(value) && isAscii(value)
? u8aToString(value)
: isHex(value)
? value
: u8aToHex(value as Uint8Array, isDisabled ? 256 : -1)
: undefined
);
const [isValid, setIsValid] = useState(false);