From 1ff990f541c520d3a10af1ce7c3aaef80936c51f Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 28 Jun 2021 10:45:47 +0200 Subject: [PATCH] get token when using import --- apps/remix-ide/src/app.js | 4 ++-- .../src/lib/compiler-content-imports.ts | 5 +++-- libs/remix-url-resolver/src/resolve.ts | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index 323ec0ba86..3f855b5f02 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.js @@ -460,11 +460,11 @@ Please make a backup of your contracts and start using http://remix.ethereum.org console.log('couldn\'t register iframe plugins', e.message) } - await appManager.activatePlugin(['settings', 'contentImport', 'theme', 'editor', 'fileManager', 'compilerMetadata', 'compilerArtefacts', 'network', 'web3Provider', 'offsetToLineColumnConverter']) + await appManager.activatePlugin(['theme', 'editor', 'fileManager', 'compilerMetadata', 'compilerArtefacts', 'network', 'web3Provider', 'offsetToLineColumnConverter']) await appManager.activatePlugin(['mainPanel', 'menuicons', 'tabs']) await appManager.activatePlugin(['sidePanel']) // activating host plugin separately await appManager.activatePlugin(['home']) - await appManager.activatePlugin(['hiddenPanel', 'pluginManager', 'filePanel', 'contextualListener', 'terminal', 'fetchAndCompile']) + await appManager.activatePlugin(['hiddenPanel', 'pluginManager', 'filePanel', 'settings', 'contextualListener', 'terminal', 'fetchAndCompile', 'contentImport']) const queryParams = new QueryParams() const params = queryParams.get() diff --git a/libs/remix-core-plugin/compiler-content-imports/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/compiler-content-imports/src/lib/compiler-content-imports.ts index d860dc4729..85450a04d9 100644 --- a/libs/remix-core-plugin/compiler-content-imports/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/compiler-content-imports/src/lib/compiler-content-imports.ts @@ -22,10 +22,10 @@ export class CompilerImports extends Plugin { this.previouslyHandled = {} // cache import so we don't make the request at each compilation. } - async onActivation () { + async setToken () { const protocol = typeof window !== 'undefined' && window.location.protocol const token = await this.call('settings', 'getGithubAccessToken') - this.urlResolver = new RemixURLResolver(token, protocol) + this.urlResolver.setGistToken(token, protocol) } isRelativeImport (url) { @@ -71,6 +71,7 @@ export class CompilerImports extends Plugin { let resolved try { + await this.setToken() resolved = await this.urlResolver.resolve(url) const { content, cleanUrl, type } = resolved self.previouslyHandled[url] = { diff --git a/libs/remix-url-resolver/src/resolve.ts b/libs/remix-url-resolver/src/resolve.ts index 13029cefbd..adfc05d862 100644 --- a/libs/remix-url-resolver/src/resolve.ts +++ b/libs/remix-url-resolver/src/resolve.ts @@ -30,6 +30,10 @@ export class RemixURLResolver { constructor (gistToken?: string, protocol = 'http:') { this.previouslyHandled = {} + this.setGistToken(gistToken, protocol) + } + + async setGistToken (gistToken?: string, protocol = 'http:') { this.gistAccessToken = gistToken || '' this.protocol = protocol }