send
This commit is contained in:
parent
eb733c5d3c
commit
7d0870aea0
6 changed files with 152 additions and 77 deletions
|
|
@ -2,17 +2,17 @@
|
||||||
|
|
||||||
<ion-nav-bar class="bar-stable">
|
<ion-nav-bar class="bar-stable">
|
||||||
<ion-nav-title>Enter Amount</ion-nav-title>
|
<ion-nav-title>Enter Amount</ion-nav-title>
|
||||||
</ion-nav-bar>
|
|
||||||
|
|
||||||
<ion-pane>
|
|
||||||
<ion-content class="calculator" scroll="false" class="amount" ng-controller="amountController" ng-init="init()">
|
|
||||||
|
|
||||||
<ion-nav-buttons side="primary">
|
<ion-nav-buttons side="primary">
|
||||||
<button class="button" href ui-sref="tabs.send">
|
<button class="button" href ui-sref="tabs.send">
|
||||||
<i class="ion-arrow-left-c"></i> Back
|
<i class="ion-arrow-left-c"></i> Back
|
||||||
</button>
|
</button>
|
||||||
</ion-nav-buttons>
|
</ion-nav-buttons>
|
||||||
|
</ion-nav-bar>
|
||||||
|
|
||||||
|
<ion-pane>
|
||||||
|
<ion-content class="calculator" scroll="false" class="amount" ng-controller="amountController" ng-init="init()">
|
||||||
|
|
||||||
<div class="list card">
|
<div class="list card">
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,17 @@
|
||||||
<ion-pane>
|
<ion-pane>
|
||||||
<ion-nav-bar class="bar-stable">
|
<ion-nav-bar class="bar-stable">
|
||||||
<ion-nav-title>Confirm</ion-nav-title>
|
<ion-nav-title>Confirm</ion-nav-title>
|
||||||
|
|
||||||
|
<ion-nav-buttons side="primary">
|
||||||
|
<button class="button" href ui-sref="tabs.send">
|
||||||
|
<i class="ion-arrow-left-c"></i> Back
|
||||||
|
</button>
|
||||||
|
</ion-nav-buttons>
|
||||||
</ion-nav-bar>
|
</ion-nav-bar>
|
||||||
|
|
||||||
|
|
||||||
<ion-content scroll="false" ng-controller="confirmController" ng-init="init()">
|
<ion-content scroll="false" ng-controller="confirmController" ng-init="init()">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ion-nav-buttons side="primary">
|
|
||||||
<button class="button" href ui-sref="amount({toAddress: toAddress, toName: toName, toAmount: toAmount})">
|
|
||||||
<i class="ion-arrow-left-c"></i> Back
|
|
||||||
</button>
|
|
||||||
</ion-nav-buttons>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ion-content ng-style="{'background-color':'#f6f7f9'}">
|
<ion-content ng-style="{'background-color':'#f6f7f9'}">
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, walletService, platformInfo, lodash, configService, go, rateService, $stateParams, $window, $state, $log, profileService, bitcore, $ionicPopup, txStatus) {
|
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, walletService, platformInfo, lodash, configService, go, rateService, $stateParams, $window, $state, $log, profileService, bitcore, $ionicPopup, txStatus, ongoingProcess, fingerprintService, gettext) {
|
||||||
|
|
||||||
// An alert dialog
|
// An alert dialog
|
||||||
var showAlert = function(title, msg, cb) {
|
var showAlert = function(title, msg, cb) {
|
||||||
$log.warn(title + ":"+ msg);
|
$log.warn(title + ":" + msg);
|
||||||
var alertPopup = $ionicPopup.alert({
|
var alertPopup = $ionicPopup.alert({
|
||||||
title: title,
|
title: title,
|
||||||
template: msg
|
template: msg
|
||||||
|
|
@ -17,11 +16,54 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// An alert dialog
|
||||||
|
var askPassword = function(name, cb) {
|
||||||
|
$scope.data = [];
|
||||||
|
var pass = $ionicPopup.show({
|
||||||
|
template: '<input type="password" ng-model="data.pass">',
|
||||||
|
title: 'Enter Spending Password',
|
||||||
|
subTitle: name,
|
||||||
|
scope: $scope,
|
||||||
|
buttons: [{
|
||||||
|
text: 'Cancel'
|
||||||
|
}, {
|
||||||
|
text: '<b>OK</b>',
|
||||||
|
type: 'button-positive',
|
||||||
|
onTap: function(e) {
|
||||||
|
|
||||||
|
console.log('[confirm.js.32]', $scope, $scope.data); //TODO
|
||||||
|
if (!$scope.data.pass) {
|
||||||
|
//don't allow the user to close unless he enters wifi password
|
||||||
|
e.preventDefault();
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $scope.data.pass;
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
pass.then(function(res) {
|
||||||
|
console.log('Tapped!', res);
|
||||||
|
return cb(res);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var handleEncryptedWallet = function(wallet, cb) {
|
||||||
|
if (!walletService.isEncrypted(wallet)) return cb();
|
||||||
|
|
||||||
|
askPassword(wallet.name, function(password) {
|
||||||
|
if (!password) return cb('no password');
|
||||||
|
return cb(walletService.unlock(wallet, password));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var unitToSatoshi;
|
var unitToSatoshi;
|
||||||
var satToUnit;
|
var satToUnit;
|
||||||
var unitDecimals;
|
var unitDecimals;
|
||||||
var satToBtc;
|
var satToBtc;
|
||||||
var self = $scope.self;
|
|
||||||
var SMALL_FONT_SIZE_LIMIT = 13;
|
var SMALL_FONT_SIZE_LIMIT = 13;
|
||||||
var LENGTH_EXPRESSION_LIMIT = 19;
|
var LENGTH_EXPRESSION_LIMIT = 19;
|
||||||
var config;
|
var config;
|
||||||
|
|
@ -47,7 +89,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
satToBtc = 1 / 100000000;
|
satToBtc = 1 / 100000000;
|
||||||
|
|
||||||
$scope.toAmount = parseInt($stateParams.toAmount);
|
$scope.toAmount = parseInt($stateParams.toAmount);
|
||||||
$scope.amount = (($stateParams.toAmount) * satToUnit).toFixed(unitDecimals) ;
|
$scope.amount = (($stateParams.toAmount) * satToUnit).toFixed(unitDecimals);
|
||||||
$scope.toAddress = $stateParams.toAddress;
|
$scope.toAddress = $stateParams.toAddress;
|
||||||
$scope.toName = $stateParams.toName;
|
$scope.toName = $stateParams.toName;
|
||||||
|
|
||||||
|
|
@ -80,7 +122,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
var currentSpendUnconfirmed = config.spendUnconfirmed;
|
var currentSpendUnconfirmed = config.spendUnconfirmed;
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
var wallet = $scope.wallet;
|
var wallet = $scope.wallet;
|
||||||
if (!wallet) {
|
if (!wallet) {
|
||||||
$log.error('No wallet selected')
|
$log.error('No wallet selected')
|
||||||
|
|
@ -105,45 +147,43 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
};
|
};
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
outputs.push({
|
outputs.push({
|
||||||
'toAddress': toAddress,
|
'toAddress': toAddress,
|
||||||
'amount': toAmount,
|
'amount': toAmount,
|
||||||
'message': comment
|
'message': comment
|
||||||
});
|
});
|
||||||
|
|
||||||
var txp = {};
|
var txp = {};
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
if (!lodash.isEmpty($scope.sendMaxInfo)) {
|
if (!lodash.isEmpty($scope.sendMaxInfo)) {
|
||||||
txp.sendMax = true;
|
txp.sendMax = true;
|
||||||
txp.inputs = $scope.sendMaxInfo.inputs;
|
txp.inputs = $scope.sendMaxInfo.inputs;
|
||||||
txp.fee = $scope.sendMaxInfo.fee;
|
txp.fee = $scope.sendMaxInfo.fee;
|
||||||
|
}
|
||||||
|
|
||||||
|
txp.outputs = outputs;
|
||||||
|
txp.message = comment;
|
||||||
|
txp.payProUrl = paypro ? paypro.url : null;
|
||||||
|
txp.excludeUnconfirmedUtxos = config.spendUnconfirmed ? false : true;
|
||||||
|
txp.feeLevel = config.feeLevel || 'normal';
|
||||||
|
|
||||||
|
|
||||||
|
walletService.createTx(wallet, txp, function(err, createdTxp) {
|
||||||
|
if (err) {
|
||||||
|
return setSendError(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
txp.outputs = outputs;
|
$scope.fee = ((createdTxp.fee) * satToUnit).toFixed(unitDecimals);
|
||||||
txp.message = comment;
|
$scope.txp = createdTxp;
|
||||||
txp.payProUrl = paypro ? paypro.url : null;
|
});
|
||||||
txp.excludeUnconfirmedUtxos = config.spendUnconfirmed ? false : true;
|
|
||||||
txp.feeLevel = config.feeLevel || 'normal';
|
|
||||||
|
|
||||||
|
|
||||||
console.log('[confirm.js.100] creatingTx', wallet, txp); //TODO
|
|
||||||
walletService.createTx(wallet, txp, function(err, createdTxp) {
|
|
||||||
console.log('[confirm.js.102:createdTxp:]',err, createdTxp); //TODO
|
|
||||||
if (err) {
|
|
||||||
return setSendError(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.fee = ((createdTxp.fee) * satToUnit).toFixed(unitDecimals) ;
|
|
||||||
$scope.txp = createdTxp;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$scope.approve = function() {
|
$scope.approve = function() {
|
||||||
var wallet = $scope.wallet;
|
var wallet = $scope.wallet;
|
||||||
var txp =$scope.txp;
|
var txp = $scope.txp;
|
||||||
if (!wallet) {
|
if (!wallet) {
|
||||||
return setSendError(gettext('No wallet selected'));
|
return setSendError(gettext('No wallet selected'));
|
||||||
return;
|
return;
|
||||||
|
|
@ -156,9 +196,9 @@ console.log('[confirm.js.102:createdTxp:]',err, createdTxp); //TODO
|
||||||
|
|
||||||
if (!wallet.canSign() && !wallet.isPrivKeyExternal()) {
|
if (!wallet.canSign() && !wallet.isPrivKeyExternal()) {
|
||||||
$log.info('No signing proposal: No private key');
|
$log.info('No signing proposal: No private key');
|
||||||
// ongoingProcess.set('sendingTx', true);
|
ongoingProcess.set('sendingTx', true);
|
||||||
walletService.publishTx(wallet, txp, function(err, publishedTxp) {
|
walletService.publishTx(wallet, txp, function(err, publishedTxp) {
|
||||||
// ongoingProcess.set('sendingTx', false);
|
ongoingProcess.set('sendingTx', false);
|
||||||
if (err) {
|
if (err) {
|
||||||
return setSendError(err);
|
return setSendError(err);
|
||||||
}
|
}
|
||||||
|
|
@ -170,53 +210,82 @@ console.log('[confirm.js.102:createdTxp:]',err, createdTxp); //TODO
|
||||||
return $scope.$emit('Local/TxProposalAction');
|
return $scope.$emit('Local/TxProposalAction');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
return;
|
||||||
|
|
||||||
$rootScope.$emit('Local/NeedsConfirmation', txp, function(accept) {
|
|
||||||
if (accept) self.confirmTx(txp);
|
|
||||||
else self.resetForm();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
fingerprintService.check(wallet, function(err) {
|
||||||
|
if (err) {
|
||||||
|
return setSendError(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleEncryptedWallet(wallet, function(err) {
|
||||||
|
if (err) {
|
||||||
|
return setSendError(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
ongoingProcess.set('sendingTx', true);
|
||||||
|
walletService.publishTx(wallet, txp, function(err, publishedTxp) {
|
||||||
|
ongoingProcess.set('sendingTx', false);
|
||||||
|
if (err) {
|
||||||
|
return setSendError(err);
|
||||||
|
}
|
||||||
|
|
||||||
function fromFiat(val) {
|
ongoingProcess.set('signingTx', true);
|
||||||
if (!rateService.isAvailable()) return;
|
walletService.signTx(wallet, txp, function(err, signedTxp) {
|
||||||
|
ongoingProcess.set('signingTx', false);
|
||||||
return parseFloat((rateService.fromFiat(val, $scope.alternativeIsoCode) * satToUnit).toFixed(unitDecimals), 10);
|
walletService.lock(wallet);
|
||||||
|
if (err) {
|
||||||
|
$scope.$emit('Local/TxProposalAction');
|
||||||
|
return setSendError(
|
||||||
|
err.message ?
|
||||||
|
err.message :
|
||||||
|
gettext('The payment was created but could not be completed. Please try again from home screen'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (signedTxp.status == 'accepted') {
|
||||||
|
ongoingProcess.set('broadcastingTx', true);
|
||||||
|
walletService.broadcastTx(wallet, signedTxp, function(err, broadcastedTxp) {
|
||||||
|
ongoingProcess.set('broadcastingTx', false);
|
||||||
|
if (err) {
|
||||||
|
return setSendError(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
$state.transitionTo('tabs.send');
|
||||||
|
var type = txStatus.notify(broadcastedTxp);
|
||||||
|
$scope.openStatusModal(type, broadcastedTxp, function() {
|
||||||
|
$scope.$emit('Local/TxProposalAction', broadcastedTxp.status == 'broadcasted');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$state.transitionTo('tabs.send');
|
||||||
|
var type = txStatus.notify(signedTxp);
|
||||||
|
$scope.openStatusModal(type, signedTxp, function() {
|
||||||
|
$scope.$emit('Local/TxProposalAction');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function toFiat(val, cb) {
|
function toFiat(val, cb) {
|
||||||
rateService.whenAvailable(function() {
|
rateService.whenAvailable(function() {
|
||||||
|
|
||||||
console.log('[confirm.js.194] WWW'); //TODO
|
|
||||||
return cb(parseFloat((rateService.toFiat(val * unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10));
|
return cb(parseFloat((rateService.toFiat(val * unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.finish = function() {
|
|
||||||
var _amount = evaluate(format($scope.amount));
|
|
||||||
var amount = $scope.showAlternativeAmount ? fromFiat(_amount).toFixed(unitDecimals) : _amount.toFixed(unitDecimals);
|
|
||||||
|
|
||||||
$state.transitionTo('confirm', {
|
|
||||||
toAmount:walletService.formatAmount(amount * unitToSatoshi, true),
|
|
||||||
toAddress: $scope.toAddress,
|
|
||||||
toName: $scope.toName,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.cancel = function() {
|
$scope.cancel = function() {
|
||||||
$state.transitionTo('tabs.send');
|
$state.transitionTo('tabs.send');
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.setWallets = function(network) {
|
$scope.setWallets = function(network) {
|
||||||
$scope.wallets = profileService.getWallets({onlyComplete:true, network: network});
|
$scope.wallets = profileService.getWallets({
|
||||||
|
onlyComplete: true,
|
||||||
|
network: network
|
||||||
|
});
|
||||||
$scope.wallet = $scope.wallets[0];
|
$scope.wallet = $scope.wallets[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -36,5 +36,5 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
$scope.bitpayCardEnabled = true; // TODO
|
$scope.bitpayCardEnabled = true; // TODO
|
||||||
|
|
||||||
|
|
||||||
$state.transitionTo('confirm', {toAmount:555500, toAddress: 'mvfAwUJohJWibGzBZgAUGsDarsr4Z4NovU', toName: 'bla bla'});
|
// $state.transitionTo('confirm', {toAmount:555500, toAddress: 'mvfAwUJohJWibGzBZgAUGsDarsr4Z4NovU', toName: 'bla bla'});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ angular.module('copayApp.services').factory('txFormatService', function(profileS
|
||||||
var formatAmountStr = function(amount) {
|
var formatAmountStr = function(amount) {
|
||||||
if (!amount) return;
|
if (!amount) return;
|
||||||
var config = configService.getSync().wallet.settings;
|
var config = configService.getSync().wallet.settings;
|
||||||
return profileService.formatAmount(amount) + ' ' + config.unitName;
|
return walletService.formatAmount(amount) + ' ' + config.unitName;
|
||||||
};
|
};
|
||||||
|
|
||||||
var formatAlternativeStr = function(amount) {
|
var formatAlternativeStr = function(amount) {
|
||||||
|
|
@ -18,7 +18,7 @@ angular.module('copayApp.services').factory('txFormatService', function(profileS
|
||||||
var formatFeeStr = function(fee) {
|
var formatFeeStr = function(fee) {
|
||||||
if (!fee) return;
|
if (!fee) return;
|
||||||
var config = configService.getSync().wallet.settings;
|
var config = configService.getSync().wallet.settings;
|
||||||
return profileService.formatAmount(fee) + ' ' + config.unitName;
|
return walletService.formatAmount(fee) + ' ' + config.unitName;
|
||||||
};
|
};
|
||||||
|
|
||||||
root.processTx = function(tx) {
|
root.processTx = function(tx) {
|
||||||
|
|
|
||||||
|
|
@ -843,5 +843,14 @@ console.log('[walletService.js.786:wallet:]',wallet, forceNew); //TODO
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
root.handleEncryptedWallet = function(client, cb) {
|
||||||
|
if (!root.isEncrypted(client)) return cb();
|
||||||
|
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
return cb(walletService.unlock(client, password));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue