Skip to content

Commit

Permalink
fix: decode uplc crash app
Browse files Browse the repository at this point in the history
  • Loading branch information
Tifa authored and Tifa committed Apr 2, 2024
1 parent ce08462 commit ca23ddc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/components/Contracts/UPLCTree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useTheme } from "@emotion/react";

import { CloseSquareIcon, MinusSquareIcon, PlusSquareIcon } from "src/commons/resources";
import { UPLCData, UPLCProgram } from "src/types/uplc";
import NotAvailable from "src/components/commons/NotAvailable";

import { StyledTreeItem, TreeContainer } from "./styles";

Expand Down Expand Up @@ -43,6 +44,14 @@ export const UPLCTree: React.FC<UPLCTreeProps> = ({ uplc }) => {
return nodeIds;
};

if (!uplc.version.major) {
return (
<>
<NotAvailable />
</>
);
}

return (
<TreeContainer
defaultCollapseIcon={<MinusSquareIcon fill={theme.isDark ? theme.palette.secondary.light : "none"} />}
Expand Down
9 changes: 7 additions & 2 deletions src/components/Contracts/common/CompiledCodeDataCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ const CompiledCodeDataCard: React.FC<CompiledCodeDataCardProps> = ({ value, titl
const { t } = useTranslation();
const [checked, setChecked] = useState(false);
const [uplc, setUplc] = useState<UPLCProgram>();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const str = (window as any).decodeUPLC(`${value}`);
let str = "";
try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
str = (window as any).decodeUPLC(`${value}`);
} catch (error) {
/* empty */
}

const version = str
.substring(0, findSecondIndex(str, "("))
Expand Down

0 comments on commit ca23ddc

Please sign in to comment.