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
f708c123
Commit
f708c123
authored
Feb 21, 2018
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract confirmation dialog call to caller
parent
1f246a95
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
70 deletions
+81
-70
txRunner.js
src/app/execution/txRunner.js
+11
-61
universal-dapp.js
src/universal-dapp.js
+70
-9
No files found.
src/app/execution/txRunner.js
View file @
f708c123
...
@@ -4,11 +4,7 @@ var EthJSBlock = require('ethereumjs-block')
...
@@ -4,11 +4,7 @@ var EthJSBlock = require('ethereumjs-block')
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
BN
=
ethJSUtil
.
BN
var
BN
=
ethJSUtil
.
BN
var
executionContext
=
require
(
'../../execution-context'
)
var
executionContext
=
require
(
'../../execution-context'
)
var
modalDialog
=
require
(
'../ui/modaldialog'
)
var
modal
=
require
(
'../ui/modal-dialog-custom'
)
var
modal
=
require
(
'../ui/modal-dialog-custom'
)
var
typeConversion
=
require
(
'./typeConversion'
)
var
confirmDialog
=
require
(
'./confirmDialog'
)
function
TxRunner
(
vmaccounts
,
api
)
{
function
TxRunner
(
vmaccounts
,
api
)
{
this
.
_api
=
api
this
.
_api
=
api
...
@@ -23,8 +19,8 @@ function TxRunner (vmaccounts, api) {
...
@@ -23,8 +19,8 @@ function TxRunner (vmaccounts, api) {
this
.
queusTxs
=
[]
this
.
queusTxs
=
[]
}
}
TxRunner
.
prototype
.
rawRun
=
function
(
args
,
cb
)
{
TxRunner
.
prototype
.
rawRun
=
function
(
args
,
c
onfirmationCb
,
c
b
)
{
run
(
this
,
args
,
Date
.
now
(),
cb
)
run
(
this
,
args
,
Date
.
now
(),
c
onfirmationCb
,
c
b
)
}
}
function
executeTx
(
tx
,
gasPrice
,
api
,
callback
)
{
function
executeTx
(
tx
,
gasPrice
,
api
,
callback
)
{
...
@@ -41,7 +37,7 @@ function executeTx (tx, gasPrice, api, callback) {
...
@@ -41,7 +37,7 @@ function executeTx (tx, gasPrice, api, callback) {
}
}
}
}
TxRunner
.
prototype
.
execute
=
function
(
args
,
callback
)
{
TxRunner
.
prototype
.
execute
=
function
(
args
,
c
onfirmationCb
,
c
allback
)
{
var
self
=
this
var
self
=
this
var
data
=
args
.
data
var
data
=
args
.
data
...
@@ -50,7 +46,7 @@ TxRunner.prototype.execute = function (args, callback) {
...
@@ -50,7 +46,7 @@ TxRunner.prototype.execute = function (args, callback) {
}
}
if
(
!
executionContext
.
isVM
())
{
if
(
!
executionContext
.
isVM
())
{
self
.
runInNode
(
args
.
from
,
args
.
to
,
data
,
args
.
value
,
args
.
gasLimit
,
args
.
useCall
,
callback
)
self
.
runInNode
(
args
.
from
,
args
.
to
,
data
,
args
.
value
,
args
.
gasLimit
,
args
.
useCall
,
c
onfirmationCb
,
c
allback
)
}
else
{
}
else
{
try
{
try
{
self
.
runInVm
(
args
.
from
,
args
.
to
,
data
,
args
.
value
,
args
.
gasLimit
,
args
.
useCall
,
callback
)
self
.
runInVm
(
args
.
from
,
args
.
to
,
data
,
args
.
value
,
args
.
gasLimit
,
args
.
useCall
,
callback
)
...
@@ -108,7 +104,7 @@ TxRunner.prototype.runInVm = function (from, to, data, value, gasLimit, useCall,
...
@@ -108,7 +104,7 @@ TxRunner.prototype.runInVm = function (from, to, data, value, gasLimit, useCall,
})
})
}
}
TxRunner
.
prototype
.
runInNode
=
function
(
from
,
to
,
data
,
value
,
gasLimit
,
useCall
,
callback
)
{
TxRunner
.
prototype
.
runInNode
=
function
(
from
,
to
,
data
,
value
,
gasLimit
,
useCall
,
c
onfirmCb
,
c
allback
)
{
const
self
=
this
const
self
=
this
var
tx
=
{
from
:
from
,
to
:
to
,
data
:
data
,
value
:
value
}
var
tx
=
{
from
:
from
,
to
:
to
,
data
:
data
,
value
:
value
}
...
@@ -142,62 +138,16 @@ TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCal
...
@@ -142,62 +138,16 @@ TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCal
if
(
self
.
_api
.
config
.
getUnpersistedProperty
(
'doNotShowTransactionConfirmationAgain'
))
{
if
(
self
.
_api
.
config
.
getUnpersistedProperty
(
'doNotShowTransactionConfirmationAgain'
))
{
return
executeTx
(
tx
,
null
,
self
.
_api
,
callback
)
return
executeTx
(
tx
,
null
,
self
.
_api
,
callback
)
}
}
self
.
_api
.
detectNetwork
((
err
,
network
)
=>
{
self
.
_api
.
detectNetwork
((
err
,
network
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
log
(
err
)
console
.
log
(
err
)
return
return
}
}
if
(
network
.
name
!==
'Main'
)
{
return
executeTx
(
tx
,
null
,
self
.
_api
,
callback
)
}
var
amount
=
executionContext
.
web3
().
fromWei
(
typeConversion
.
toInt
(
tx
.
value
),
'ether'
)
confirmCb
(
network
,
tx
,
gasEstimation
,
callback
,
(
gasPrice
)
=>
{
var
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
self
,
return
executeTx
(
tx
,
gasPrice
,
self
.
_api
,
callback
)
(
gasPrice
,
cb
)
=>
{
})
let
txFeeText
,
priceStatus
// TODO: this try catch feels like an anti pattern, can/should be
// removed, but for now keeping the original logic
try
{
var
fee
=
executionContext
.
web3
().
toBigNumber
(
tx
.
gas
).
mul
(
executionContext
.
web3
().
toBigNumber
(
executionContext
.
web3
().
toWei
(
gasPrice
.
toString
(
10
),
'gwei'
)))
txFeeText
=
' '
+
executionContext
.
web3
().
fromWei
(
fee
.
toString
(
10
),
'ether'
)
+
' Ether'
priceStatus
=
true
}
catch
(
e
)
{
txFeeText
=
' Please fix this issue before sending any transaction. '
+
e
.
message
priceStatus
=
false
}
cb
(
priceStatus
,
txFeeText
)
},
(
cb
)
=>
{
executionContext
.
web3
().
eth
.
getGasPrice
((
error
,
gasPrice
)
=>
{
var
warnMessage
=
' Please fix this issue before sending any transaction. '
if
(
error
)
{
return
cb
(
'Unable to retrieve the current network gas price.'
+
warnMessage
+
error
)
}
try
{
var
gasPriceValue
=
executionContext
.
web3
().
fromWei
(
gasPrice
.
toString
(
10
),
'gwei'
)
cb
(
null
,
gasPriceValue
)
}
catch
(
e
)
{
cb
(
warnMessage
+
e
.
message
,
null
,
false
)
}
})
}
)
modalDialog
(
'Confirm transaction'
,
content
,
{
label
:
'Confirm'
,
fn
:
()
=>
{
self
.
_api
.
config
.
setUnpersistedProperty
(
'doNotShowTransactionConfirmationAgain'
,
content
.
querySelector
(
'input#confirmsetting'
).
checked
)
if
(
!
content
.
gasPriceStatus
)
{
return
callback
(
'Given gas grice is not correct'
)
}
var
gasPrice
=
executionContext
.
web3
().
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
executeTx
(
tx
,
gasPrice
,
self
.
_api
,
callback
)
}},
{
label
:
'Cancel'
,
fn
:
()
=>
{
return
callback
(
'Transaction canceled by user.'
)
}
})
})
})
})
})
}
}
...
@@ -231,12 +181,12 @@ function sendTransaction (sendTx, tx, pass, callback) {
...
@@ -231,12 +181,12 @@ function sendTransaction (sendTx, tx, pass, callback) {
}
}
}
}
function
run
(
self
,
tx
,
stamp
,
callback
)
{
function
run
(
self
,
tx
,
stamp
,
c
onfirmationCb
,
c
allback
)
{
if
(
!
self
.
runAsync
&&
Object
.
keys
(
self
.
pendingTxs
).
length
)
{
if
(
!
self
.
runAsync
&&
Object
.
keys
(
self
.
pendingTxs
).
length
)
{
self
.
queusTxs
.
push
({
tx
,
stamp
,
callback
})
self
.
queusTxs
.
push
({
tx
,
stamp
,
callback
})
}
else
{
}
else
{
self
.
pendingTxs
[
stamp
]
=
tx
self
.
pendingTxs
[
stamp
]
=
tx
self
.
execute
(
tx
,
(
error
,
result
)
=>
{
self
.
execute
(
tx
,
confirmationCb
,
(
error
,
result
)
=>
{
delete
self
.
pendingTxs
[
stamp
]
delete
self
.
pendingTxs
[
stamp
]
callback
(
error
,
result
)
callback
(
error
,
result
)
if
(
self
.
queusTxs
.
length
)
{
if
(
self
.
queusTxs
.
length
)
{
...
...
src/universal-dapp.js
View file @
f708c123
...
@@ -14,6 +14,10 @@ var txHelper = remixLib.execution.txHelper
...
@@ -14,6 +14,10 @@ var txHelper = remixLib.execution.txHelper
var
executionContext
=
require
(
'./execution-context'
)
var
executionContext
=
require
(
'./execution-context'
)
var
modalCustom
=
require
(
'./app/ui/modal-dialog-custom'
)
var
modalCustom
=
require
(
'./app/ui/modal-dialog-custom'
)
var
modalDialog
=
require
(
'./app/ui/modaldialog'
)
var
typeConversion
=
require
(
'./app/execution/typeConversion'
)
var
confirmDialog
=
require
(
'./app/execution/confirmDialog'
)
/*
/*
trigger debugRequested
trigger debugRequested
*/
*/
...
@@ -248,18 +252,75 @@ UniversalDApp.prototype.runTx = function (args, cb) {
...
@@ -248,18 +252,75 @@ UniversalDApp.prototype.runTx = function (args, cb) {
var
timestamp
=
Date
.
now
()
var
timestamp
=
Date
.
now
()
self
.
event
.
trigger
(
'initiatingTransaction'
,
[
timestamp
,
tx
,
payLoad
])
self
.
event
.
trigger
(
'initiatingTransaction'
,
[
timestamp
,
tx
,
payLoad
])
self
.
txRunner
.
rawRun
(
tx
,
function
(
error
,
result
)
{
self
.
txRunner
.
rawRun
(
tx
,
let
eventName
=
(
tx
.
useCall
?
'callExecuted'
:
'transactionExecuted'
)
self
.
event
.
trigger
(
eventName
,
[
error
,
tx
.
from
,
tx
.
to
,
tx
.
data
,
tx
.
useCall
,
result
,
timestamp
,
payLoad
])
if
(
error
&&
(
typeof
(
error
)
!==
'string'
))
{
(
network
,
tx
,
continueTxExecution
,
gasEstimation
,
cancelCb
)
=>
{
if
(
error
.
message
)
error
=
error
.
message
if
(
network
.
name
!==
'Main'
)
{
else
{
return
continueTxExecution
(
null
)
try
{
error
=
'error: '
+
JSON
.
stringify
(
error
)
}
catch
(
e
)
{}
}
}
var
amount
=
executionContext
.
web3
().
fromWei
(
typeConversion
.
toInt
(
tx
.
value
),
'ether'
)
var
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
self
,
(
gasPrice
,
cb
)
=>
{
let
txFeeText
,
priceStatus
// TODO: this try catch feels like an anti pattern, can/should be
// removed, but for now keeping the original logic
try
{
var
fee
=
executionContext
.
web3
().
toBigNumber
(
tx
.
gas
).
mul
(
executionContext
.
web3
().
toBigNumber
(
executionContext
.
web3
().
toWei
(
gasPrice
.
toString
(
10
),
'gwei'
)))
txFeeText
=
' '
+
executionContext
.
web3
().
fromWei
(
fee
.
toString
(
10
),
'ether'
)
+
' Ether'
priceStatus
=
true
}
catch
(
e
)
{
txFeeText
=
' Please fix this issue before sending any transaction. '
+
e
.
message
priceStatus
=
false
}
cb
(
txFeeText
,
priceStatus
)
},
(
cb
)
=>
{
executionContext
.
web3
().
eth
.
getGasPrice
((
error
,
gasPrice
)
=>
{
var
warnMessage
=
' Please fix this issue before sending any transaction. '
if
(
error
)
{
return
cb
(
'Unable to retrieve the current network gas price.'
+
warnMessage
+
error
)
}
try
{
var
gasPriceValue
=
executionContext
.
web3
().
fromWei
(
gasPrice
.
toString
(
10
),
'gwei'
)
cb
(
null
,
gasPriceValue
)
}
catch
(
e
)
{
cb
(
warnMessage
+
e
.
message
,
null
,
false
)
}
})
}
)
modalDialog
(
'Confirm transaction'
,
content
,
{
label
:
'Confirm'
,
fn
:
()
=>
{
self
.
_api
.
config
.
setUnpersistedProperty
(
'doNotShowTransactionConfirmationAgain'
,
content
.
querySelector
(
'input#confirmsetting'
).
checked
)
// TODO: check if this is check is still valid given the refactor
if
(
!
content
.
gasPriceStatus
)
{
cancelCb
(
'Given gas price is not correct'
)
}
else
{
var
gasPrice
=
executionContext
.
web3
().
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
continueTxExecution
(
gasPrice
)
}
}},
{
label
:
'Cancel'
,
fn
:
()
=>
{
return
cancelCb
(
'Transaction canceled by user.'
)
}
})
},
function
(
error
,
result
)
{
let
eventName
=
(
tx
.
useCall
?
'callExecuted'
:
'transactionExecuted'
)
self
.
event
.
trigger
(
eventName
,
[
error
,
tx
.
from
,
tx
.
to
,
tx
.
data
,
tx
.
useCall
,
result
,
timestamp
,
payLoad
])
if
(
error
&&
(
typeof
(
error
)
!==
'string'
))
{
if
(
error
.
message
)
error
=
error
.
message
else
{
try
{
error
=
'error: '
+
JSON
.
stringify
(
error
)
}
catch
(
e
)
{}
}
}
next
(
error
,
result
)
}
}
next
(
error
,
result
)
)
})
}
}
],
cb
)
],
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