@ -288,84 +288,62 @@ class Recorder {
return address
}
runScenario ( continueCb , promptCb , alertCb , confirmDialog , modalDialog , logCallBack , cb ) {
var currentFile = this . config . get ( 'currentFile' )
this . fileManager . fileProviderOf ( currentFile ) . get ( currentFile , ( error , json ) => {
if ( error ) {
return cb ( 'Invalid Scenario File ' + error )
fromWei ( value , doTypeConversion , unit ) {
if ( doTypeConversion ) {
return Web3 . utils . fromWei ( typeConversion . toInt ( value ) , unit || 'ether' )
}
if ( ! currentFile . match ( '.json$' ) ) {
return cb ( 'A scenario file is required. Please make sure a scenario file is currently displayed in the editor. The file must be of type JSON. Use the "Save Transactions" Button to generate a new Scenario File.' )
}
try {
var obj = JSON . parse ( json )
var txArray = obj . transactions || [ ]
var accounts = obj . accounts || [ ]
var options = obj . options || { }
var abis = obj . abis || { }
var linkReferences = obj . linkReferences || { }
} catch ( e ) {
return cb ( 'Invalid Scenario File, please try again' )
return Web3 . utils . fromWei ( value . toString ( 10 ) , unit || 'ether' )
}
if ( ! txArray . length ) {
return
toWei ( value , unit ) {
return Web3 . utils . toWei ( value , unit || 'gwei' )
}
var confirmationCb = ( network , tx , gasEstimation , continueTxExecution , cancelCb ) => {
if ( network . name !== 'Main' ) {
return continueTxExecution ( null )
calculateFee ( gas , gasPrice , unit ) {
return Web3 . utils . toBN ( gas ) . mul ( Web3 . utils . toBN ( Web3 . utils . toWei ( gasPrice . toString ( 10 ) , unit || 'gwei' ) ) )
}
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 ) => {
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 = Web3 . utils . toBN ( tx . gas ) . mul ( Web3 . utils . toBN ( Web3 . utils . toWei ( gasPrice . toString ( 10 ) , 'gwei' ) ) )
txFeeText = ' ' + Web3 . util s. fromWei ( fee . toString ( 10 ) , 'ether' ) + ' Ether'
var fee = this . calculateFee ( tx . gas , gasPrice )
txFeeText = ' ' + thi s. 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 )
} ,
( 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 )
return determineGasFeesCb
}
} )
runScenario ( continueCb , promptCb , alertCb , confirmationCb , logCallBack , cb ) {
var currentFile = this . config . get ( 'currentFile' )
this . fileManager . fileProviderOf ( currentFile ) . get ( currentFile , ( error , json ) => {
if ( error ) {
return cb ( 'Invalid Scenario File ' + error )
}
)
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 )
if ( ! currentFile . match ( '.json$' ) ) {
return cb ( 'A scenario file is required. Please make sure a scenario file is currently displayed in the editor. The file must be of type JSON. Use the "Save Transactions" Button to generate a new Scenario File.' )
}
} } , {
label : 'Cancel' ,
fn : ( ) => {
return cancelCb ( 'Transaction canceled by user.' )
try {
var obj = JSON . parse ( json )
var txArray = obj . transactions || [ ]
var accounts = obj . accounts || [ ]
var options = obj . options || { }
var abis = obj . abis || { }
var linkReferences = obj . linkReferences || { }
} catch ( e ) {
return cb ( 'Invalid Scenario File, please try again' )
}
} )
if ( ! txArray . length ) {
return
}
this . run ( txArray , accounts , options , abis , linkReferences , confirmationCb , continueCb , promptCb , alertCb , logCallBack , ( abi , address , contractName ) => {