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
035ea3fd
Commit
035ea3fd
authored
Dec 26, 2019
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor recorder logic to extract modal and confirm dialogs out, use blockchain class
parent
a756977b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
62 deletions
+74
-62
recorder.js
src/app/tabs/runTab/model/recorder.js
+35
-57
recorder.js
src/app/tabs/runTab/recorder.js
+36
-2
run-tab.js
src/app/udapp/run-tab.js
+3
-3
No files found.
src/app/tabs/runTab/model/recorder.js
View file @
035ea3fd
...
@@ -288,7 +288,41 @@ class Recorder {
...
@@ -288,7 +288,41 @@ class Recorder {
return
address
return
address
}
}
runScenario
(
continueCb
,
promptCb
,
alertCb
,
confirmDialog
,
modalDialog
,
logCallBack
,
cb
)
{
fromWei
(
value
,
doTypeConversion
,
unit
)
{
if
(
doTypeConversion
)
{
return
Web3
.
utils
.
fromWei
(
typeConversion
.
toInt
(
value
),
unit
||
'ether'
)
}
return
Web3
.
utils
.
fromWei
(
value
.
toString
(
10
),
unit
||
'ether'
)
}
toWei
(
value
,
unit
)
{
return
Web3
.
utils
.
toWei
(
value
,
unit
||
'gwei'
)
}
calculateFee
(
gas
,
gasPrice
,
unit
)
{
return
Web3
.
utils
.
toBN
(
gas
).
mul
(
Web3
.
utils
.
toBN
(
Web3
.
utils
.
toWei
(
gasPrice
.
toString
(
10
),
unit
||
'gwei'
)))
}
determineGasFees
(
tx
)
{
const
determineGasFeesCb
=
(
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
=
this
.
calculateFee
(
tx
.
gas
,
gasPrice
)
txFeeText
=
' '
+
this
.
fromWei
(
fee
,
false
,
'ether'
)
+
' Ether'
priceStatus
=
true
}
catch
(
e
)
{
txFeeText
=
' Please fix this issue before sending any transaction. '
+
e
.
message
priceStatus
=
false
}
cb
(
txFeeText
,
priceStatus
)
}
return
determineGasFeesCb
}
runScenario
(
continueCb
,
promptCb
,
alertCb
,
confirmationCb
,
logCallBack
,
cb
)
{
var
currentFile
=
this
.
config
.
get
(
'currentFile'
)
var
currentFile
=
this
.
config
.
get
(
'currentFile'
)
this
.
fileManager
.
fileProviderOf
(
currentFile
).
get
(
currentFile
,
(
error
,
json
)
=>
{
this
.
fileManager
.
fileProviderOf
(
currentFile
).
get
(
currentFile
,
(
error
,
json
)
=>
{
if
(
error
)
{
if
(
error
)
{
...
@@ -312,62 +346,6 @@ class Recorder {
...
@@ -312,62 +346,6 @@ class Recorder {
return
return
}
}
var
confirmationCb
=
(
network
,
tx
,
gasEstimation
,
continueTxExecution
,
cancelCb
)
=>
{
if
(
network
.
name
!==
'Main'
)
{
return
continueTxExecution
(
null
)
}
var
amount
=
Web3
.
utils
.
fromWei
(
typeConversion
.
toInt
(
tx
.
value
),
'ether'
)
// TODO: there is still a UI dependency to remove here, it's still too coupled at this point to remove easily
var
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
this
.
recorder
,
(
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
=
Web3
.
utils
.
toBN
(
tx
.
gas
).
mul
(
Web3
.
utils
.
toBN
(
Web3
.
utils
.
toWei
(
gasPrice
.
toString
(
10
),
'gwei'
)))
txFeeText
=
' '
+
Web3
.
utils
.
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
)
=>
{
this
.
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
=
Web3
.
utils
.
fromWei
(
gasPrice
.
toString
(
10
),
'gwei'
)
cb
(
null
,
gasPriceValue
)
}
catch
(
e
)
{
cb
(
warnMessage
+
e
.
message
,
null
,
false
)
}
})
}
)
modalDialog
(
'Confirm transaction'
,
content
,
{
label
:
'Confirm'
,
fn
:
()
=>
{
this
.
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
=
Web3
.
utils
.
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
continueTxExecution
(
gasPrice
)
}
}},
{
label
:
'Cancel'
,
fn
:
()
=>
{
return
cancelCb
(
'Transaction canceled by user.'
)
}
})
}
this
.
run
(
txArray
,
accounts
,
options
,
abis
,
linkReferences
,
confirmationCb
,
continueCb
,
promptCb
,
alertCb
,
logCallBack
,
(
abi
,
address
,
contractName
)
=>
{
this
.
run
(
txArray
,
accounts
,
options
,
abis
,
linkReferences
,
confirmationCb
,
continueCb
,
promptCb
,
alertCb
,
logCallBack
,
(
abi
,
address
,
contractName
)
=>
{
cb
(
null
,
abi
,
address
,
contractName
)
cb
(
null
,
abi
,
address
,
contractName
)
})
})
...
...
src/app/tabs/runTab/recorder.js
View file @
035ea3fd
...
@@ -10,7 +10,8 @@ var confirmDialog = require('../../ui/confirmDialog')
...
@@ -10,7 +10,8 @@ var confirmDialog = require('../../ui/confirmDialog')
class
RecorderUI
{
class
RecorderUI
{
constructor
(
recorder
,
logCallBack
)
{
constructor
(
blockchain
,
recorder
,
logCallBack
)
{
this
.
blockchain
=
blockchain
this
.
recorder
=
recorder
this
.
recorder
=
recorder
this
.
logCallBack
=
logCallBack
this
.
logCallBack
=
logCallBack
this
.
event
=
new
EventManager
()
this
.
event
=
new
EventManager
()
...
@@ -63,8 +64,10 @@ class RecorderUI {
...
@@ -63,8 +64,10 @@ class RecorderUI {
modalDialogCustom
.
alert
(
msg
)
modalDialogCustom
.
alert
(
msg
)
}
}
const
confirmationCb
=
this
.
getConfirmationCb
(
modalDialog
,
confirmDialog
)
// TODO: there is still a UI dependency to remove here, it's still too coupled at this point to remove easily
// TODO: there is still a UI dependency to remove here, it's still too coupled at this point to remove easily
this
.
recorder
.
runScenario
(
continueCb
,
promptCb
,
alertCb
,
confirm
Dialog
,
modalDialog
,
this
.
logCallBack
,
(
error
,
abi
,
address
,
contractName
)
=>
{
this
.
recorder
.
runScenario
(
continueCb
,
promptCb
,
alertCb
,
confirm
ationCb
,
this
.
logCallBack
,
(
error
,
abi
,
address
,
contractName
)
=>
{
if
(
error
)
{
if
(
error
)
{
return
modalDialogCustom
.
alert
(
error
)
return
modalDialogCustom
.
alert
(
error
)
}
}
...
@@ -73,6 +76,37 @@ class RecorderUI {
...
@@ -73,6 +76,37 @@ class RecorderUI {
})
})
}
}
getConfirmationCb
(
modalDialog
,
confirmDialog
)
{
const
confirmationCb
=
(
network
,
tx
,
gasEstimation
,
continueTxExecution
,
cancelCb
)
=>
{
if
(
network
.
name
!==
'Main'
)
{
return
continueTxExecution
(
null
)
}
const
amount
=
this
.
recorder
.
fromWei
(
tx
.
value
,
true
,
'ether'
)
const
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
null
,
this
.
recorder
.
determineGasFees
(
tx
),
this
.
blockchain
.
determineGasPrice
)
modalDialog
(
'Confirm transaction'
,
content
,
{
label
:
'Confirm'
,
fn
:
()
=>
{
this
.
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
=
this
.
recorder
.
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
continueTxExecution
(
gasPrice
)
}
}},
{
label
:
'Cancel'
,
fn
:
()
=>
{
return
cancelCb
(
'Transaction canceled by user.'
)
}
}
)
}
return
confirmationCb
}
triggerRecordButton
()
{
triggerRecordButton
()
{
this
.
recorder
.
saveScenario
(
this
.
recorder
.
saveScenario
(
(
path
,
cb
)
=>
{
(
path
,
cb
)
=>
{
...
...
src/app/udapp/run-tab.js
View file @
035ea3fd
...
@@ -41,6 +41,7 @@ export class RunTab extends LibraryPlugin {
...
@@ -41,6 +41,7 @@ export class RunTab extends LibraryPlugin {
this
.
config
=
config
this
.
config
=
config
this
.
udapp
=
udapp
this
.
udapp
=
udapp
this
.
executionContext
=
executionContext
this
.
executionContext
=
executionContext
this
.
blockchain
=
new
Blockchain
(
this
.
executionContext
,
udapp
)
this
.
fileManager
=
fileManager
this
.
fileManager
=
fileManager
this
.
editor
=
editor
this
.
editor
=
editor
this
.
logCallback
=
(
msg
)
=>
{
mainView
.
getTerminal
().
logHtml
(
msg
)
}
this
.
logCallback
=
(
msg
)
=>
{
mainView
.
getTerminal
().
logHtml
(
msg
)
}
...
@@ -133,8 +134,7 @@ export class RunTab extends LibraryPlugin {
...
@@ -133,8 +134,7 @@ export class RunTab extends LibraryPlugin {
renderDropdown
(
udappUI
,
fileManager
,
compilersArtefacts
,
config
,
editor
,
udapp
,
filePanel
,
logCallback
)
{
renderDropdown
(
udappUI
,
fileManager
,
compilersArtefacts
,
config
,
editor
,
udapp
,
filePanel
,
logCallback
)
{
const
dropdownLogic
=
new
DropdownLogic
(
compilersArtefacts
,
config
,
editor
,
this
)
const
dropdownLogic
=
new
DropdownLogic
(
compilersArtefacts
,
config
,
editor
,
this
)
const
blockchain
=
new
Blockchain
(
this
.
executionContext
,
udapp
)
this
.
contractDropdownUI
=
new
ContractDropdownUI
(
this
.
blockchain
,
dropdownLogic
,
logCallback
,
this
)
this
.
contractDropdownUI
=
new
ContractDropdownUI
(
blockchain
,
dropdownLogic
,
logCallback
,
this
)
fileManager
.
events
.
on
(
'currentFileChanged'
,
this
.
contractDropdownUI
.
changeCurrentFile
.
bind
(
this
.
contractDropdownUI
))
fileManager
.
events
.
on
(
'currentFileChanged'
,
this
.
contractDropdownUI
.
changeCurrentFile
.
bind
(
this
.
contractDropdownUI
))
...
@@ -159,7 +159,7 @@ export class RunTab extends LibraryPlugin {
...
@@ -159,7 +159,7 @@ export class RunTab extends LibraryPlugin {
})
})
this
.
event
.
register
(
'clearInstance'
,
recorder
.
clearAll
.
bind
(
recorder
))
this
.
event
.
register
(
'clearInstance'
,
recorder
.
clearAll
.
bind
(
recorder
))
this
.
recorderInterface
=
new
RecorderUI
(
recorder
,
logCallback
)
this
.
recorderInterface
=
new
RecorderUI
(
this
.
blockchain
,
recorder
,
logCallback
)
this
.
recorderInterface
.
event
.
register
(
'newScenario'
,
(
abi
,
address
,
contractName
)
=>
{
this
.
recorderInterface
.
event
.
register
(
'newScenario'
,
(
abi
,
address
,
contractName
)
=>
{
var
noInstancesText
=
this
.
noInstancesText
var
noInstancesText
=
this
.
noInstancesText
...
...
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