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() runCompiler()
if (queryParams.get().context) { 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) { if (queryParams.get().debugtx) {

@ -238,13 +238,32 @@ function runTab (container, appAPI, appEvents, opts) {
// DROPDOWN // DROPDOWN
var selectExEnv = el.querySelector('#selectExEnvOptions') 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) { selectExEnv.addEventListener('change', function (event) {
executionContext.executionContextChange(selectExEnv.options[selectExEnv.selectedIndex].value, null, () => { 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() modalDialogCustom.confirm(null, 'Are you sure you want to connect to an ethereum node?', () => {
fillAccountsList(appAPI, el) let endPointUrl = null;
events.trigger('clearInstance', []) 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() selectExEnv.value = executionContext.getProvider()
fillAccountsList(appAPI, el) fillAccountsList(appAPI, el)

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

Loading…
Cancel
Save