Promise for minixhr:

uiCheck
LianaHus 5 years ago
parent 18dde6ec1b
commit 9ad5e3dfa5
  1. 2
      src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js
  2. 44
      src/app/compiler/compiler-utils.js
  3. 70
      src/app/tabs/compileTab/compilerContainer.js

@ -107,7 +107,7 @@ export default class FetchAndCompile extends Plugin {
version: data.metadata.compiler.version,
languageName: data.metadata.language,
evmVersion: data.metadata.settings.evmVersion,
optimize: data.metadata.settings.optimizer.enabled,
optimize: data.metadata.settings.optimizer.enabled
}
try {
setTimeout(_ => this.emit('compiling', settings), 0)

@ -1,11 +1,13 @@
const semver = require('semver')
const minixhr = require('minixhr')
/* global Worker */
export const baseURLBin = 'https://solc-bin.ethereum.org/bin'
export const baseURLWasm = 'https://solc-bin.ethereum.org/wasm'
export const pathToURL = []
export const pathToURL = {}
// retrieves the URL of the given compiler version
export function urlFromVersion (version) {
return `${pathToURL[version]}/${version}`
}
@ -15,45 +17,23 @@ export function urlFromVersion (version) {
* checks a compiler whitelist, browser support and OS.
*/
export function canUseWorker (selectedVersion) {
// Following restrictions should be deleted when Solidity will release fixed versions of compilers.
// See https://github.com/ethereum/remix-ide/issues/2461
/* const isChrome = !!window.chrome
const os = retrieveOS()
// define a whitelist for Linux
const linuxWL = ['0.4.26', '0.5.3', '0.5.4', '0.5.5']
const version = semver.coerce(selectedVersion)
// defining whitelist for chrome
let isFromWhiteList = false
switch (os) {
case 'Windows':
isFromWhiteList = semver.gt(version, '0.5.2') || version === '0.4.26'
break
case 'Linux':
isFromWhiteList = semver.gt(version, '0.5.13') || linuxWL.includes(version)
break
default :
isFromWhiteList = true
} */
const version = semver.coerce(selectedVersion)
const isNightly = selectedVersion.includes('nightly')
return browserSupportWorker() &&
(
return browserSupportWorker() && (
semver.gt(version, '0.6.3') ||
semver.gt(version, '0.3.5') && !isNightly
semver.gt(version, '0.3.6') && !isNightly
)
// && (!isChrome || (isChrome && isFromWhiteList))
}
function browserSupportWorker () {
return document.location.protocol !== 'file:' && Worker !== undefined
}
/* function retrieveOS () {
let osName = 'Unknown OS'
if (navigator.platform.indexOf('Win') !== -1) {
osName = 'Windows'
} else if (navigator.platform.indexOf('Linux') !== -1) {
osName = 'Linux'
// returns a promice for minixhr
export function promisedMiniXhr (url) {
return new Promise((resolve, reject) => {
minixhr(url, (json, event) => {
resolve({ json, event })
})
})
}
return osName
} */

@ -1,12 +1,11 @@
const yo = require('yo-yo')
const minixhr = require('minixhr')
const helper = require('../../../lib/helper')
const addTooltip = require('../../ui/tooltip')
const semver = require('semver')
const modalDialogCustom = require('../../ui/modal-dialog-custom')
const css = require('../styles/compile-tab-styles')
import { canUseWorker, baseURLBin, baseURLWasm, urlFromVersion, pathToURL } from '../../compiler/compiler-utils'
import { canUseWorker, baseURLBin, baseURLWasm, urlFromVersion, pathToURL, promisedMiniXhr } from '../../compiler/compiler-utils'
class CompilerContainer {
@ -414,61 +413,42 @@ class CompilerContainer {
if (this._view.version) this._view.version.innerText = text
}
// fetching both normal and wasm builds and creating an array [version, baseUrl]
fetchAllVersion (callback) {
let allVersions, selectedVersion, allVersionsWasm, urls
// fetching both normal and wasm builds and creating a [version, baseUrl] map
async fetchAllVersion (callback) {
let allVersions, selectedVersion, allVersionsWasm
// fetch normal builds
minixhr(`${this.data.baseURLBin}/list.json`, (json, event) => {
// @TODO: optimise and cache results to improve app loading times #2461
if (event.type !== 'error') {
const binRes = await promisedMiniXhr(`${this.data.baseURLBin}/list.json`)
// fetch wasm builds
const wasmRes = await promisedMiniXhr(`${this.data.baseURLWasm}/list.json`)
if (binRes.event.type === 'error' && wasmRes.event.type === 'error') {
allVersions = [{ path: 'builtin', longVersion: 'latest local version' }]
selectedVersion = 'builtin'
callback(allVersions, selectedVersion)
}
try {
const data = JSON.parse(json)
allVersions = data.builds.slice().reverse()
allVersions = JSON.parse(binRes.json).builds.slice().reverse()
selectedVersion = this.data.defaultVersion
if (this.queryParams.get().version) selectedVersion = this.queryParams.get().version
// no fetching wasm builds
minixhr(`${this.data.baseURLWasm}/list.json`, (json, event) => {
// @TODO: optimise and cache results to improve app loading times #2461
if (event.type !== 'error') {
try {
const data = JSON.parse(json)
allVersionsWasm = data.builds.slice().reverse()
//selectedVersion = this.data.defaultVersion
if (this.queryParams.get().version) selectedVersion = this.queryParams.get().version
// rewriting all versions in allVersions which exist in allVersionsWasm
if (allVersionsWasm && allVersions)
allVersions.forEach((compiler, index) => {
const rewritten = allVersionsWasm.findIndex(oldCompiler => { return oldCompiler.longVersion === compiler.longVersion })
if (-1 !== rewritten) {
allVersions[index] = allVersionsWasm[rewritten]
pathToURL[compiler.path] = baseURLWasm
} else {
pathToURL[compiler.path] = baseURLBin
if (wasmRes.event.type !== 'error') {
allVersionsWasm = JSON.parse(wasmRes.json).builds.slice().reverse()
}
})
callback(allVersions, selectedVersion)
} catch (e) {
addTooltip('Cannot load compiler version list. It might have been blocked by an advertisement blocker. Please try deactivating any of them from this page and reload.')
addTooltip('Cannot load compiler version list. It might have been blocked by an advertisement blocker. Please try deactivating any of them from this page and reload. Error: ' + e)
}
// replace in allVersions those compiler builds which exist in allVersionsWasm with new once
if (allVersionsWasm && allVersions) {
allVersions.forEach((compiler, index) => {
const wasmIndex = allVersionsWasm.findIndex(wasmCompiler => { return wasmCompiler.longVersion === compiler.longVersion })
if (wasmIndex !== -1) {
allVersions[index] = allVersionsWasm[wasmIndex]
pathToURL[compiler.path] = baseURLWasm
} else {
allVersionsWasm = [{ path: 'builtin', longVersion: 'latest local version' }]
selectedVersion = 'builtin'
pathToURL[compiler.path] = baseURLBin
}
//callback(allVersions, selectedVersion)
})
} catch (e) {
addTooltip('Cannot load compiler version list. It might have been blocked by an advertisement blocker. Please try deactivating any of them from this page and reload.')
}
} else {
allVersions = [{ path: 'builtin', longVersion: 'latest local version' }]
selectedVersion = 'builtin'
}
//callback(allVersions, selectedVersion)
})
callback(allVersions, selectedVersion)
}
scheduleCompilation () {
if (!this.config.get('autoCompile')) return
if (this.data.compileTimeout) window.clearTimeout(this.data.compileTimeout)

Loading…
Cancel
Save