diff --git a/src/codec-components/LookupTypeEdit/LookupTypeEdit.tsx b/src/codec-components/LookupTypeEdit/LookupTypeEdit.tsx index a980078..930059e 100644 --- a/src/codec-components/LookupTypeEdit/LookupTypeEdit.tsx +++ b/src/codec-components/LookupTypeEdit/LookupTypeEdit.tsx @@ -4,6 +4,7 @@ import { byteArraysAreEqual } from "@/utils/byteArray" import { CodecComponentType, CodecComponentValue, + NOTIN, } from "@polkadot-api/react-builder" import { state, useStateObservable } from "@react-rxjs/core" import { Codec } from "polkadot-api" @@ -142,6 +143,7 @@ const useCodecProps = ( if (!codec) return const encodedValue = (() => { if (componentValue.value.encoded) return componentValue.value.encoded + if (detectNotin(componentValue.value.decoded)) return null try { return codec.enc(componentValue.value.decoded) } catch (_) { @@ -224,3 +226,9 @@ const useCodecProps = ( }), } } +const detectNotin: (x: T) => boolean = (x) => { + if (x === NOTIN) return true + return x != null && typeof x === "object" + ? Object.values(x).some(detectNotin) + : false +} diff --git a/src/utils/shape.ts b/src/utils/shape.ts index 1180792..b57fa14 100644 --- a/src/utils/shape.ts +++ b/src/utils/shape.ts @@ -58,9 +58,10 @@ export const getDefaultValue = (innerVar: Var, depth = 0): any => { case "struct": return mapObject(innerVar.value, (v) => nextDefault(v)) case "array": - return new Array(innerVar.len) - .fill(0) - .map(() => nextDefault(innerVar.value)) + return innerVar.value.type === "primitive" && + innerVar.value.value === "u8" + ? NOTIN + : new Array(innerVar.len).fill(0).map(() => nextDefault(innerVar.value)) case "tuple": return innerVar.value.map(nextDefault) case "enum": {