Skip to content

Commit ce7dbe0

Browse files
committed
fix: missing snip-12 enum type dependency
1 parent 2b69310 commit ce7dbe0

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

src/utils/typedData.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -167,36 +167,46 @@ export function getDependencies(
167167
contains: string = '',
168168
revision: Revision = Revision.LEGACY
169169
): string[] {
170+
let dependencyTypes: string[] = [type];
171+
170172
// Include pointers (struct arrays)
171173
if (type[type.length - 1] === '*') {
172-
type = type.slice(0, -1);
174+
dependencyTypes = [type.slice(0, -1)];
173175
} else if (revision === Revision.ACTIVE) {
174176
// enum base
175177
if (type === 'enum') {
176-
type = contains;
178+
dependencyTypes = [contains];
177179
}
178180
// enum element types
179181
else if (type.match(/^\(.*\)$/)) {
180-
type = type.slice(1, -1);
182+
dependencyTypes = type
183+
.slice(1, -1)
184+
.split(',')
185+
.map((depType) => (depType[depType.length - 1] === '*' ? depType.slice(0, -1) : depType));
181186
}
182187
}
183188

184-
if (dependencies.includes(type) || !types[type]) {
185-
return dependencies;
186-
}
187-
188-
return [
189-
type,
190-
...(types[type] as StarknetEnumType[]).reduce<string[]>(
191-
(previous, t) => [
192-
...previous,
193-
...getDependencies(types, t.type, previous, t.contains, revision).filter(
194-
(dependency) => !previous.includes(dependency)
195-
),
189+
return dependencyTypes
190+
.filter((t) => !dependencies.includes(t) && types[t])
191+
.reduce<string[]>(
192+
// This comment prevents prettier from rolling everything here into a single line.
193+
(p, depType) => [
194+
...p,
195+
...[
196+
depType,
197+
...(types[depType] as StarknetEnumType[]).reduce<string[]>(
198+
(previous, t) => [
199+
...previous,
200+
...getDependencies(types, t.type, previous, t.contains, revision).filter(
201+
(dependency) => !previous.includes(dependency)
202+
),
203+
],
204+
[]
205+
),
206+
].filter((dependency) => !p.includes(dependency)),
196207
],
197208
[]
198-
),
199-
];
209+
);
200210
}
201211

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

0 commit comments

Comments
 (0)