@ -63,42 +63,39 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
const route = window . location . pathname
const route = window . location . pathname
if ( route . startsWith ( '/address/0x' ) && route . length === 51 ) {
if ( route . startsWith ( '/address/0x' ) && route . length === 51 ) {
const contractAddress = route . split ( '/' ) [ 2 ]
const contractAddress = route . split ( '/' ) [ 2 ]
plugin . call ( 'notification' , 'toast' , ` Looking for contract address ${ contractAddress } on different networks ` )
let data
let data
try {
try {
const etherscanKey = await plugin . call ( 'config' , 'getAppParameter' , 'etherscan-access-token' )
let etherscanKey = await plugin . call ( 'config' , 'getAppParameter' , 'etherscan-access-token' )
if ( ! etherscanKey ) {
if ( ! etherscanKey ) etherscanKey = '2HKUX5ZVASZIKWJM8MIQVCRUVZ6JAWT531'
plugin . call ( 'notification' , 'toast' , ` Cannot look for contract address ${ contractAddress } . Etherscan access token not found. Go to Remix settings page and save an access token. ` )
const networks = [
await basicWorkspaceInit ( workspaces , workspaceProvider )
{ id : 1 , name : 'mainnet' } ,
} else {
{ id : 3 , name : 'ropsten' } ,
const networks = [
{ id : 4 , name : 'rinkeby' } ,
{ id : 1 , name : 'mainnet' } ,
{ id : 42 , name : 'kovan' } ,
{ id : 3 , name : 'ropsten' } ,
{ id : 5 , name : 'goerli' }
{ id : 4 , name : 'rinkeby' } ,
]
{ id : 42 , name : 'kovan' } ,
plugin . call ( 'notification' , 'toast' , ` Looking for contract address ${ contractAddress } on different networks ` )
{ id : 5 , name : 'goerli' }
let found = false
]
for ( const network of networks ) {
plugin . call ( 'notification' , 'toast' , ` Looking for contract address ${ contractAddress } on different networks ` )
const target = ` / ${ network . name } `
let found = false
try {
for ( const network of networks ) {
data = await fetchContractFromEtherscan ( plugin , network , contractAddress , target , etherscanKey )
const target = ` / ${ network . name } `
} catch ( error ) {
try {
if ( ( error . message . startsWith ( 'contract not verified on Etherscan' ) || error . message . startsWith ( 'unable to retrieve contract data' ) ) && network . id !== 5 )
data = await fetchContractFromEtherscan ( plugin , network , contractAddress , target )
continue
} catch ( error ) {
else {
if ( ( error . message . startsWith ( 'contract not verified on Etherscan' ) || error . message . startsWith ( 'unable to retrieve contract data' ) ) && network . id !== 5 )
if ( ! found ) await basicWorkspaceInit ( workspaces , workspaceProvider )
continue
break
else {
if ( ! found ) await basicWorkspaceInit ( workspaces , workspaceProvider )
break
}
}
}
found = true
await createWorkspaceTemplate ( 'etherscan-code-sample' , 'code-template' )
plugin . setWorkspace ( { name : 'etherscan-code-sample' , isLocalhost : false } )
dispatch ( setCurrentWorkspace ( 'etherscan-code-sample' ) )
const filePath = Object . keys ( data . compilationTargets ) [ 0 ]
await workspaceProvider . set ( filePath , data . compilationTargets [ filePath ] [ 'content' ] )
plugin . on ( 'editor' , 'editorMounted' , async ( ) = > await plugin . fileManager . openFile ( filePath ) )
}
}
found = true
await createWorkspaceTemplate ( 'etherscan-code-sample' , 'code-template' )
plugin . setWorkspace ( { name : 'etherscan-code-sample' , isLocalhost : false } )
dispatch ( setCurrentWorkspace ( 'etherscan-code-sample' ) )
const filePath = Object . keys ( data . compilationTargets ) [ 0 ]
await workspaceProvider . set ( filePath , data . compilationTargets [ filePath ] [ 'content' ] )
plugin . on ( 'editor' , 'editorMounted' , async ( ) = > await plugin . fileManager . openFile ( filePath ) )
}
}
} catch ( error ) {
} catch ( error ) {
await basicWorkspaceInit ( workspaces , workspaceProvider )
await basicWorkspaceInit ( workspaces , workspaceProvider )