@@ -75,25 +75,21 @@ export default function ContractIdentifier({
75
75
const jsonContent = await jsonFile . text ( ) ;
76
76
const stdJson = JSON . parse ( jsonContent ) ;
77
77
78
- if ( stdJson . sources ) {
79
- for ( const [ filePath , sourceInfo ] of Object . entries ( stdJson . sources ) ) {
80
- if ( sourceInfo && typeof sourceInfo === "object" && "content" in sourceInfo ) {
81
- const sourceContent = ( sourceInfo as any ) . content ;
82
- if ( typeof sourceContent === "string" ) {
83
- if ( selectedLanguage === "solidity" ) {
84
- const fileContracts = await parseFileContent ( filePath , sourceContent ) ;
85
- contracts . push ( ...fileContracts ) ;
86
- } else if ( selectedLanguage === "vyper" && filePath . endsWith ( ".vy" ) ) {
87
- // For Vyper, generate contract identifier from file path
88
- const contractName = filePath . split ( "/" ) . pop ( ) ?. replace ( ".vy" , "" ) || "" ;
89
- if ( contractName ) {
90
- contracts . push ( {
91
- fileName : filePath ,
92
- contractName,
93
- fullIdentifier : `${ filePath } :${ contractName } ` ,
94
- } ) ;
95
- }
96
- }
78
+ for ( const [ filePath , sourceInfo ] of Object . entries ( stdJson . sources ) ) {
79
+ if ( sourceInfo && typeof sourceInfo === "object" && "content" in sourceInfo ) {
80
+ const sourceContent = ( sourceInfo as any ) . content ;
81
+ if ( selectedLanguage === "solidity" ) {
82
+ const fileContracts = await parseFileContent ( filePath , sourceContent ) ;
83
+ contracts . push ( ...fileContracts ) ;
84
+ } else if ( selectedLanguage === "vyper" && filePath . endsWith ( ".vy" ) ) {
85
+ // For Vyper, generate contract identifier from file path
86
+ const contractName = filePath . split ( "/" ) . pop ( ) ?. replace ( ".vy" , "" ) || "" ;
87
+ if ( contractName ) {
88
+ contracts . push ( {
89
+ fileName : filePath ,
90
+ contractName,
91
+ fullIdentifier : `${ filePath } :${ contractName } ` ,
92
+ } ) ;
97
93
}
98
94
}
99
95
}
@@ -167,7 +163,7 @@ export default function ContractIdentifier({
167
163
}
168
164
} , [ isDropdownOpen ] ) ;
169
165
170
- const parseFileContent = async ( fileName : string , content : string ) : Promise < ParsedContract [ ] > => {
166
+ const parseFileContent = async ( fileName : string | null , content : string ) : Promise < ParsedContract [ ] > => {
171
167
try {
172
168
const ast = parse ( content , {
173
169
loc : false ,
@@ -180,6 +176,11 @@ export default function ContractIdentifier({
180
176
if ( ast . children ) {
181
177
for ( const child of ast . children ) {
182
178
if ( child . type === "ContractDefinition" && child . name ) {
179
+ if ( ! fileName ) {
180
+ const extension = selectedLanguage === "solidity" ? ".sol" : ".vy" ;
181
+ fileName = `${ child . name } ${ extension } ` ;
182
+ }
183
+
183
184
contracts . push ( {
184
185
fileName,
185
186
contractName : child . name ,
@@ -191,8 +192,7 @@ export default function ContractIdentifier({
191
192
192
193
return contracts ;
193
194
} catch ( error ) {
194
- console . warn ( `Failed to parse ${ fileName } :` , error ) ;
195
- return [ ] ;
195
+ throw new Error ( `Failed to parse ${ fileName } : ${ error } ` ) ;
196
196
}
197
197
} ;
198
198
@@ -298,12 +298,9 @@ export default function ContractIdentifier({
298
298
>
299
299
< span >
300
300
{ contractIdentifier ? (
301
- < >
302
- { contractIdentifier . substring ( 0 , contractIdentifier . lastIndexOf ( ":" ) ) } :
303
- < span className = "font-bold" >
304
- { contractIdentifier . substring ( contractIdentifier . lastIndexOf ( ":" ) + 1 ) }
305
- </ span >
306
- </ >
301
+ < span className = "font-bold" >
302
+ { contractIdentifier . substring ( contractIdentifier . lastIndexOf ( ":" ) + 1 ) }
303
+ </ span >
307
304
) : (
308
305
< span className = "text-gray-500" > Select a contract...</ span >
309
306
) }
@@ -338,7 +335,7 @@ export default function ContractIdentifier({
338
335
} }
339
336
className = "w-full px-3 py-2 text-left hover:bg-gray-50 focus:bg-gray-50 focus:outline-none font-mono text-sm"
340
337
>
341
- { contract . fileName } : < span className = "font-bold" > { contract . contractName } </ span >
338
+ < span className = "font-bold" > { contract . contractName } </ span >
342
339
</ button >
343
340
) )
344
341
) : (
0 commit comments