2016-08-16 18:38:18 -03:00
'use strict' ;
2017-02-17 13:45:17 -03:00
angular . module ( 'copayApp.controllers' ) . controller ( 'confirmController' , function ( $rootScope , $scope , $interval , $filter , $timeout , $ionicScrollDelegate , gettextCatalog , walletService , platformInfo , lodash , configService , rateService , $stateParams , $window , $state , $log , profileService , bitcore , txFormatService , ongoingProcess , $ionicModal , popupService , $ionicHistory , $ionicConfig , payproService , feeService , bwcError ) {
2017-06-20 12:14:21 -03:00
2016-10-20 15:38:57 -03:00
var countDown = null ;
2017-06-20 12:14:21 -03:00
var tx = { } ;
// Config Related values
var config = configService . getSync ( ) ;
var walletConfig = config . wallet ;
var unitToSatoshi = walletConfig . settings . unitToSatoshi ;
var unitDecimals = walletConfig . settings . unitDecimals ;
var satToUnit = 1 / unitToSatoshi ;
var touchIdEnabled = config . touchIdFor && config . touchIdFor [ wallet . id ] ;
var configFeeLevel = walletConfig . settings . feeLevel ? walletConfig . settings . feeLevel : 'normal' ;
// Platform info
var isChromeApp = platformInfo . isChromeApp ;
var isCordova = platformInfo . isCordova ;
$scope . showWalletSelector = function ( ) {
$scope . walletSelector = true ;
} ;
2017-02-23 14:26:05 -05:00
$scope . $on ( "$ionicView.beforeLeave" , function ( event , data ) {
$ionicConfig . views . swipeBackEnabled ( true ) ;
} ) ;
2016-10-10 10:56:12 -04:00
2017-03-03 10:36:19 -03:00
$scope . $on ( "$ionicView.enter" , function ( event , data ) {
2017-02-23 14:26:05 -05:00
$ionicConfig . views . swipeBackEnabled ( false ) ;
2017-03-03 10:36:19 -03:00
} ) ;
$scope . $on ( "$ionicView.beforeEnter" , function ( event , data ) {
2017-02-23 14:26:05 -05:00
2017-06-20 12:14:21 -03:00
function setWalletSelector ( minAmount , cb ) {
console . log ( '[confirm.js.38:minAmount:]' , minAmount ) ; //TODO
$scope . wallets = profileService . getWallets ( {
onlyComplete : true ,
network : $scope . network
} ) ;
if ( ! $scope . wallets || ! $scope . wallets . length ) {
$scope . noMatchingWallet = true ;
$log . warn ( 'No ' + $scope . network + ' wallets to make the payment' ) ;
$timeout ( function ( ) {
$scope . $apply ( ) ;
} ) ;
return ;
}
var filteredWallets = [ ] ;
var index = 0 ;
var walletsUpdated = 0 ;
lodash . each ( $scope . wallets , function ( w ) {
walletService . getStatus ( w , { } , function ( err , status ) {
if ( err || ! status ) {
$log . error ( err ) ;
} else {
walletsUpdated ++ ;
w . status = status ;
if ( ! status . availableBalanceSat )
$log . debug ( 'No balance available in: ' + w . name ) ;
console . log ( '[confirm.js.68]' , status . availableBalanceSat , minAmount ) ; //TODO
if ( status . availableBalanceSat > minAmount ) {
filteredWallets . push ( w ) ;
}
}
if ( ++ index == $scope . wallets . length ) {
if ( ! walletsUpdated )
return cb ( 'Could not update any wallet' ) ;
if ( lodash . isEmpty ( filteredWallets ) ) {
$scope . insufficientFunds = true ;
$log . warn ( 'No wallet available to make the payment' ) ;
}
$scope . wallets = lodash . clone ( filteredWallets ) ;
return cb ( ) ;
}
} ) ;
} ) ;
} ;
// Setup $scope
// Grab stateParams
tx = {
toAmount : parseInt ( data . stateParams . toAmount ) ,
sendMax : data . stateParams . useSendMax == 'true' ? true : false ,
toAddress : data . stateParams . toAddress ,
description : data . stateParams . description ,
paypro : data . stateParams . paypro ,
feeLevel : configFeeLevel ,
spendUnconfirmed : walletConfig . spendUnconfirmed ,
// Vanity tx info (not in the real tx)
recipientType : data . stateParams . recipientType || null ,
toName : data . stateParams . toName ,
toEmail : data . stateParams . toEmail ,
toColor : data . stateParams . toColor ,
network : ( new bitcore . Address ( data . stateParams . toAddress ) ) . network . name ,
} ;
// Other Scope vars
$scope . isCordova = isCordova ;
2017-02-22 15:08:51 -05:00
$scope . showAddress = false ;
2016-11-25 17:05:35 -03:00
$scope . insufficientFunds = false ;
2016-11-23 11:23:19 -03:00
$scope . noMatchingWallet = false ;
2016-10-20 15:38:57 -03:00
$scope . paymentExpired = {
value : false
} ;
$scope . remainingTimeStr = {
value : null
} ;
2016-11-25 17:05:35 -03:00
2017-06-20 12:14:21 -03:00
$scope . walletSelectorTitle = gettextCatalog . getString ( 'Send from' ) ;
console . log ( '[confirm.js.126:tx:]' , tx ) ; //TODO
setWalletSelector ( tx . toAmount , function ( err ) {
if ( err ) {
$log . debug ( 'Error updating wallets:' + err ) ;
popupService . showAlert ( gettextCatalog . getString ( 'Could not update wallets' ) , bwcError . msg ( err ) , function ( ) {
$ionicHistory . nextViewOptions ( {
disableAnimate : true ,
historyRoot : true
} ) ;
$ionicHistory . clearHistory ( ) ;
$state . go ( 'tabs.send' ) ;
} ) ;
}
$log . debug ( 'Wallet selector is setup' ) ;
if ( $scope . wallets . length > 1 ) {
$scope . showWalletSelector ( ) ;
} else {
setWallet ( $scope . wallets [ 0 ] , tx ) ;
}
2017-05-19 10:59:36 -03:00
} ) ;
2017-06-20 12:14:21 -03:00
} ) ;
2017-05-16 14:21:33 -03:00
2017-06-20 12:14:21 -03:00
function getSendMaxInfo ( tx , cb ) {
if ( ! tx . sendMax ) return cb ( ) ;
2017-01-16 16:25:12 -03:00
2017-06-20 12:14:21 -03:00
//ongoingProcess.set('retrievingInputs', true);
walletService . getSendMaxInfo ( wallet , {
feePerKb : tx . feeRate ,
excludeUnconfirmedUtxos : ! tx . spendUnconfirmed ,
returnInputs : true ,
} , cb ) ;
2017-01-16 16:25:12 -03:00
} ;
2016-09-20 15:28:31 -03:00
2017-06-20 12:14:21 -03:00
function getTxp ( tx , wallet , dryRun , cb ) {
var paypro = tx . paypro ;
var toAddress = tx . toAddress ;
var description = tx . description ;
// ToDo: use a credential's (or fc's) function for this
if ( description && ! wallet . credentials . sharedEncryptingKey ) {
var msg = gettextCatalog . getString ( 'Could not add message to imported wallet without shared encrypting key' ) ;
$log . warn ( msg ) ;
return setSendError ( msg ) ;
}
if ( tx . toAmount > Number . MAX _SAFE _INTEGER ) {
var msg = gettextCatalog . getString ( 'Amount too big' ) ;
$log . warn ( msg ) ;
return setSendError ( msg ) ;
2016-11-29 14:28:43 -03:00
}
2016-10-10 13:57:25 -03:00
2017-06-20 12:14:21 -03:00
var txp = { } ;
2016-09-20 15:28:31 -03:00
2017-06-20 12:14:21 -03:00
txp . outputs = [ {
'toAddress' : tx . toAddress ,
'amount' : tx . toAmount ,
'message' : tx . description
} ] ;
if ( tx . sendMaxInfo ) {
txp . inputs = tx . sendMaxInfo . inputs ;
txp . fee = tx . sendMaxInfo . fee ;
} else {
txp . feeLevel = tx . feeLevel ;
}
txp . message = description ;
if ( tx . paypro ) {
txp . payProUrl = tx . paypro . url ;
}
txp . excludeUnconfirmedUtxos = ! tx . spendUnconfirmed ;
txp . dryRun = dryRun ;
walletService . createTx ( wallet , txp , function ( err , ctxp ) {
if ( err ) {
setSendError ( err ) ;
return cb ( err ) ;
}
return cb ( null , ctxp ) ;
} ) ;
} ;
function updateTx ( tx , wallet , cb ) {
// Amount
tx . amountStr = txFormatService . formatAmountStr ( tx . amount ) ;
tx . amountValueStr = $scope . amountStr . split ( ' ' ) [ 0 ] ;
tx . amountUnitStr = $scope . amountStr . split ( ' ' ) [ 1 ] ;
txFormatService . formatAlternativeStr ( tx . amount , function ( v ) {
tx . alternativeAmountStr = v ;
} ) ;
$scope . tx = tx ;
feeService . getFeeRate ( tx . network , tx . feeLevel , function ( err , feeRate ) {
if ( err ) return cb ( err ) ;
tx . feeRate = feeRate ;
tx . feeLevelName = feeService . feeOpts [ tx . feeLevel ] ;
getSendMaxInfo ( lodash . clone ( tx ) , function ( err , sendMaxInfo ) {
if ( err ) {
var msg = gettextCatalog . getString ( 'Error getting SendMax information' ) ;
return setSendError ( msg ) ;
}
if ( sendMaxInfo ) {
if ( tx . sendMax && tx . sendMaxInfo . amount == 0 ) {
$scope . insufficientFunds = true ;
popupService . showAlert ( gettextCatalog . getString ( 'Error' ) , gettextCatalog . getString ( 'Not enough funds for fee' ) ) ;
return cb ( 'no_funds' ) ;
2016-10-10 13:57:25 -03:00
}
2017-06-20 12:14:21 -03:00
tx . sendMaxInfo = resp ;
tx . toAmount = parseFloat ( ( tx . sendMaxInfo . amount * unitToSatoshi ) . toFixed ( 0 ) ) ;
2016-09-20 15:28:31 -03:00
}
2017-06-20 12:14:21 -03:00
getTxp ( lodash . clone ( tx ) , wallet , true , function ( err , txp ) {
if ( err ) return cb ( err ) ;
2017-01-16 16:58:42 -03:00
2017-06-20 12:14:21 -03:00
if ( tx . sendMaxInfo )
showSendMaxWarning ( sendMaxInfo , function ( err ) { } ) ;
2017-01-16 16:58:42 -03:00
2017-06-20 12:14:21 -03:00
tx . feeStr = txFormatService . formatAmountStr ( txp . fee ) ;
txFormatService . formatAlternativeStr ( txp . fee , function ( v ) {
tx . alternativeFeeStr = v ;
2016-11-29 11:05:55 -03:00
} ) ;
2017-06-20 12:14:21 -03:00
tx . feeRateStr = ( txp . fee / ( txp . amount + txp . fee ) * 100 ) . toFixed ( 2 ) + '%' ;
tx . txp = tx . txp || [ ] ;
tx . txp [ wallet . id ] = txp ;
return cb ( ) ;
} ) ;
2016-09-20 15:28:31 -03:00
} ) ;
} ) ;
2017-06-20 12:14:21 -03:00
}
2016-11-25 17:05:35 -03:00
2017-06-20 12:14:21 -03:00
function useSelectedWallet ( ) {
2017-02-22 15:08:51 -05:00
2017-06-20 12:14:21 -03:00
if ( ! $scope . useSendMax ) {
showAmount ( tx . toAmount ) ;
}
2016-10-26 14:00:43 -04:00
2017-06-20 12:14:21 -03:00
$scope . onWalletSelect ( $scope . wallet ) ;
}
2016-09-20 15:28:31 -03:00
2017-06-20 12:14:21 -03:00
function setButtonText ( isMultisig , isPayPro ) {
$scope . buttonText = gettextCatalog . getString ( isCordova ? 'Slide' : 'Click' ) + ' ' ;
2016-11-29 14:28:43 -03:00
2017-06-20 12:14:21 -03:00
if ( isPayPro ) {
$scope . buttonText += gettextCatalog . getString ( 'to pay' ) ;
} else if ( isMultisig ) {
$scope . buttonText += gettextCatalog . getString ( 'to accept' ) ;
} else
$scope . buttonText += gettextCatalog . getString ( 'to send' ) ;
2016-11-29 11:05:55 -03:00
} ;
2016-11-25 15:24:02 -03:00
2017-06-20 12:14:21 -03:00
$scope . toggleAddress = function ( ) {
$scope . showAddress = ! $scope . showAddress ;
} ;
2016-11-23 11:23:19 -03:00
2017-06-20 12:14:21 -03:00
function resetView ( ) {
$scope . displayAmount = $scope . displayUnit = $scope . fee = $scope . feeFiat = $scope . feeRateStr = $scope . alternativeAmountStr = $scope . insufficientFunds = $scope . noMatchingWallet = null ;
$scope . showAddress = false ;
2016-11-24 16:17:01 -03:00
2017-06-20 12:14:21 -03:00
console . log ( '[confirm.js.213] RESET' ) ; //TODO
} ;
2016-11-25 15:59:44 -03:00
2016-11-23 11:23:19 -03:00
2017-06-20 12:14:21 -03:00
function showSendMaxWarning ( sendMaxInfo ) {
2016-11-23 11:23:19 -03:00
2017-06-20 12:14:21 -03:00
function verifyExcludedUtxos ( ) {
var warningMsg = [ ] ;
if ( sendMaxInfo . utxosBelowFee > 0 ) {
warningMsg . push ( gettextCatalog . getString ( "A total of {{amountBelowFeeStr}} were excluded. These funds come from UTXOs smaller than the network fee provided." , {
amountBelowFeeStr : txFormatService . formatAmountStr ( sendMaxInfo . amountBelowFee )
} ) ) ;
}
2016-11-23 11:23:19 -03:00
2017-06-20 12:14:21 -03:00
if ( sendMaxInfo . utxosAboveMaxSize > 0 ) {
warningMsg . push ( gettextCatalog . getString ( "A total of {{amountAboveMaxSizeStr}} were excluded. The maximum size allowed for a transaction was exceeded." , {
amountAboveMaxSizeStr : txFormatService . formatAmountStr ( sendMaxInfo . amountAboveMaxSize )
} ) ) ;
}
return warningMsg . join ( '\n' ) ;
} ;
2016-11-23 11:23:19 -03:00
2017-06-20 12:14:21 -03:00
var msg = gettextCatalog . getString ( "{{fee}} will be deducted for bitcoin networking fees." , {
fee : txFormatService . formatAmountStr ( sendMaxInfo . fee )
2016-11-23 11:23:19 -03:00
} ) ;
2017-06-20 12:14:21 -03:00
var warningMsg = verifyExcludedUtxos ( ) ;
if ( ! lodash . isEmpty ( warningMsg ) )
msg += '\n' + warningMsg ;
popupService . showAlert ( null , msg , function ( ) { } ) ;
2016-11-23 11:23:19 -03:00
} ;
2016-11-25 15:59:44 -03:00
function setSendMaxValues ( data ) {
2017-06-20 12:14:21 -03:00
resetView ( ) ;
2016-12-16 14:54:16 -03:00
$scope . amountStr = txFormatService . formatAmountStr ( data . amount , true ) ;
$scope . displayAmount = getDisplayAmount ( $scope . amountStr ) ;
$scope . displayUnit = getDisplayUnit ( $scope . amountStr ) ;
2016-11-29 12:02:10 -03:00
$scope . fee = txFormatService . formatAmountStr ( data . fee ) ;
2017-05-16 14:21:33 -03:00
txFormatService . formatAlternativeStr ( data . fee , function ( v ) {
$scope . feeFiat = v ;
} ) ;
2016-11-25 15:59:44 -03:00
toAmount = parseFloat ( ( data . amount * satToUnit ) . toFixed ( unitDecimals ) ) ;
txFormatService . formatAlternativeStr ( data . amount , function ( v ) {
$scope . alternativeAmountStr = v ;
} ) ;
2017-05-16 14:36:20 -03:00
$scope . feeRateStr = ( data . fee / ( data . amount + data . fee ) * 100 ) . toFixed ( 2 ) + '%' ;
2016-11-29 11:05:55 -03:00
$timeout ( function ( ) {
$scope . $apply ( ) ;
} ) ;
2016-11-25 15:59:44 -03:00
} ;
2016-09-20 15:28:31 -03:00
$scope . $on ( 'accepted' , function ( event ) {
$scope . approve ( ) ;
} ) ;
2016-09-02 14:55:18 -03:00
2016-10-12 20:13:28 -04:00
$scope . onWalletSelect = function ( wallet ) {
2017-06-20 12:14:21 -03:00
setWallet ( wallet , tx ) ;
2016-10-12 18:49:00 -04:00
} ;
2017-06-20 12:14:21 -03:00
// TODO
2016-08-24 16:53:14 -03:00
$scope . showDescriptionPopup = function ( ) {
2016-09-23 12:07:56 -03:00
var message = gettextCatalog . getString ( 'Add description' ) ;
2016-09-16 21:01:19 -03:00
var opts = {
defaultText : $scope . description
2016-09-07 16:48:16 -03:00
} ;
2016-09-23 12:07:56 -03:00
popupService . showPrompt ( null , message , opts , function ( res ) {
2016-10-11 15:46:02 -03:00
if ( typeof res != 'undefined' ) $scope . description = res ;
2016-09-23 12:07:56 -03:00
$timeout ( function ( ) {
$scope . $apply ( ) ;
2016-11-29 11:05:55 -03:00
} ) ;
2016-08-24 15:47:36 -03:00
} ) ;
} ;
2016-10-20 15:38:57 -03:00
function _paymentTimeControl ( expirationTime ) {
$scope . paymentExpired . value = false ;
setExpirationTime ( ) ;
countDown = $interval ( function ( ) {
setExpirationTime ( ) ;
} , 1000 ) ;
function setExpirationTime ( ) {
var now = Math . floor ( Date . now ( ) / 1000 ) ;
if ( now > expirationTime ) {
setExpiredValues ( ) ;
return ;
}
var totalSecs = expirationTime - now ;
var m = Math . floor ( totalSecs / 60 ) ;
var s = totalSecs % 60 ;
$scope . remainingTimeStr . value = ( '0' + m ) . slice ( - 2 ) + ":" + ( '0' + s ) . slice ( - 2 ) ;
2016-11-23 11:23:19 -03:00
} ;
2016-10-20 15:38:57 -03:00
function setExpiredValues ( ) {
$scope . paymentExpired . value = true ;
$scope . remainingTimeStr . value = gettextCatalog . getString ( 'Expired' ) ;
if ( countDown ) $interval . cancel ( countDown ) ;
$timeout ( function ( ) {
$scope . $apply ( ) ;
} ) ;
2016-11-23 11:23:19 -03:00
} ;
} ;
2016-10-20 15:38:57 -03:00
2017-06-20 12:14:21 -03:00
/* sets a wallet on the UI, creates a TXPs for that wallet */
function setWallet ( wallet , tx ) {
2016-08-23 16:15:10 -03:00
$scope . wallet = wallet ;
2016-08-18 14:51:35 -03:00
2017-06-20 12:14:21 -03:00
setButtonText ( wallet . credentials . m > 1 , ! ! tx . paypro ) ;
//T TODO
if ( $scope . paypro )
_paymentTimeControl ( $scope . paypro . expires ) ;
updateTx ( tx , wallet , function ( err ) {
if ( err ) return ;
$timeout ( function ( ) {
$ionicScrollDelegate . resize ( ) ;
$scope . $apply ( ) ;
} , 10 ) ;
} ) ;
2016-11-24 16:26:15 -03:00
2016-11-23 11:23:19 -03:00
} ;
2016-08-16 18:38:18 -03:00
2016-08-17 15:36:19 -03:00
var setSendError = function ( msg ) {
2016-10-10 15:27:57 -04:00
$scope . sendStatus = '' ;
2016-10-17 14:46:51 -03:00
$timeout ( function ( ) {
$scope . $apply ( ) ;
} ) ;
2016-12-13 14:21:57 -03:00
popupService . showAlert ( gettextCatalog . getString ( 'Error at confirm' ) , bwcError . msg ( msg ) ) ;
2016-08-17 13:16:06 -03:00
} ;
2016-08-16 18:38:18 -03:00
2016-08-24 19:12:11 -03:00
$scope . openPPModal = function ( ) {
$ionicModal . fromTemplateUrl ( 'views/modals/paypro.html' , {
scope : $scope
} ) . then ( function ( modal ) {
$scope . payproModal = modal ;
$scope . payproModal . show ( ) ;
} ) ;
} ;
2016-12-27 16:16:55 -03:00
$scope . cancel = function ( ) {
$scope . payproModal . hide ( ) ;
} ;
2016-10-07 20:12:37 -04:00
$scope . approve = function ( onSendStatusChange ) {
2016-12-05 11:17:48 -03:00
var wallet = $scope . wallet ;
if ( ! wallet ) {
return ;
}
2016-10-26 16:09:21 -04:00
if ( $scope . paypro && $scope . paymentExpired . value ) {
2016-10-27 16:15:11 -04:00
popupService . showAlert ( null , gettextCatalog . getString ( 'This bitcoin payment request has expired.' ) ) ;
2016-10-20 16:44:20 -03:00
$scope . sendStatus = '' ;
$timeout ( function ( ) {
$scope . $apply ( ) ;
} ) ;
2016-10-20 15:38:57 -03:00
return ;
}
2016-10-07 20:03:51 -04:00
ongoingProcess . set ( 'creatingTx' , true , onSendStatusChange ) ;
2017-06-20 12:14:21 -03:00
getTxp ( wallet , false , function ( err , txp ) {
2016-10-07 20:03:51 -04:00
ongoingProcess . set ( 'creatingTx' , false , onSendStatusChange ) ;
2016-12-16 14:54:16 -03:00
if ( err ) return ;
2016-09-21 11:47:19 -03:00
var spendingPassEnabled = walletService . isEncrypted ( wallet ) ;
var bigAmount = parseFloat ( txFormatService . formatToUSD ( txp . amount ) ) > 20 ;
2016-09-23 10:33:26 -03:00
var message = gettextCatalog . getString ( 'Sending {{amountStr}} from your {{name}} wallet' , {
2016-11-29 14:28:43 -03:00
amountStr : $scope . amountStr ,
2016-09-21 11:47:19 -03:00
name : wallet . name
2016-09-02 14:17:47 -03:00
} ) ;
2016-09-21 11:47:19 -03:00
var okText = gettextCatalog . getString ( 'Confirm' ) ;
var cancelText = gettextCatalog . getString ( 'Cancel' ) ;
if ( ! spendingPassEnabled && ! touchIdEnabled ) {
2016-10-12 10:53:27 -03:00
if ( isCordova ) {
if ( bigAmount ) {
popupService . showConfirm ( null , message , okText , cancelText , function ( ok ) {
if ( ! ok ) {
$scope . sendStatus = '' ;
$timeout ( function ( ) {
$scope . $apply ( ) ;
} ) ;
return ;
}
publishAndSign ( wallet , txp , onSendStatusChange ) ;
} ) ;
2016-10-20 15:38:57 -03:00
} else publishAndSign ( wallet , txp , onSendStatusChange ) ;
} else {
2016-09-21 11:47:19 -03:00
popupService . showConfirm ( null , message , okText , cancelText , function ( ok ) {
2016-10-10 14:33:55 -04:00
if ( ! ok ) {
$scope . sendStatus = '' ;
return ;
}
2016-10-07 20:12:37 -04:00
publishAndSign ( wallet , txp , onSendStatusChange ) ;
2016-09-21 11:47:19 -03:00
} ) ;
}
2016-10-20 15:38:57 -03:00
} else publishAndSign ( wallet , txp , onSendStatusChange ) ;
2016-09-21 11:47:19 -03:00
} ) ;
} ;
2016-10-07 20:12:37 -04:00
function statusChangeHandler ( processName , showName , isOn ) {
2016-10-11 10:19:05 -03:00
$log . debug ( 'statusChangeHandler: ' , processName , showName , isOn ) ;
2016-12-14 15:26:56 -03:00
if (
(
2017-02-20 10:25:52 -05:00
processName === 'broadcastingTx' ||
( ( processName === 'signingTx' ) && $scope . wallet . m > 1 ) ||
2017-01-13 01:21:32 -03:00
( processName == 'sendingTx' && ! $scope . wallet . canSign ( ) && ! $scope . wallet . isPrivKeyExternal ( ) )
2016-12-14 15:26:56 -03:00
) && ! isOn ) {
2016-10-07 20:03:51 -04:00
$scope . sendStatus = 'success' ;
2016-12-19 11:50:49 -03:00
$timeout ( function ( ) {
$scope . $digest ( ) ;
2017-01-13 01:21:32 -03:00
} , 100 ) ;
2016-10-11 10:19:05 -03:00
} else if ( showName ) {
2016-10-07 20:03:51 -04:00
$scope . sendStatus = showName ;
}
2016-11-23 11:23:19 -03:00
} ;
2016-10-07 20:03:51 -04:00
2016-10-10 15:27:57 -04:00
$scope . statusChangeHandler = statusChangeHandler ;
2016-10-07 20:03:51 -04:00
$scope . onConfirm = function ( ) {
2016-10-07 20:12:37 -04:00
$scope . approve ( statusChangeHandler ) ;
2016-10-07 20:03:51 -04:00
} ;
$scope . onSuccessConfirm = function ( ) {
2016-10-13 17:49:48 -03:00
var previousView = $ionicHistory . viewHistory ( ) . backView && $ionicHistory . viewHistory ( ) . backView . stateName ;
2016-10-07 20:03:51 -04:00
$ionicHistory . nextViewOptions ( {
disableAnimate : true
} ) ;
2016-10-13 17:49:48 -03:00
$ionicHistory . removeBackView ( ) ;
2016-10-10 15:27:57 -04:00
$scope . sendStatus = '' ;
2016-10-13 17:49:48 -03:00
2017-02-17 13:45:17 -03:00
$ionicHistory . nextViewOptions ( {
disableAnimate : true ,
historyRoot : true
} ) ;
$ionicHistory . clearHistory ( ) ;
$state . go ( 'tabs.send' ) . then ( function ( ) {
$state . transitionTo ( 'tabs.home' ) ;
} ) ;
2016-10-07 20:03:51 -04:00
} ;
2017-01-13 01:21:32 -03:00
function publishAndSign ( wallet , txp , onSendStatusChange ) {
2016-12-14 15:26:56 -03:00
if ( ! wallet . canSign ( ) && ! wallet . isPrivKeyExternal ( ) ) {
$log . info ( 'No signing proposal: No private key' ) ;
2017-01-13 01:21:32 -03:00
return walletService . onlyPublish ( wallet , txp , function ( err ) {
if ( err ) setSendError ( err ) ;
2016-12-14 15:26:56 -03:00
} , onSendStatusChange ) ;
}
2016-09-21 11:47:19 -03:00
walletService . publishAndSign ( wallet , txp , function ( err , txp ) {
2017-01-13 01:21:32 -03:00
if ( err ) return setSendError ( err ) ;
2016-10-07 20:03:51 -04:00
} , onSendStatusChange ) ;
2016-12-30 19:08:51 -03:00
} ;
2017-05-16 14:21:33 -03:00
$scope . chooseFeeLevel = function ( ) {
2017-05-19 10:59:36 -03:00
$scope . customFeeLevel = feeLevel ;
$ionicModal . fromTemplateUrl ( 'views/modals/chooseFeeLevel.html' , {
scope : $scope ,
} ) . then ( function ( modal ) {
$scope . chooseFeeLevelModal = modal ;
$scope . openModal ( ) ;
} ) ;
$scope . openModal = function ( ) {
$scope . chooseFeeLevelModal . show ( ) ;
} ;
$scope . hideModal = function ( customFeeLevel ) {
if ( customFeeLevel ) {
ongoingProcess . set ( 'gettingFeeLevels' , true ) ;
2017-06-20 12:14:21 -03:00
setAndShowFee ( customFeeLevel , function ( ) {
2017-05-19 10:59:36 -03:00
ongoingProcess . set ( 'gettingFeeLevels' , false ) ;
2017-06-20 12:14:21 -03:00
resetView ( ) ;
if ( $scope . wallet )
useSelectedWallet ( ) ;
2017-05-19 10:59:36 -03:00
} )
}
$scope . chooseFeeLevelModal . hide ( ) ;
} ;
2017-05-16 14:21:33 -03:00
} ;
2016-08-16 18:38:18 -03:00
} ) ;