From b3984350e4231d7da2f1c35cca6d20edb7e44f93 Mon Sep 17 00:00:00 2001 From: Zhi-Qiang Lei Date: Tue, 26 Apr 2022 13:23:51 +0800 Subject: [PATCH] Memorize parsed NativeScript --- src/pages/treasuries/[base64CBOR]/new.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pages/treasuries/[base64CBOR]/new.tsx b/src/pages/treasuries/[base64CBOR]/new.tsx index 8ba96eb5..85b5d353 100644 --- a/src/pages/treasuries/[base64CBOR]/new.tsx +++ b/src/pages/treasuries/[base64CBOR]/new.tsx @@ -339,16 +339,20 @@ const GetTreasury: NextPage = () => { const router = useRouter() const { base64CBOR } = router.query const cardano = useCardanoMultiplatformLib() + const parseResult = useMemo(() => { + if (!cardano) return; + return getResult(() => { + if (typeof base64CBOR !== 'string') throw new Error('Invalid Script'); + return cardano.lib.NativeScript.from_bytes(Buffer.from(base64CBOR, 'base64')) + }) + }, [cardano, base64CBOR]) - if (!cardano) return ; - if (typeof base64CBOR !== 'string') return Invalid script; - const parseResult = getResult(() => cardano.lib.NativeScript.from_bytes(Buffer.from(base64CBOR, 'base64'))) - if (!parseResult.isOk) return Invalid script; - const script = parseResult.data + if (!cardano || !parseResult) return ; + if (!parseResult.isOk) return {parseResult.message}; return + script={parseResult.data} /> } export default GetTreasury