Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/remix-ide/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
const workspace = pluginLoader.get()
const engine = new Engine(appManager)
engine.setPluginOption = ({ name, kind }) => {
if (kind === 'provider') return {queueTimeout: 60000 * 4}
if (kind === 'provider') return {queueTimeout: 60000 * 2}
if (name === 'LearnEth') return {queueTimeout: 60000}
return {queueTimeout: 10000}
}
Expand Down
16 changes: 13 additions & 3 deletions apps/remix-ide/src/app/files/compiler-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,20 @@ class CompilerMetadata extends Plugin {
}

// TODO: is only called by dropdownLogic and can be moved there
deployMetadataOf (contractName) {
deployMetadataOf (contractName, fileLocation) {
return new Promise((resolve, reject) => {
var provider = this.fileManager.currentFileProvider()
var path = this.fileManager.currentPath()
var provider
let path
if (fileLocation) {
provider = this.fileManager.fileProviderOf(fileLocation)
path = fileLocation.split('/')
path.pop()
path = path.join('/')
} else {
provider = this.fileManager.currentFileProvider()
path = this.fileManager.currentPath()
}

if (provider && path) {
this.blockchain.detectNetwork((err, { id, name } = {}) => {
if (err) {
Expand Down
6 changes: 4 additions & 2 deletions apps/remix-ide/src/app/tabs/network-module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Plugin } from '@remixproject/engine'
import * as packageJson from '../../../../../package.json'
import { Web3 } from 'web3'

export const profile = {
name: 'network',
Expand Down Expand Up @@ -59,8 +60,9 @@ export class NetworkModule extends Plugin {
}

/** Add a custom network to the list of available networks */
addNetwork (customNetwork) {
this.blockchain.addProvider(customNetwork)
addNetwork (network) { // { name, url }
const provider = network.url === 'ipc' ? new Web3.providers.IpcProvider() : new Web3.providers.HttpProvider(network.url)
this.blockchain.addProvider({ name: network.name, provider })
}

/** Remove a network to the list of availble networks */
Expand Down
2 changes: 1 addition & 1 deletion apps/remix-ide/src/app/tabs/runTab/contractDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class ContractDropdownUI {

let contractMetadata
try {
contractMetadata = await this.runView.call('compilerMetadata', 'deployMetadataOf', selectedContract.name)
contractMetadata = await this.runView.call('compilerMetadata', 'deployMetadataOf', selectedContract.name, selectedContract.contract.file)
} catch (error) {
return statusCb(`creation of ${selectedContract.name} errored: ` + (error.message ? error.message : error))
}
Expand Down
25 changes: 15 additions & 10 deletions apps/remix-ide/src/app/tabs/runTab/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SettingsUI {

setInterval(() => {
this.updateAccountBalances()
}, 10 * 1000)
}, 1000)

this.accountListCallId = 0
this.loadedAccounts = {}
Expand Down Expand Up @@ -145,7 +145,7 @@ class SettingsUI {

setInterval(() => {
this.updateNetwork()
}, 5000)
}, 1000)

this.el = el

Expand All @@ -156,24 +156,26 @@ class SettingsUI {
setDropdown (selectExEnv) {
this.selectExEnv = selectExEnv

this.blockchain.event.register('addProvider', (network) => {
const addProvider = (network) => {
selectExEnv.appendChild(yo`<option
title="Manually added environment: ${network.url}"
title="provider name: ${network.name}"
value="${network.name}"
name="executionContext"
>
${network.name}
</option>`)
addTooltip(`${network.name} [${network.url}] added`)
})
addTooltip(yo`<span><b>${network.name}</b> provider added</span>`)
}

this.blockchain.event.register('removeProvider', (name) => {
const removeProvider = (name) => {
var env = selectExEnv.querySelector(`option[value="${name}"]`)
if (env) {
selectExEnv.removeChild(env)
addTooltip(`${name} removed`)
addTooltip(yo`<span><b>${name}</b> provider removed</span>`)
}
})
}
this.blockchain.event.register('addProvider', provider => addProvider(provider))
this.blockchain.event.register('removeProvider', name => removeProvider(name))

selectExEnv.addEventListener('change', (event) => {
let context = selectExEnv.options[selectExEnv.selectedIndex].value
Expand Down Expand Up @@ -241,7 +243,10 @@ class SettingsUI {
this.onPersonalChange()
}
break
default:
default: {
plusBtn.classList.add(css.disableMouseEvents)
plusTitle.title = `Unfortunately it's not possible to create an account using an external wallet (${this.selectExEnv.value}).`
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions apps/remix-ide/src/app/udapp/run-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,29 @@ export class RunTab extends LibraryPlugin {
this.renderDropdown(this.udappUI, this.fileManager, this.compilersArtefacts, this.config, this.editor, this.logCallback)
this.renderRecorder(this.udappUI, this.fileManager, this.config, this.logCallback)
this.renderRecorderCard()

const addPluginProvider = (profile) => {
if (profile.kind === 'provider') {
((profile, app) => {
const web3Provider = {
async sendAsync (payload, callback) {
try {
const result = await app.call(profile.name, 'sendAsync', payload)
callback(null, result)
} catch (e) {
callback(e)
}
}
}
app.blockchain.addProvider({ name: profile.displayName, provider: web3Provider })
})(profile, this)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really necessary (() => {})() it feels like it could be removed, and use this instead of app

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed yes.
(() => {})() is to make sure the creation of the provider is encapsulated. (that the local var profile doesn't get overridden in case the event callback is triggered multiple time.
But there might be better way to handle that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I had to keep this ...

}
}
const removePluginProvider = (profile) => {
if (profile.kind === 'provider') this.blockchain.removeProvider(profile.displayName)
}
this.on('manager', 'pluginActivated', addPluginProvider.bind(this))
this.on('manager', 'pluginDeactivated', removePluginProvider.bind(this))
return this.renderContainer()
}
}
9 changes: 5 additions & 4 deletions apps/remix-ide/src/blockchain/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class Blockchain {

getCurrentProvider () {
const provider = this.getProvider()
return this.providers[provider]
if (this.providers[provider]) return this.providers[provider]
return this.providers.web3 // default to the common type of provider
}

/** Return the list of accounts */
Expand Down Expand Up @@ -285,11 +286,11 @@ class Blockchain {
this.resetEnvironment()
}

addNetwork (customNetwork) {
this.executionContext.addProvider(customNetwork)
addProvider (provider) {
this.executionContext.addProvider(provider)
}

removeNetwork (name) {
removeProvider (name) {
this.executionContext.removeProvider(name)
}

Expand Down
15 changes: 13 additions & 2 deletions apps/remix-ide/src/remixAppManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function canActivate (name) {

export class RemixAppManager extends PluginManager {

constructor (plugins) {
constructor () {
super()
this.event = new EventEmitter()
this.pluginsDirectory = 'https://raw.githubusercontent.com/ethereum/remix-plugins-directory/master/build/metadata.json'
Expand Down Expand Up @@ -94,7 +94,18 @@ export class RemixAppManager extends PluginManager {

async registeredPlugins () {
const res = await fetch(this.pluginsDirectory)
const plugins = await res.json()
let plugins = await res.json()
plugins.push({
'name': 'walletconnect',
'kind': 'provider',
'displayName': 'Wallet Connect',
'events': [],
'methods': ['sendAsync'],
'url': 'ipfs://QmUD93rF9RKaDabCM5jFTHraBKd72HApbv7m9Vd5i5EHZe',
'description': 'Use an external wallet for transacting',
'icon': 'data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjUxMiIgdmlld0JveD0iMCAwIDUxMiA1MTIiIHdpZHRoPSI1MTIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxyYWRpYWxHcmFkaWVudCBpZD0iYSIgY3g9IjAlIiBjeT0iNTAlIiByPSIxMDAlIj48c3RvcCBvZmZzZXQ9IjAiIHN0b3AtY29sb3I9IiM1ZDlkZjYiLz48c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiMwMDZmZmYiLz48L3JhZGlhbEdyYWRpZW50PjxnIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCI+PHBhdGggZD0ib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XJ1bGU9Im5vbnplcm8iIHRyYW5zZm9ybT0idHJhbnNsYXRlKDk4IDE2MCkiLz48L2c+PC9zdmc+',
'location': 'mainPanel'
})
return plugins.map(plugin => new IframePlugin(plugin))
}
}
Expand Down
29 changes: 15 additions & 14 deletions libs/remix-lib/src/execution/execution-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,14 @@ function ExecutionContext () {

this.removeProvider = (name) => {
if (name && this.customNetWorks[name]) {
if (executionContext === name) this.setContext('vm', null)
delete this.customNetWorks[name]
this.event.trigger('removeProvider', [name])
}
}

this.addProvider = (network) => {
if (network && network.name && network.url) {
if (network && network.name && !this.customNetWorks[network.name]) {
this.customNetWorks[network.name] = network
this.event.trigger('addProvider', [network])
}
Expand All @@ -205,7 +206,8 @@ function ExecutionContext () {

this.executionContextChange = (context, endPointUrl, confirmCb, infoCb, cb) => {
if (!cb) cb = () => {}

if (!confirmCb) confirmCb = () => {}
if (!infoCb) infoCb = () => {}
if (context === 'vm') {
executionContext = context
vms[currentFork].stateManager.revert(() => {
Expand Down Expand Up @@ -234,8 +236,11 @@ function ExecutionContext () {
}

if (this.customNetWorks[context]) {
var provider = this.customNetWorks[context]
setProviderFromEndpoint(provider.url, 'web3', () => { cb() })
var network = this.customNetWorks[context]
this.setProviderFromEndpoint(network.provider, network.name, (error) => {
if (error) infoCb(error)
cb()
})
}
}

Expand Down Expand Up @@ -269,29 +274,25 @@ function ExecutionContext () {

// TODO: remove this when this function is moved
const self = this
// TODO: not used here anymore and needs to be moved
function setProviderFromEndpoint (endpoint, context, cb) {

this.setProviderFromEndpoint = (endpoint, context, cb) => {
const oldProvider = web3.currentProvider

if (endpoint === 'ipc') {
web3.setProvider(new web3.providers.IpcProvider())
} else {
web3.setProvider(new web3.providers.HttpProvider(endpoint))
}
web3.setProvider(endpoint)

web3.eth.net.isListening((err, isConnected) => {
if (!err && isConnected) {
executionContext = context
self._updateBlockGasLimit()
self.event.trigger('contextChanged', ['web3'])
self.event.trigger('contextChanged', [context])
self.event.trigger('web3EndpointChanged')
cb()
} else {
web3.setProvider(oldProvider)
cb('Not possible to connect to the Web3 provider. Make sure the provider is running and a connection is open (via IPC or RPC).')
cb('Not possible to connect to the Web3 provider. Make sure the provider is running, a connection is open (via IPC or RPC) or that the provider plugin is properly configured.')
}
})
}
this.setProviderFromEndpoint = setProviderFromEndpoint

this.txDetailsLink = (network, hash) => {
if (transactionDetailsLinks[network]) {
Expand Down
4 changes: 4 additions & 0 deletions libs/remix-lib/src/execution/txRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ class TxRunner {
})
}
this.executionContext.web3().eth.estimateGas(tx, (err, gasEstimation) => {
if (err && err.message.indexOf('Invalid JSON RPC response') !== -1) {
// // @todo(#378) this should be removed when https://github.com/WalletConnect/walletconnect-monorepo/issues/334 is fixed
err = 'Gas estimation failed because of an unknown internal error. This may indicated that the transaction will fail.'
}
gasEstimationForceSend(err, () => {
// callback is called whenever no error
tx.gas = !gasEstimation ? gasLimit : gasEstimation
Expand Down