From 6cd5e4d847899b324f09d3b8fcff80ea48afb5f5 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 12 Aug 2020 14:00:21 +0200 Subject: [PATCH] Strip newlines from hex input (#3403) * Strip newlines from hex input * Update packages/react-components/src/InputFile.tsx --- packages/page-sudo/src/Sudo.tsx | 3 +-- packages/react-components/src/InputFile.tsx | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/page-sudo/src/Sudo.tsx b/packages/page-sudo/src/Sudo.tsx index 68a6e6e36f..e4ceef67e7 100644 --- a/packages/page-sudo/src/Sudo.tsx +++ b/packages/page-sudo/src/Sudo.tsx @@ -27,8 +27,7 @@ function Sudo ({ className, isMine, sudoKey }: Props): React.ReactElement const [weight, setWeight] = useState(BN_ZERO); const _onChangeExtrinsic = useCallback( - (method: SubmittableExtrinsic<'promise'> | null = null) => - setMethod(() => method), + (method: SubmittableExtrinsic<'promise'> | null = null) => setMethod(() => method), [] ); diff --git a/packages/react-components/src/InputFile.tsx b/packages/react-components/src/InputFile.tsx index e7272fc62a..8aa477ff72 100644 --- a/packages/react-components/src/InputFile.tsx +++ b/packages/react-components/src/InputFile.tsx @@ -34,6 +34,7 @@ interface FileState { const BYTE_STR_0 = '0'.charCodeAt(0); const BYTE_STR_X = 'x'.charCodeAt(0); +const STR_NL = '\n'; const NOOP = (): void => undefined; function convertResult (result: ArrayBuffer): Uint8Array { @@ -41,7 +42,11 @@ function convertResult (result: ArrayBuffer): Uint8Array { // this converts the input (if detected as hex), via the hex conversion route if (data[0] === BYTE_STR_0 && data[1] === BYTE_STR_X) { - const hex = u8aToString(data); + let hex = u8aToString(data); + + while (hex[hex.length - 1] === STR_NL) { + hex = hex.substr(0, hex.length - 1); + } if (isHex(hex)) { return hexToU8a(hex);