@ -2,7 +2,6 @@ var yo = require('yo-yo')
var css = require ( '../styles/run-tab-styles' )
var css = require ( '../styles/run-tab-styles' )
var modalDialogCustom = require ( '../../ui/modal-dialog-custom' )
var modalDialogCustom = require ( '../../ui/modal-dialog-custom' )
var remixLib = require ( 'remix-lib' )
var remixLib = require ( 'remix-lib' )
var txExecution = remixLib . execution . txExecution
var txFormat = remixLib . execution . txFormat
var txFormat = remixLib . execution . txFormat
var EventManager = remixLib . EventManager
var EventManager = remixLib . EventManager
var confirmDialog = require ( '../../execution/confirmDialog' )
var confirmDialog = require ( '../../execution/confirmDialog' )
@ -111,69 +110,13 @@ class ContractDropdownUI {
return this . dropdownLogic . getSelectedContract ( contractName , compilerAtributeName )
return this . dropdownLogic . getSelectedContract ( contractName , compilerAtributeName )
}
}
// ===============
// TODO: move this to DropdownLogic
// ===============
createInstanceCallback ( selectedContract , data ) {
createInstanceCallback ( selectedContract , data ) {
this . parentSelf . _deps . logCallback ( ` creation of ${ selectedContract . name } pending... ` )
this . parentSelf . _deps . logCallback ( ` creation of ${ selectedContract . name } pending... ` )
if ( data ) {
data . contractName = selectedContract . name
data . linkReferences = selectedContract . bytecodeLinkReferences
data . contractABI = selectedContract . abi
}
this . parentSelf . _deps . udapp . createContract ( data ,
( network , tx , gasEstimation , continueTxExecution , cancelCb ) => {
var continueCb = ( error , continueTxExecution , cancelCb ) => {
if ( network . name !== 'Main' ) {
return continueTxExecution ( null )
}
var amount = this . dropdownLogic . fromWei ( tx . value , true )
var content = confirmDialog ( tx , amount , gasEstimation , this . parentSelf ,
( 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 . dropdownLogic . calculateFee ( tx . gas , gasPrice , 'gwei' )
txFeeText = ' ' + this . dropdownLogic . fromWei ( fee ) + ' Ether'
priceStatus = true
} catch ( e ) {
txFeeText = ' Please fix this issue before sending any transaction. ' + e . message
priceStatus = false
}
cb ( txFeeText , priceStatus )
} ,
( cb ) => {
this . dropdownLogic . 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 = this . dropdownLogic . fromWei ( gasPrice , false , 'gwei' )
cb ( null , gasPriceValue )
} catch ( e ) {
cb ( warnMessage + e . message , null , false )
}
} )
}
)
modalDialog ( 'Confirm transaction' , content ,
{ label : 'Confirm' ,
fn : ( ) => {
this . parentSelf . _deps . 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 . dropdownLogic . toWei ( content . querySelector ( '#gasprice' ) . value , 'gwei' )
continueTxExecution ( gasPrice )
}
} } , {
label : 'Cancel' ,
fn : ( ) => {
return cancelCb ( 'Transaction canceled by user.' )
}
} )
} ,
( error , continueTxExecution , cancelCb ) => {
if ( error ) {
if ( error ) {
var msg = typeof error !== 'string' ? error . message : error
var msg = typeof error !== 'string' ? error . message : error
modalDialog ( 'Gas estimation failed' , yo ` <div>Gas estimation errored with the following message (see below).
modalDialog ( 'Gas estimation failed' , yo ` <div>Gas estimation errored with the following message (see below).
@ -193,32 +136,23 @@ class ContractDropdownUI {
} else {
} else {
continueTxExecution ( )
continueTxExecution ( )
}
}
} ,
function ( okCb , cancelCb ) {
modalDialogCustom . promptPassphrase ( null , 'Personal mode is enabled. Please provide passphrase of account' , '' , okCb , cancelCb )
} ,
( error , txResult ) => {
if ( error ) {
return this . parentSelf . _deps . logCallback ( ` creation of ${ selectedContract . name } errored: ${ error } ` )
}
var isVM = this . dropdownLogic . isVM ( )
if ( isVM ) {
var vmError = txExecution . checkVMError ( txResult )
if ( vmError . error ) {
return this . parentSelf . _deps . logCallback ( vmError . message )
}
}
}
if ( txResult . result . status && txResult . result . status === '0x0' ) {
return this . parentSelf . _deps . logCallback ( ` creation of ${ selectedContract . name } errored: transaction execution failed ` )
var promptCb = function ( okCb , cancelCb ) {
modalDialogCustom . promptPassphrase ( null , 'Personal mode is enabled. Please provide passphrase of account' , '' , okCb , cancelCb )
}
}
this . dropdownLogic . createContract ( selectedContract , data , continueCb , promptCb , modalDialog , confirmDialog , ( error , contractObject , address ) => {
this . event . trigger ( 'clearInstance' )
this . event . trigger ( 'clearInstance' )
var address = isVM ? txResult . result . createdAddress : txResult . result . contractAddress
this . event . trigger ( 'newContractInstanceAdded' , [ selectedContract , address , this . selectContractNames . value ] )
if ( error ) {
return this . parentSelf . _deps . logCallback ( error )
}
}
)
this . event . trigger ( 'newContractInstanceAdded' , [ contractObject , address , this . selectContractNames . value ] )
} )
}
}
// DEPLOY INSTANCE
createInstance ( args , compiler ) {
createInstance ( args , compiler ) {
var selectedContract = this . getSelectedContract ( )
var selectedContract = this . getSelectedContract ( )
@ -226,6 +160,9 @@ class ContractDropdownUI {
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.' )
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.' )
}
}
// ===============
// TODO: move this to DropdownLogic
// ===============
var forceSend = ( ) => {
var forceSend = ( ) => {
var constructor = selectedContract . getConstructorInterface ( )
var constructor = selectedContract . getConstructorInterface ( )
this . parentSelf . _deps . filePanel . compilerMetadata ( ) . deployMetadataOf ( selectedContract . name , ( error , contractMetadata ) => {
this . parentSelf . _deps . filePanel . compilerMetadata ( ) . deployMetadataOf ( selectedContract . name , ( error , contractMetadata ) => {
@ -237,65 +174,11 @@ class ContractDropdownUI {
} , ( msg ) => {
} , ( msg ) => {
this . parentSelf . _deps . logCallback ( msg )
this . parentSelf . _deps . logCallback ( msg )
} , ( data , runTxCallback ) => {
} , ( data , runTxCallback ) => {
// called for libraries deployment
var promptCb = ( okCb , cancelCb ) => {
this . parentSelf . _deps . udapp . runTx ( data ,
( network , tx , gasEstimation , continueTxExecution , cancelCb ) => {
if ( network . name !== 'Main' ) {
return continueTxExecution ( null )
}
var amount = this . dropdownLogic . fromWei ( tx . value , true , 'ether' )
var content = confirmDialog ( tx , amount , gasEstimation , this . parentSelf ,
( 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 . dropdownLogic . calculateFee ( tx . gas , gasPrice )
txFeeText = ' ' + this . dropdownLogic . 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 . dropdownLogic . 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 = this . dropdownLogic . fromWei ( gasPrice , false , 'gwei' )
cb ( null , gasPriceValue )
} catch ( e ) {
cb ( warnMessage + e . message , null , false )
}
} )
}
)
modalDialog ( 'Confirm transaction' , content ,
{ label : 'Confirm' ,
fn : ( ) => {
this . parentSelf . _deps . 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 . dropdownLogic . toWei ( content . querySelector ( '#gasprice' ) . value , 'gwei' )
continueTxExecution ( gasPrice )
}
} } , {
label : 'Cancel' ,
fn : ( ) => {
return cancelCb ( 'Transaction canceled by user.' )
}
} )
} ,
function ( okCb , cancelCb ) {
modalDialogCustom . promptPassphrase ( null , 'Personal mode is enabled. Please provide passphrase of account' , '' , okCb , cancelCb )
modalDialogCustom . promptPassphrase ( null , 'Personal mode is enabled. Please provide passphrase of account' , '' , okCb , cancelCb )
} ,
}
runTxCallback )
// called for libraries deployment
this . dropdownLogic . runTransaction ( data , promptCb , modalDialog , confirmDialog , runTxCallback )
} )
} )
} else {
} else {
if ( Object . keys ( selectedContract . bytecodeLinkReferences ) . length ) this . parentSelf . _deps . logCallback ( ` linking ${ JSON . stringify ( selectedContract . bytecodeLinkReferences , null , '\t' ) } using ${ JSON . stringify ( contractMetadata . linkReferences , null , '\t' ) } ` )
if ( Object . keys ( selectedContract . bytecodeLinkReferences ) . length ) this . parentSelf . _deps . logCallback ( ` linking ${ JSON . stringify ( selectedContract . bytecodeLinkReferences , null , '\t' ) } using ${ JSON . stringify ( contractMetadata . linkReferences , null , '\t' ) } ` )