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
29457b71
Commit
29457b71
authored
Dec 23, 2019
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor contract dropdown logic
parent
3e47a365
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
76 deletions
+30
-76
contractDropdown.js
src/app/tabs/runTab/contractDropdown.js
+5
-6
dropdownlogic.js
src/app/tabs/runTab/model/dropdownlogic.js
+25
-70
No files found.
src/app/tabs/runTab/contractDropdown.js
View file @
29457b71
...
...
@@ -109,7 +109,8 @@ class ContractDropdownUI {
const
selectedContract
=
this
.
getSelectedContract
()
const
clickCallback
=
(
valArray
,
inputsValues
)
=>
{
this
.
createInstance
(
inputsValues
)
var
selectedContract
=
this
.
getSelectedContract
()
this
.
createInstance
(
selectedContract
,
inputsValues
)
}
const
createConstructorInstance
=
new
MultiParamManager
(
0
,
...
...
@@ -130,9 +131,7 @@ class ContractDropdownUI {
return
this
.
dropdownLogic
.
getSelectedContract
(
contractName
,
compilerAtributeName
)
}
createInstance
(
args
)
{
var
selectedContract
=
this
.
getSelectedContract
()
createInstance
(
selectedContract
,
args
)
{
if
(
selectedContract
.
bytecodeObject
.
length
===
0
)
{
return
modalDialogCustom
.
alert
(
'This contract may be abstract, not implement an abstract parent
\'
s methods completely or not invoke an inherited contract
\'
s constructor correctly.'
)
}
...
...
@@ -184,7 +183,7 @@ class ContractDropdownUI {
{
label
:
'Force Send'
,
fn
:
()
=>
{
this
.
dropdownLogic
.
forceSend
(
selectedContract
,
args
,
continueCb
,
promptCb
,
modalDialog
,
confirmDialog
,
statusCb
,
finalCb
)
this
.
dropdownLogic
.
deployContract
(
selectedContract
,
args
,
{
continueCb
,
promptCb
,
statusCb
,
finalCb
},
{
modalDialog
,
confirmDialog
}
)
}},
{
label
:
'Cancel'
,
fn
:
()
=>
{
...
...
@@ -192,7 +191,7 @@ class ContractDropdownUI {
}
})
}
this
.
dropdownLogic
.
forceSend
(
selectedContract
,
args
,
continueCb
,
promptCb
,
modalDialog
,
confirmDialog
,
statusCb
,
finalCb
)
this
.
dropdownLogic
.
deployContract
(
selectedContract
,
args
,
{
continueCb
,
promptCb
,
statusCb
,
finalCb
},
{
modalDialog
,
confirmDialog
}
)
}
loadFromAddress
()
{
...
...
src/app/tabs/runTab/model/dropdownlogic.js
View file @
29457b71
...
...
@@ -136,62 +136,7 @@ class DropdownLogic {
data
.
contractABI
=
selectedContract
.
abi
}
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.'
)
}
})
}
const
confirmationCb
=
this
.
getConfirmationCb
(
modalDialog
,
confirmDialog
)
this
.
udapp
.
createContract
(
data
,
confirmationCb
,
continueCb
,
promptCb
,
(
error
,
txResult
)
=>
{
if
(
error
)
{
...
...
@@ -213,14 +158,7 @@ class DropdownLogic {
)
}
runTransaction
(
data
,
continueCb
,
promptCb
,
modalDialog
,
confirmDialog
,
finalCb
)
{
var
confirmationCb
=
(
network
,
tx
,
gasEstimation
,
continueTxExecution
,
cancelCb
)
=>
{
if
(
network
.
name
!==
'Main'
)
{
return
continueTxExecution
(
null
)
}
var
amount
=
this
.
fromWei
(
tx
.
value
,
true
,
'ether'
)
var
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
null
,
(
gasPrice
,
cb
)
=>
{
determineGasFees
(
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
...
...
@@ -233,8 +171,9 @@ class DropdownLogic {
priceStatus
=
false
}
cb
(
txFeeText
,
priceStatus
)
},
(
cb
)
=>
{
}
determineGasPrice
(
cb
)
{
this
.
getGasPrice
((
error
,
gasPrice
)
=>
{
var
warnMessage
=
' Please fix this issue before sending any transaction. '
if
(
error
)
{
...
...
@@ -248,7 +187,15 @@ class DropdownLogic {
}
})
}
)
getConfirmationCb
(
modalDialog
,
confirmDialog
)
{
const
confirmationCb
=
(
network
,
tx
,
gasEstimation
,
continueTxExecution
,
cancelCb
)
=>
{
if
(
network
.
name
!==
'Main'
)
{
return
continueTxExecution
(
null
)
}
const
amount
=
this
.
fromWei
(
tx
.
value
,
true
,
'ether'
)
const
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
null
,
this
.
determineGasFees
,
this
.
determineGasPrice
)
modalDialog
(
'Confirm transaction'
,
content
,
{
label
:
'Confirm'
,
fn
:
()
=>
{
...
...
@@ -269,10 +216,18 @@ class DropdownLogic {
)
}
return
confirmationCb
}
runTransaction
(
data
,
continueCb
,
promptCb
,
modalDialog
,
confirmDialog
,
finalCb
)
{
const
confirmationCb
=
this
.
getConfirmationCb
(
modalDialog
,
confirmDialog
)
this
.
udapp
.
runTx
(
data
,
confirmationCb
,
continueCb
,
promptCb
,
finalCb
)
}
async
forceSend
(
selectedContract
,
args
,
continueCb
,
promptCb
,
modalDialog
,
confirmDialog
,
statusCb
,
cb
)
{
async
deploContract
(
selectedContract
,
args
,
callbacks
,
dialogs
)
{
const
{
continueCb
,
promptCb
,
statusCb
,
finalCb
}
=
callbacks
const
{
modalDialog
,
confirmDialog
}
=
dialogs
var
constructor
=
selectedContract
.
getConstructorInterface
()
// TODO: deployMetadataOf can be moved here
let
contractMetadata
...
...
@@ -286,7 +241,7 @@ class DropdownLogic {
if
(
error
)
return
statusCb
(
`creation of
${
selectedContract
.
name
}
errored: `
+
error
)
statusCb
(
`creation of
${
selectedContract
.
name
}
pending...`
)
this
.
createContract
(
selectedContract
,
data
,
continueCb
,
promptCb
,
modalDialog
,
confirmDialog
,
c
b
)
this
.
createContract
(
selectedContract
,
data
,
continueCb
,
promptCb
,
modalDialog
,
confirmDialog
,
finalC
b
)
},
statusCb
,
(
data
,
runTxCallback
)
=>
{
// called for libraries deployment
this
.
runTransaction
(
data
,
continueCb
,
promptCb
,
modalDialog
,
confirmDialog
,
runTxCallback
)
...
...
@@ -297,7 +252,7 @@ class DropdownLogic {
if
(
error
)
return
statusCb
(
`creation of
${
selectedContract
.
name
}
errored: `
+
error
)
statusCb
(
`creation of
${
selectedContract
.
name
}
pending...`
)
this
.
createContract
(
selectedContract
,
data
,
continueCb
,
promptCb
,
modalDialog
,
confirmDialog
,
c
b
)
this
.
createContract
(
selectedContract
,
data
,
continueCb
,
promptCb
,
modalDialog
,
confirmDialog
,
finalC
b
)
})
}
...
...
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