From cf5b2791108b9903add836f4b99060b6da3b24cd Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 10 Jul 2020 11:01:13 +0200 Subject: [PATCH] Display Bytes with ASCII as text (#3155) --- packages/react-params/src/Param/BaseBytes.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/react-params/src/Param/BaseBytes.tsx b/packages/react-params/src/Param/BaseBytes.tsx index 4567f86eba..28b31c43e8 100644 --- a/packages/react-params/src/Param/BaseBytes.tsx +++ b/packages/react-params/src/Param/BaseBytes.tsx @@ -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 { 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);