diff --git a/package.json b/package.json index 4c899eb578..967adf8eec 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "remix-lib": "latest", "remix-solidity": "latest", "remixd": "git+https://github.com/ethereum/remixd.git", + "request": "^2.83.0", "rimraf": "^2.6.1", "selenium-standalone": "^6.0.1", "standard": "^8.5.0", diff --git a/src/app.js b/src/app.js index 73f2c21cd8..77890695d6 100644 --- a/src/app.js +++ b/src/app.js @@ -201,14 +201,18 @@ function run () { if (provider && provider.exists(url)) { return provider.get(url, cb) } - handleImports.import(url, (error, content, cleanUrl, type, url) => { - if (!error) { - filesProviders[type].addReadOnly(cleanUrl, content, url) - cb(null, content) - } else { - cb(error) - } - }) + handleImports.import(url, + (loadingMsg) => { + $('#output').append($('
').append($('
').text(loadingMsg)))
+      },
+      (error, content, cleanUrl, type, url) => {
+        if (!error) {
+          filesProviders[type].addReadOnly(cleanUrl, content, url)
+          cb(null, content)
+        } else {
+          cb(error)
+        }
+      })
   })
   var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event)
 
diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js
index a6162cb972..9730f9b046 100644
--- a/src/app/compiler/compiler-imports.js
+++ b/src/app/compiler/compiler-imports.js
@@ -1,23 +1,30 @@
 'use strict'
-// TODO: can just use request or fetch instead
-var $ = require('jquery')
 var base64 = require('js-base64').Base64
 var swarmgw = require('swarmgw')
+var request = require('request')
 
 module.exports = {
   handleGithubCall: function (root, path, cb) {
-    return $.getJSON('https://api.github.com/repos/' + root + '/contents/' + path)
-      .done(function (data) {
+    return request.get(
+      {
+        url: 'https://api.github.com/repos/' + root + '/contents/' + path,
+        json: true,
+        headers: {
+          'User-Agent': 'Remix'
+        }
+      },
+      (err, r, data) => {
+        if (err) {
+          return cb(err || 'Unknown transport error')
+        }
         if ('content' in data) {
           cb(null, base64.decode(data.content), root + '/' + path)
+        } else if ('message' in data) {
+          cb(data.message)
         } else {
           cb('Content not received')
         }
       })
-      .fail(function (xhr, text, err) {
-        // NOTE: on some browsers, err equals to '' for certain errors (such as offline browser)
-        cb(err || 'Unknown transport error')
-      })
   },
 
   handleSwarmImport: function (url, cb) {
@@ -30,14 +37,19 @@ module.exports = {
     // replace ipfs:// with /ipfs/
     url = url.replace(/^ipfs:\/\/?/, 'ipfs/')
 
-    return $.ajax({ type: 'GET', url: 'https://gateway.ipfs.io/' + url })
-      .done(function (data) {
+    return request.get(
+      {
+        url: 'https://gateway.ipfs.io/' + url,
+        headers: {
+          'User-Agent': 'Remix'
+        }
+      },
+      (err, r, data) => {
+        if (err) {
+          return cb(err || 'Unknown transport error')
+        }
         cb(null, data, url)
       })
-      .fail(function (xhr, text, err) {
-        // NOTE: on some browsers, err equals to '' for certain errors (such as offline browser)
-        cb(err || 'Unknown transport error')
-      })
   },
 
   handlers: function () {
@@ -48,7 +60,7 @@ module.exports = {
     ]
   },
 
-  import: function (url, cb) {
+  import: function (url, loadingCb, cb) {
     var handlers = this.handlers()
 
     var found = false
@@ -61,8 +73,7 @@ module.exports = {
       if (match) {
         found = true
 
-        // TODO: this needs to be moved to the caller
-        $('#output').append($('
').append($('
').text('Loading ' + url + ' ...')))
+        loadingCb('Loading ' + url + ' ...')
         handler.handler(match, function (err, content, cleanUrl) {
           if (err) {
             cb('Unable to import "' + cleanUrl + '": ' + err)