Merge pull request #3347 from javierbitpay/bug/send-all

Bug/send all
This commit is contained in:
Gustavo Maximiliano Cortez 2015-10-28 09:53:55 -03:00
commit 11d675e46a
2 changed files with 26 additions and 43 deletions

View File

@ -333,19 +333,20 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setSendMax = function() { self.setSendMax = function() {
self.feeToSendMaxStr = null;
self.feeRateToSendMax = null;
// Set Send max // Set Send max
if (self.currentFeeLevel && self.totalBytesToSendMax) { if (self.currentFeeLevel && self.totalBytesToSendMax) {
feeService.getCurrentFeeValue(self.currentFeeLevel, function(err, feePerKb) { feeService.getCurrentFeeValue(self.currentFeeLevel, function(err, feePerKb) {
// KB to send max // KB to send max
if (self.totalBytesToSendMax) { var feeToSendMaxSat = parseInt(((self.totalBytesToSendMax * feePerKb) / 1000.).toFixed(0));
var feeToSendMaxSat = parseInt(((self.totalBytesToSendMax * feePerKb) / 1000.).toFixed(0)); self.feeRateToSendMax = feePerKb;
self.feeRateToSendMax = feePerKb;
if (self.availableBalanceSat > feeToSendMaxSat) {
self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit); self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit);
self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName; self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName;
} else {
self.feeToSendMaxStr = null;
self.feeRateToSendMax = null;
} }
}); });
} }
@ -1255,4 +1256,4 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setFocusedWallet(); self.setFocusedWallet();
}); });
}); });
}); });

View File

@ -142,12 +142,15 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
self.resetForm(); self.resetForm();
var ModalInstanceCtrl = function($scope, $modalInstance) { var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.wallets = wallets; $scope.wallets = wallets;
$scope.editAddressbook = false; $scope.editAddressbook = false;
$scope.addAddressbookEntry = false; $scope.addAddressbookEntry = false;
$scope.selectedAddressbook = {}; $scope.selectedAddressbook = {};
$scope.newAddress = address; $scope.newAddress = address;
$scope.addressbook = { 'address' : ($scope.newAddress || '') , 'label' : ''}; $scope.addressbook = {
'address': ($scope.newAddress || ''),
'label': ''
};
$scope.color = fc.backgroundColor; $scope.color = fc.backgroundColor;
$scope.beforeQrCodeScann = function() { $scope.beforeQrCodeScann = function() {
@ -185,14 +188,17 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.toggleAddAddressbookEntry = function() { $scope.toggleAddAddressbookEntry = function() {
$scope.error = null; $scope.error = null;
$scope.addressbook = { 'address' : ($scope.newAddress || '') , 'label' : ''}; $scope.addressbook = {
'address': ($scope.newAddress || ''),
'label': ''
};
$scope.addAddressbookEntry = !$scope.addAddressbookEntry; $scope.addAddressbookEntry = !$scope.addAddressbookEntry;
}; };
$scope.list = function() { $scope.list = function() {
$scope.error = null; $scope.error = null;
addressbookService.list(function(err, ab) { addressbookService.list(function(err, ab) {
if (err) { if (err) {
$scope.error = err; $scope.error = err;
return; return;
} }
@ -204,7 +210,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.error = null; $scope.error = null;
$timeout(function() { $timeout(function() {
addressbookService.add(addressbook, function(err, ab) { addressbookService.add(addressbook, function(err, ab) {
if (err) { if (err) {
$scope.error = err; $scope.error = err;
return; return;
} }
@ -220,7 +226,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.error = null; $scope.error = null;
$timeout(function() { $timeout(function() {
addressbookService.remove(addr, function(err, ab) { addressbookService.remove(addr, function(err, ab) {
if (err) { if (err) {
$scope.error = err; $scope.error = err;
return; return;
} }
@ -348,7 +354,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}; };
$scope.sign = function(txp) { $scope.sign = function(txp) {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if (!fc.canSign() && !fc.isPrivKeyExternal()) if (!fc.canSign() && !fc.isPrivKeyExternal())
return; return;
@ -366,7 +372,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
self._setOngoingForSigning(); self._setOngoingForSigning();
$scope.loading = true; $scope.loading = true;
$scope.error = null; $scope.error = null;
$timeout(function() { $timeout(function() {
requestTouchid(function(err) { requestTouchid(function(err) {
if (err) { if (err) {
@ -900,7 +906,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
} else { } else {
feeService.getCurrentFeeValue(self.currentSendFeeLevel, cb); feeService.getCurrentFeeValue(self.currentSendFeeLevel, cb);
} }
}; };
requestTouchid(function(err) { requestTouchid(function(err) {
if (err) { if (err) {
@ -1159,6 +1165,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.setFromUri = function(uri) { this.setFromUri = function(uri) {
var self = this; var self = this;
function sanitizeUri(uri) { function sanitizeUri(uri) {
// Fixes when a region uses comma to separate decimals // Fixes when a region uses comma to separate decimals
var regex = /[\?\&]amount=(\d+([\,\.]\d+)?)/i; var regex = /[\?\&]amount=(\d+([\,\.]\d+)?)/i;
@ -1180,7 +1187,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
if (err) { if (err) {
return err; return err;
} }
}); });
} else { } else {
uri = sanitizeUri(uri); uri = sanitizeUri(uri);
@ -1302,37 +1309,13 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.setForm(null, amount, null, feeRate); this.setForm(null, amount, null, feeRate);
}; };
// TODO: showPopup alike
this.confirmDialog = function(msg, cb) {
if (isCordova) {
navigator.notification.confirm(
msg,
function(buttonIndex) {
if (buttonIndex == 1) {
$timeout(function() {
return cb(true);
}, 1);
} else {
return cb(false);
}
},
confirm_msg, [accept_msg, cancel_msg]
);
} else if (isChromeApp) {
// No feedback, alert/confirm not supported.
return cb(true);
} else {
return cb(confirm(msg));
}
};
this.sendAll = function(amount, feeStr, feeRate) { this.sendAll = function(amount, feeStr, feeRate) {
var self = this; var self = this;
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", { var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", {
fee: feeStr fee: feeStr
}); });
this.confirmDialog(msg, function(confirmed) { confirmDialog.show(msg, function(confirmed) {
if (confirmed) if (confirmed)
self._doSendAll(amount, feeRate); self._doSendAll(amount, feeRate);
}); });
@ -1345,5 +1328,4 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.setAddress(); this.setAddress();
this.setSendFormInputs(); this.setSendFormInputs();
} }
}); });