@@ -29,6 +29,7 @@ export type UrlParametersType = {
29
29
opendir : string ,
30
30
blockscout : string ,
31
31
ghfolder : string
32
+ endpoint : string
32
33
}
33
34
34
35
const basicWorkspaceInit = async ( workspaces : { name : string ; isGitRepo : boolean ; } [ ] , workspaceProvider ) => {
@@ -136,39 +137,25 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
136
137
try {
137
138
let etherscanKey = await plugin . call ( 'config' , 'getAppParameter' , 'etherscan-access-token' )
138
139
if ( ! etherscanKey ) etherscanKey = '2HKUX5ZVASZIKWJM8MIQVCRUVZ6JAWT531'
139
- const networks = [
140
- { id : 1 , name : 'mainnet' } ,
141
- { id : 11155111 , name : 'sepolia' }
142
- ]
143
- let found = false
144
140
const workspaceName = 'code-sample'
145
141
let filePath
146
142
const foundOnNetworks = [ ]
147
- for ( const network of networks ) {
148
- const target = `/${ network . name } /${ contractAddress } `
149
- try {
150
- data = await fetchContractFromEtherscan ( plugin , network , contractAddress , target , false , etherscanKey )
151
- } catch ( error ) {
152
- if ( ( error . message . startsWith ( 'contract not verified on Etherscan' ) || error . message . startsWith ( 'unable to retrieve contract data' ) ) && network . id !== 5 )
153
- continue
154
- else {
155
- if ( ! found ) await basicWorkspaceInit ( workspaces , workspaceProvider )
156
- break
157
- }
158
- }
159
- found = true
160
- foundOnNetworks . push ( network . name )
161
- if ( await workspaceExists ( workspaceName ) ) workspaceProvider . setWorkspace ( workspaceName )
162
- else await createWorkspaceTemplate ( workspaceName , 'code-template' )
163
- plugin . setWorkspace ( { name : workspaceName , isLocalhost : false } )
164
- dispatch ( setCurrentWorkspace ( { name : workspaceName , isGitRepo : false } ) )
165
- count = count + ( Object . keys ( data . compilationTargets ) ) . length
166
- for ( filePath in data . compilationTargets )
167
- await workspaceProvider . set ( filePath , data . compilationTargets [ filePath ] [ 'content' ] )
168
-
169
- if ( data . config ) {
170
- await workspaceProvider . set ( 'compiler_config.json' , JSON . stringify ( data . config , null , '\t' ) )
171
- }
143
+ const endpoint = params . endpoint || 'api.etherscan.io'
144
+ try {
145
+ data = await fetchContractFromEtherscan ( plugin , endpoint , contractAddress , '' , false , etherscanKey )
146
+ } catch ( error ) {
147
+ await basicWorkspaceInit ( workspaces , workspaceProvider )
148
+ }
149
+ if ( await workspaceExists ( workspaceName ) ) workspaceProvider . setWorkspace ( workspaceName )
150
+ else await createWorkspaceTemplate ( workspaceName , 'code-template' )
151
+ plugin . setWorkspace ( { name : workspaceName , isLocalhost : false } )
152
+ dispatch ( setCurrentWorkspace ( { name : workspaceName , isGitRepo : false } ) )
153
+ count = count + ( Object . keys ( data . compilationTargets ) ) . length
154
+ for ( filePath in data . compilationTargets )
155
+ await workspaceProvider . set ( filePath , data . compilationTargets [ filePath ] [ 'content' ] )
156
+
157
+ if ( data . config ) {
158
+ await workspaceProvider . set ( 'compiler_config.json' , JSON . stringify ( data . config , null , '\t' ) )
172
159
}
173
160
174
161
plugin . on ( 'filePanel' , 'workspaceInitializationCompleted' , async ( ) => {
0 commit comments