Skip to content

Commit

Permalink
Memorize parsed NativeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
siegfried committed Apr 26, 2022
1 parent 6565e0c commit b398435
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/pages/treasuries/[base64CBOR]/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Loading />;
if (typeof base64CBOR !== 'string') return <ErrorMessage>Invalid script</ErrorMessage>;
const parseResult = getResult(() => cardano.lib.NativeScript.from_bytes(Buffer.from(base64CBOR, 'base64')))
if (!parseResult.isOk) return <ErrorMessage>Invalid script</ErrorMessage>;
const script = parseResult.data
if (!cardano || !parseResult) return <Loading />;
if (!parseResult.isOk) return <ErrorMessage>{parseResult.message}</ErrorMessage>;

return <GetUTxOsToSpend
cardano={cardano}
script={script} />
script={parseResult.data} />
}

export default GetTreasury

0 comments on commit b398435

Please sign in to comment.