Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
4cd6a9b7
Commit
4cd6a9b7
authored
Oct 02, 2017
by
yann300
Committed by
GitHub
Oct 02, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #837 from holgerd77/refactor-execution-context-change
Refactor/fix execution context change
parents
8540f374
8786773d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
18 deletions
+37
-18
execution-context.js
src/execution-context.js
+37
-18
No files found.
src/execution-context.js
View file @
4cd6a9b7
...
@@ -114,38 +114,44 @@ function ExecutionContext () {
...
@@ -114,38 +114,44 @@ function ExecutionContext () {
this
.
executionContextChange
=
function
(
context
,
endPointUrl
,
cb
)
{
this
.
executionContextChange
=
function
(
context
,
endPointUrl
,
cb
)
{
if
(
!
cb
)
cb
=
()
=>
{}
if
(
!
cb
)
cb
=
()
=>
{}
function
runPrompt
()
{
function
runPrompt
()
{
executionContext
=
context
if
(
!
endPointUrl
)
{
if
(
!
endPointUrl
)
{
endPointUrl
=
'http://localhost:8545'
endPointUrl
=
'http://localhost:8545'
}
}
modalDialogCustom
.
prompt
(
null
,
'Web3 Provider Endpoint'
,
endPointUrl
,
(
target
)
=>
{
modalDialogCustom
.
prompt
(
null
,
'Web3 Provider Endpoint'
,
endPointUrl
,
(
target
)
=>
{
setProviderFromEndpoint
(
target
)
setProviderFromEndpoint
(
target
,
context
,
cb
)
self
.
event
.
trigger
(
'contextChanged'
,
[
'web3'
])
cb
()
},
()
=>
{
},
()
=>
{
self
.
event
.
trigger
(
'contextChanged'
,
[
'web3'
])
cb
()
cb
()
})
})
}
}
if
(
context
===
'web3'
)
{
if
(
context
===
'vm'
)
{
modalDialogCustom
.
confirm
(
null
,
'Are you sure you want to connect to an ethereum node?'
,
()
=>
{
runPrompt
(
endPointUrl
)
},
()
=>
{
cb
()
}
)
}
else
if
(
context
===
'injected'
&&
injectedProvider
===
undefined
)
{
cb
()
}
else
{
if
(
context
===
'injected'
)
{
executionContext
=
context
web3
.
setProvider
(
injectedProvider
)
self
.
event
.
trigger
(
'contextChanged'
,
[
'injected'
])
}
else
if
(
context
===
'vm'
)
{
executionContext
=
context
executionContext
=
context
vm
.
stateManager
.
revert
(
function
()
{
vm
.
stateManager
.
revert
(
function
()
{
vm
.
stateManager
.
checkpoint
()
vm
.
stateManager
.
checkpoint
()
})
})
self
.
event
.
trigger
(
'contextChanged'
,
[
'vm'
])
self
.
event
.
trigger
(
'contextChanged'
,
[
'vm'
])
cb
()
}
}
if
(
context
===
'injected'
)
{
if
(
injectedProvider
===
undefined
)
{
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
()
}
else
{
executionContext
=
context
web3
.
setProvider
(
injectedProvider
)
self
.
event
.
trigger
(
'contextChanged'
,
[
'injected'
])
cb
()
}
}
if
(
context
===
'web3'
)
{
modalDialogCustom
.
confirm
(
null
,
'Are you sure you want to connect to an ethereum node?'
,
()
=>
{
runPrompt
(
endPointUrl
)
},
()
=>
{
cb
()
}
)
}
}
}
}
...
@@ -168,13 +174,26 @@ function ExecutionContext () {
...
@@ -168,13 +174,26 @@ function ExecutionContext () {
}
}
},
15000
)
},
15000
)
function
setProviderFromEndpoint
(
endpoint
)
{
function
setProviderFromEndpoint
(
endpoint
,
context
,
cb
)
{
var
oldProvider
=
web3
.
currentProvider
if
(
endpoint
===
'ipc'
)
{
if
(
endpoint
===
'ipc'
)
{
web3
.
setProvider
(
new
web3
.
providers
.
IpcProvider
())
web3
.
setProvider
(
new
web3
.
providers
.
IpcProvider
())
}
else
{
}
else
{
web3
.
setProvider
(
new
web3
.
providers
.
HttpProvider
(
endpoint
))
web3
.
setProvider
(
new
web3
.
providers
.
HttpProvider
(
endpoint
))
}
}
if
(
web3
.
isConnected
())
{
executionContext
=
context
self
.
event
.
trigger
(
'contextChanged'
,
[
'web3'
])
self
.
event
.
trigger
(
'web3EndpointChanged'
)
self
.
event
.
trigger
(
'web3EndpointChanged'
)
cb
()
}
else
{
web3
.
setProvider
(
oldProvider
)
var
alertMsg
=
'Not possible to connect to the Web3 provider. '
alertMsg
+=
'Make sure the provider is running and a connection is open (via IPC or RPC).'
modalDialogCustom
.
alert
(
alertMsg
)
cb
()
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment