fix loading external files

pull/5370/head
yann300 3 years ago
parent d384db7a67
commit 364b009976
  1. 17
      libs/remix-ui/workspace/src/lib/actions/workspace.ts

@ -85,7 +85,7 @@ export const loadWorkspacePreset = async (template: 'gist-template' | 'code-temp
case 'code-template':
// creates a new workspace code-sample and loads code from url params.
try {
let path = ''; let content = ''
let path = ''; let content
if (params.code) {
const hash = bufferToHex(keccakFromString(params.code))
@ -99,15 +99,20 @@ export const loadWorkspacePreset = async (template: 'gist-template' | 'code-temp
path = data.cleanUrl
content = data.content
if (content && typeof content === 'object') {
const standardInput = content as JSONStandardInput
if (standardInput.language && standardInput.language === "Solidity" && standardInput.sources) {
try {
content = JSON.parse(content) as any
if (content.language && content.language === "Solidity" && content.sources) {
const standardInput: JSONStandardInput = content as JSONStandardInput
for (const [fname, source] of Object.entries(standardInput.sources)) {
await workspaceProvider.set(fname, source.content)
}
return Object.keys(standardInput.sources)[0]
} else {
workspaceProvider.set(path, JSON.stringify(content))
}
return Object.keys(standardInput.sources)[0]
} else {
} catch (e) {
console.log(e)
workspaceProvider.set(path, content)
}
}

Loading…
Cancel
Save