Skip to content

Commit

Permalink
Merge pull request #882 from alleslabs/fix/main-abi-opt-bool
Browse files Browse the repository at this point in the history
fix: main abi opt bool
  • Loading branch information
songwongtp authored Apr 11, 2024
2 parents 69533d8 + d7e0f3a commit 0c57314
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib/utils/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export const getArgType = (argType: string) =>
.replace("0x1::decimal128::Decimal128", BCS.DECIMAL128)
.replace("0x1::decimal256::Decimal256", BCS.DECIMAL256);

const getChildType = (parentType: string, type: string) => {
const [pType, childType] = type.split(/<(.*)>/);
return pType === parentType ? childType : undefined;
};
const getArgValue = ({
type,
value,
Expand All @@ -81,13 +85,14 @@ const getArgValue = ({
try {
if (value === null) return null;
if (type.startsWith("vector")) {
const [, elementType] = type.split(/<(.*)>/);
const elementType = getChildType("vector", type);
const elements = getVectorElements(value);
return elementType === "bool"
? elements.map((element) => element.toLowerCase() === "true")
: elements;
}
if (type === "bool") return value.toLowerCase() === "true";
if (type === "bool" || getChildType("0x1::option::Option", type) === "bool")
return value.toLowerCase() === "true";
return value.trim();
} catch (e) {
return "";
Expand Down

0 comments on commit 0c57314

Please sign in to comment.