Skip to content

Commit

Permalink
fix: missing snip-12 enum type dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Jan 1, 2025
1 parent 2b69310 commit ce7dbe0
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions src/utils/typedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,36 +167,46 @@ export function getDependencies(
contains: string = '',
revision: Revision = Revision.LEGACY
): string[] {
let dependencyTypes: string[] = [type];

// Include pointers (struct arrays)
if (type[type.length - 1] === '*') {
type = type.slice(0, -1);
dependencyTypes = [type.slice(0, -1)];
} else if (revision === Revision.ACTIVE) {
// enum base
if (type === 'enum') {
type = contains;
dependencyTypes = [contains];
}
// enum element types
else if (type.match(/^\(.*\)$/)) {
type = type.slice(1, -1);
dependencyTypes = type
.slice(1, -1)
.split(',')
.map((depType) => (depType[depType.length - 1] === '*' ? depType.slice(0, -1) : depType));
}
}

if (dependencies.includes(type) || !types[type]) {
return dependencies;
}

return [
type,
...(types[type] as StarknetEnumType[]).reduce<string[]>(
(previous, t) => [
...previous,
...getDependencies(types, t.type, previous, t.contains, revision).filter(
(dependency) => !previous.includes(dependency)
),
return dependencyTypes
.filter((t) => !dependencies.includes(t) && types[t])
.reduce<string[]>(
// This comment prevents prettier from rolling everything here into a single line.
(p, depType) => [
...p,
...[
depType,
...(types[depType] as StarknetEnumType[]).reduce<string[]>(
(previous, t) => [
...previous,
...getDependencies(types, t.type, previous, t.contains, revision).filter(
(dependency) => !previous.includes(dependency)
),
],
[]
),
].filter((dependency) => !p.includes(dependency)),
],
[]
),
];
);
}

function getMerkleTreeType(types: TypedData['types'], ctx: Context) {
Expand Down

0 comments on commit ce7dbe0

Please sign in to comment.