move UI part of executionContext change and set to the caller

pull/3094/head
Iuri Matias 7 years ago
parent c3b144f4bf
commit 0409fc1afc
  1. 20
      src/app.js
  2. 29
      src/app/tabs/run-tab.js
  3. 31
      src/execution-context.js

@ -784,7 +784,25 @@ function run () {
runCompiler()
if (queryParams.get().context) {
executionContext.setContext(queryParams.get().context, queryParams.get().endpointurl)
executionContext.setContext(queryParams.get().context, queryParams.get().endpointurl,
() => {
modalDialogCustom.confirm(null, 'Are you sure you want to connect to an ethereum node?', () => {
let context = queryParams.get().context;
let endPointUrl = queryParams.get().endPointUrl;
if (!endPointUrl) {
endPointUrl = 'http://localhost:8545'
}
modalDialogCustom.prompt(null, 'Web3 Provider Endpoint', endPointUrl, (target) => {
executionContext.setProviderFromEndpoint(target, context)
}, () => {})
}, () => {})
},
(alertMsg) => {
modalDialogCustom.alert(alertMsg)
})
}
if (queryParams.get().debugtx) {

@ -238,13 +238,32 @@ function runTab (container, appAPI, appEvents, opts) {
// DROPDOWN
var selectExEnv = el.querySelector('#selectExEnvOptions')
function setFinalContext() {
// set the final context. Cause it is possible that this is not the one we've originaly selected
selectExEnv.value = executionContext.getProvider()
fillAccountsList(appAPI, el)
events.trigger('clearInstance', [])
}
selectExEnv.addEventListener('change', function (event) {
executionContext.executionContextChange(selectExEnv.options[selectExEnv.selectedIndex].value, null, () => {
// set the final context. Cause it is possible that this is not the one we've originaly selected
selectExEnv.value = executionContext.getProvider()
fillAccountsList(appAPI, el)
events.trigger('clearInstance', [])
})
modalDialogCustom.confirm(null, 'Are you sure you want to connect to an ethereum node?', () => {
let endPointUrl = null;
let context = selectExEnv.options[selectExEnv.selectedIndex].value;
if (!endPointUrl) {
endPointUrl = 'http://localhost:8545'
}
modalDialogCustom.prompt(null, 'Web3 Provider Endpoint', endPointUrl, (target) => {
executionContext.setProviderFromEndpoint(target, context, setFinalContext)
}, setFinalContext)
}, setFinalContext)
}, (alertMsg) => {
modalDialogCustom.alert(alertMsg)
}, setFinalContext)
})
selectExEnv.value = executionContext.getProvider()
fillAccountsList(appAPI, el)

@ -145,23 +145,13 @@ function ExecutionContext () {
return vm
}
this.setContext = function (context, endPointUrl) {
this.setContext = function (context, endPointUrl, confirmCb, infoCb) {
executionContext = context
this.executionContextChange(context, endPointUrl)
this.executionContextChange(context, endPointUrl, confirmCb, infoCb)
}
this.executionContextChange = function (context, endPointUrl, cb) {
this.executionContextChange = function (context, endPointUrl, confirmCb, infoCb, cb) {
if (!cb) cb = () => {}
function runPrompt () {
if (!endPointUrl) {
endPointUrl = 'http://localhost:8545'
}
modalDialogCustom.prompt(null, 'Web3 Provider Endpoint', endPointUrl, (target) => {
setProviderFromEndpoint(target, context, cb)
}, () => {
cb()
})
}
if (context === 'vm') {
executionContext = context
@ -169,7 +159,7 @@ function ExecutionContext () {
vm.stateManager.checkpoint()
})
self.event.trigger('contextChanged', ['vm'])
cb()
return cb()
}
if (context === 'injected') {
@ -177,20 +167,18 @@ function ExecutionContext () {
var alertMsg = 'No injected Web3 provider found. '
alertMsg += 'Make sure your provider (e.g. MetaMask) is active and running '
alertMsg += '(when recently activated you may have to reload the page).'
modalDialogCustom.alert(alertMsg)
cb()
infoCb(alertMsg);
return cb()
} else {
executionContext = context
web3.setProvider(injectedProvider)
self.event.trigger('contextChanged', ['injected'])
cb()
return cb()
}
}
if (context === 'web3') {
modalDialogCustom.confirm(null, 'Are you sure you want to connect to an ethereum node?',
() => { runPrompt(endPointUrl) }, () => { cb() }
)
confirmCb(cb);
}
}
@ -213,7 +201,9 @@ function ExecutionContext () {
}
}, 15000)
// TODO: not used here anymore and needs to be moved
function setProviderFromEndpoint (endpoint, context, cb) {
if (!cb) cb = () => {}
var oldProvider = web3.currentProvider
if (endpoint === 'ipc') {
@ -234,6 +224,7 @@ function ExecutionContext () {
cb()
}
}
this.setProviderFromEndpoint = setProviderFromEndpoint;
}
module.exports = new ExecutionContext()

Loading…
Cancel
Save