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
a3946e67
Commit
a3946e67
authored
Dec 26, 2019
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move common fromWei/toWei/determineGasFee methods into blockchain module
parent
035ea3fd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
78 deletions
+33
-78
contractDropdown.js
src/app/tabs/runTab/contractDropdown.js
+3
-3
blockchain.js
src/app/tabs/runTab/model/blockchain.js
+27
-0
dropdownlogic.js
src/app/tabs/runTab/model/dropdownlogic.js
+0
-36
recorder.js
src/app/tabs/runTab/model/recorder.js
+0
-36
recorder.js
src/app/tabs/runTab/recorder.js
+3
-3
No files found.
src/app/tabs/runTab/contractDropdown.js
View file @
a3946e67
...
@@ -209,8 +209,8 @@ class ContractDropdownUI {
...
@@ -209,8 +209,8 @@ class ContractDropdownUI {
if
(
network
.
name
!==
'Main'
)
{
if
(
network
.
name
!==
'Main'
)
{
return
continueTxExecution
(
null
)
return
continueTxExecution
(
null
)
}
}
const
amount
=
this
.
dropdownLogic
.
fromWei
(
tx
.
value
,
true
,
'ether'
)
const
amount
=
this
.
blockchain
.
fromWei
(
tx
.
value
,
true
,
'ether'
)
const
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
null
,
this
.
dropdownLogic
.
determineGasFees
(
tx
),
this
.
blockchain
.
determineGasPrice
)
const
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
null
,
this
.
blockchain
.
determineGasFees
(
tx
),
this
.
blockchain
.
determineGasPrice
)
modalDialog
(
'Confirm transaction'
,
content
,
modalDialog
(
'Confirm transaction'
,
content
,
{
label
:
'Confirm'
,
{
label
:
'Confirm'
,
...
@@ -220,7 +220,7 @@ class ContractDropdownUI {
...
@@ -220,7 +220,7 @@ class ContractDropdownUI {
if
(
!
content
.
gasPriceStatus
)
{
if
(
!
content
.
gasPriceStatus
)
{
cancelCb
(
'Given gas price is not correct'
)
cancelCb
(
'Given gas price is not correct'
)
}
else
{
}
else
{
var
gasPrice
=
this
.
dropdownLogic
.
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
var
gasPrice
=
this
.
blockchain
.
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
continueTxExecution
(
gasPrice
)
continueTxExecution
(
gasPrice
)
}
}
}},
{
}},
{
...
...
src/app/tabs/runTab/model/blockchain.js
View file @
a3946e67
...
@@ -93,6 +93,33 @@ class Blockchain {
...
@@ -93,6 +93,33 @@ class Blockchain {
return
Web3
.
utils
.
fromWei
(
value
.
toString
(
10
),
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
}
}
}
module
.
exports
=
Blockchain
module
.
exports
=
Blockchain
src/app/tabs/runTab/model/dropdownlogic.js
View file @
a3946e67
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
remixLib
=
require
(
'remix-lib'
)
var
remixLib
=
require
(
'remix-lib'
)
var
txHelper
=
remixLib
.
execution
.
txHelper
var
txHelper
=
remixLib
.
execution
.
txHelper
var
typeConversion
=
remixLib
.
execution
.
typeConversion
var
CompilerAbstract
=
require
(
'../../../compiler/compiler-abstract'
)
var
CompilerAbstract
=
require
(
'../../../compiler/compiler-abstract'
)
var
EventManager
=
remixLib
.
EventManager
var
EventManager
=
remixLib
.
EventManager
var
Web3
=
require
(
'web3'
)
class
DropdownLogic
{
class
DropdownLogic
{
constructor
(
compilersArtefacts
,
config
,
editor
,
runView
)
{
constructor
(
compilersArtefacts
,
config
,
editor
,
runView
)
{
...
@@ -96,40 +94,6 @@ class DropdownLogic {
...
@@ -96,40 +94,6 @@ class DropdownLogic {
}
}
}
}
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
}
getCompilerContracts
()
{
getCompilerContracts
()
{
return
this
.
compilersArtefacts
[
'__last'
].
getData
().
contracts
return
this
.
compilersArtefacts
[
'__last'
].
getData
().
contracts
}
}
...
...
src/app/tabs/runTab/model/recorder.js
View file @
a3946e67
...
@@ -4,9 +4,7 @@ var remixLib = require('remix-lib')
...
@@ -4,9 +4,7 @@ var remixLib = require('remix-lib')
var
EventManager
=
remixLib
.
EventManager
var
EventManager
=
remixLib
.
EventManager
var
format
=
remixLib
.
execution
.
txFormat
var
format
=
remixLib
.
execution
.
txFormat
var
txHelper
=
remixLib
.
execution
.
txHelper
var
txHelper
=
remixLib
.
execution
.
txHelper
var
typeConversion
=
remixLib
.
execution
.
typeConversion
var
helper
=
require
(
'../../../../lib/helper.js'
)
var
helper
=
require
(
'../../../../lib/helper.js'
)
var
Web3
=
require
(
'web3'
)
/**
/**
* Record transaction as long as the user create them.
* Record transaction as long as the user create them.
...
@@ -288,40 +286,6 @@ class Recorder {
...
@@ -288,40 +286,6 @@ class Recorder {
return
address
return
address
}
}
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
)
{
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
)
=>
{
...
...
src/app/tabs/runTab/recorder.js
View file @
a3946e67
...
@@ -81,8 +81,8 @@ class RecorderUI {
...
@@ -81,8 +81,8 @@ class RecorderUI {
if
(
network
.
name
!==
'Main'
)
{
if
(
network
.
name
!==
'Main'
)
{
return
continueTxExecution
(
null
)
return
continueTxExecution
(
null
)
}
}
const
amount
=
this
.
recorder
.
fromWei
(
tx
.
value
,
true
,
'ether'
)
const
amount
=
this
.
blockchain
.
fromWei
(
tx
.
value
,
true
,
'ether'
)
const
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
null
,
this
.
recorder
.
determineGasFees
(
tx
),
this
.
blockchain
.
determineGasPrice
)
const
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
null
,
this
.
blockchain
.
determineGasFees
(
tx
),
this
.
blockchain
.
determineGasPrice
)
modalDialog
(
'Confirm transaction'
,
content
,
modalDialog
(
'Confirm transaction'
,
content
,
{
label
:
'Confirm'
,
{
label
:
'Confirm'
,
...
@@ -92,7 +92,7 @@ class RecorderUI {
...
@@ -92,7 +92,7 @@ class RecorderUI {
if
(
!
content
.
gasPriceStatus
)
{
if
(
!
content
.
gasPriceStatus
)
{
cancelCb
(
'Given gas price is not correct'
)
cancelCb
(
'Given gas price is not correct'
)
}
else
{
}
else
{
var
gasPrice
=
this
.
recorder
.
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
var
gasPrice
=
this
.
blockchain
.
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
continueTxExecution
(
gasPrice
)
continueTxExecution
(
gasPrice
)
}
}
}},
{
}},
{
...
...
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