handle error

pull/2450/head^2
Aniket-Engg 2 years ago committed by Aniket
parent 209b890db0
commit 1c68619d81
  1. 34
      libs/remix-ui/workspace/src/lib/actions/index.ts

@ -23,6 +23,21 @@ export type UrlParametersType = {
url: string
}
const basicWorkspaceInit = async (workspaces, workspaceProvider) => {
if (workspaces.length === 0) {
await createWorkspaceTemplate('default_workspace', 'remixDefault')
plugin.setWorkspace({ name: 'default_workspace', isLocalhost: false })
dispatch(setCurrentWorkspace('default_workspace'))
await loadWorkspacePreset('remixDefault')
} else {
if (workspaces.length > 0) {
workspaceProvider.setWorkspace(workspaces[workspaces.length - 1])
plugin.setWorkspace({ name: workspaces[workspaces.length - 1], isLocalhost: false })
dispatch(setCurrentWorkspace(workspaces[workspaces.length - 1]))
}
}
}
export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.Dispatch<any>) => {
if (filePanelPlugin) {
plugin = filePanelPlugin
@ -50,6 +65,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
const contractAddress = route.split('/')[2]
const network = {id: 1, name: 'main'}
const target = `/${network.name}`
try {
const data = await fetchContractFromEtherscan(plugin, network, contractAddress, target)
await createWorkspaceTemplate('etherscan-code-sample', 'code-template')
plugin.setWorkspace({ name: 'etherscan-code-sample', isLocalhost: false })
@ -57,20 +73,14 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
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))
}
} else {
if (workspaces.length === 0) {
await createWorkspaceTemplate('default_workspace', 'remixDefault')
plugin.setWorkspace({ name: 'default_workspace', isLocalhost: false })
dispatch(setCurrentWorkspace('default_workspace'))
await loadWorkspacePreset('remixDefault')
} else {
if (workspaces.length > 0) {
workspaceProvider.setWorkspace(workspaces[workspaces.length - 1])
plugin.setWorkspace({ name: workspaces[workspaces.length - 1], isLocalhost: false })
dispatch(setCurrentWorkspace(workspaces[workspaces.length - 1]))
} catch (error) {
if(error.message.includes('unable to retrieve contract data') || error.message.includes('unable to try fetching the source code'))
plugin.call('notification', 'toast', error.message)
await basicWorkspaceInit(workspaces, workspaceProvider)
}
}
} else {
await basicWorkspaceInit(workspaces, workspaceProvider)
}
listenOnPluginEvents(plugin)

Loading…
Cancel
Save