Strip newlines from hex input (#3403)

* Strip newlines from hex input

* Update packages/react-components/src/InputFile.tsx
This commit is contained in:
Jaco Greeff 2020-08-12 14:00:21 +02:00 committed by GitHub
parent 4aecec7628
commit 6cd5e4d847
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -27,8 +27,7 @@ function Sudo ({ className, isMine, sudoKey }: Props): React.ReactElement<Props>
const [weight, setWeight] = useState<BN>(BN_ZERO);
const _onChangeExtrinsic = useCallback(
(method: SubmittableExtrinsic<'promise'> | null = null) =>
setMethod(() => method),
(method: SubmittableExtrinsic<'promise'> | null = null) => setMethod(() => method),
[]
);

View File

@ -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);