-
-
- {hex ? (
- hex.slice(0, displayLength) + (exceedsDisplayLength ? "…" : "")
- ) : (
+
+
+
+ {isEmpty ? (
- {isEmpty
- ? "Start by filling out your extrinsic, or enter a binary using the edit binary button at the end of this line."
- : "Cannot display hex. Complete the required values."}
+ Start by filling out your extrinsic, or enter a binary using the
+ edit binary button at the end of this line.
+ ) : (
+ <>
+ 0x
+
+ >
)}
-
+
+ setWrap((v) => !v)}
+ />
+ {
+ const encoded = codec.enc(decoded)
+ onUpdate({ empty: false, decoded, encoded })
+ return true
+ }}
+ decode={codec.dec}
+ iconProps={{
+ size: 24,
+ }}
+ />
+
)
diff --git a/src/pages/Extrinsics/Extrinsics.tsx b/src/pages/Extrinsics/Extrinsics.tsx
index 2c10a9a..e0626e4 100644
--- a/src/pages/Extrinsics/Extrinsics.tsx
+++ b/src/pages/Extrinsics/Extrinsics.tsx
@@ -2,11 +2,7 @@ import { metadata$ } from "@/chain.state"
import { ActionButton } from "@/components/ActionButton"
import { ButtonGroup } from "@/components/ButtonGroup"
import { withSubscribe } from "@/components/withSuspense"
-import {
- CodecComponentType,
- CodecComponentValue,
- NOTIN,
-} from "@codec-components"
+import { CodecComponentType, CodecComponentValue } from "@codec-components"
import { getDynamicBuilder, getLookupFn } from "@polkadot-api/metadata-builders"
import { Binary } from "@polkadot-api/substrate-bindings"
import { state, useStateObservable } from "@react-rxjs/core"
@@ -28,17 +24,16 @@ const extrinsicProps$ = state(
})),
),
)
-const extrinsicDecoder = extrinsicProps$.pipeState(
- map(
- ({ metadata, codecType }) =>
- getDynamicBuilder(getLookupFn(metadata)).buildDefinition(codecType).dec,
+const extrinsicCodec = extrinsicProps$.pipeState(
+ map(({ metadata, codecType }) =>
+ getDynamicBuilder(getLookupFn(metadata)).buildDefinition(codecType),
),
)
export const Extrinsics = withSubscribe(() => {
const [viewMode, setViewMode] = useState<"edit" | "json">("edit")
const extrinsicProps = useStateObservable(extrinsicProps$)
- const decoder = useStateObservable(extrinsicDecoder)
+ const codec = useStateObservable(extrinsicCodec)
const [componentValue, setComponentValue] = useState
({
type: CodecComponentType.Initial,
@@ -57,25 +52,12 @@ export const Extrinsics = withSubscribe(() => {
Extrinsics
+ setComponentValue({ type: CodecComponentType.Updated, value })
}
- decode={(value) => {
- try {
- return decoder(value)
- } catch (_) {
- return NOTIN
- }
- }}
- onValueChanged={(decoded) => {
- setComponentValue({
- type: CodecComponentType.Updated,
- value: { empty: false, decoded },
- })
- return true
- }}
/>
@@ -112,7 +94,7 @@ export const Extrinsics = withSubscribe(() => {
? Binary.fromHex(binaryValue).asBytes()
: binaryValue
}
- decode={decoder}
+ decode={codec.dec}
/>
)}