@@ -5,6 +5,7 @@ import {
|
||||
import { Modal } from "@/components/Modal"
|
||||
import { useGenericSynchronizeInput } from "@/components/useSynchroniseInput"
|
||||
import { NOTIN } from "@polkadot-api/react-builder"
|
||||
import { Binary } from "@polkadot-api/substrate-bindings"
|
||||
import { Download, FileUp } from "lucide-react"
|
||||
import { ComponentProps, FC, useMemo, useState } from "react"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
@@ -12,7 +13,6 @@ import { twMerge } from "tailwind-merge"
|
||||
import { saveAs } from "save-as"
|
||||
import { BinaryEdit } from "./Icons"
|
||||
import { ActionButton } from "./ActionButton"
|
||||
import { fromHex, toHex } from "polkadot-api/utils"
|
||||
|
||||
export interface BinaryEditProps {
|
||||
initialValue?: Uint8Array
|
||||
@@ -80,13 +80,17 @@ const BinaryEditModalContent: FC<
|
||||
const [inputValue, setInputValue] = useGenericSynchronizeInput(
|
||||
value,
|
||||
setValue as any,
|
||||
parseInput,
|
||||
(input) => parseInput(input).asBytes(),
|
||||
"" as string | Uint8Array,
|
||||
(value) => {
|
||||
if (value.length > MAX_DISPLAY_SIZE) return ""
|
||||
return toHex(value)
|
||||
return Binary.fromBytes(value).asHex()
|
||||
},
|
||||
(input, value) => checkEqualInputBinary(parseInput(input), value),
|
||||
(input, value) =>
|
||||
checkEqualInputBinary(
|
||||
parseInput(input),
|
||||
value === NOTIN ? NOTIN : Binary.fromBytes(value),
|
||||
),
|
||||
)
|
||||
|
||||
const placeholder =
|
||||
@@ -154,7 +158,7 @@ const BinaryEditModalContent: FC<
|
||||
<BinaryFileInput
|
||||
validate={validateFile}
|
||||
onError={() => setError("Error loading file")}
|
||||
onLoaded={setValue}
|
||||
onLoaded={(value) => setValue(value.asBytes())}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
@@ -182,4 +186,6 @@ const BinaryEditModalContent: FC<
|
||||
}
|
||||
|
||||
const parseInput = (value: string | Uint8Array) =>
|
||||
value instanceof Uint8Array ? value : fromHex(value)
|
||||
value instanceof Uint8Array
|
||||
? Binary.fromBytes(value)
|
||||
: Binary.fromHex(value.startsWith("0x") ? value : `0x${value}`)
|
||||
|
||||
Reference in New Issue
Block a user