Merge pull request #3716 from cmgustavo/bug/send_all_fee

Bug/send all fee
This commit is contained in:
Gustavo Maximiliano Cortez 2016-01-05 17:21:45 -03:00
commit c70c8947ec
6 changed files with 153 additions and 112 deletions

View file

@ -371,14 +371,15 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
};
self.setSpendUnconfirmed = function() {
self.spendUnconfirmed = configService.getSync().wallet.spendUnconfirmed;
self.setSpendUnconfirmed = function(spendUnconfirmed) {
self.spendUnconfirmed = spendUnconfirmed || configService.getSync().wallet.spendUnconfirmed;
};
self.setSendMax = function() {
self.setFeeAndSendMax = function(cb) {
self.feeToSendMaxStr = null;
self.feeRateToSendMax = null;
self.availableMaxBalance = null;
self.currentFeePerKb = null;
// Set Send max
if (self.currentFeeLevel && self.totalBytesToSendMax) {
@ -386,12 +387,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
// KB to send max
var feeToSendMaxSat = parseInt(((self.totalBytesToSendMax * feePerKb) / 1000.).toFixed(0));
self.feeRateToSendMax = feePerKb;
self.currentFeePerKb = feePerKb;
if (self.availableBalanceSat > feeToSendMaxSat) {
self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit);
self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName;
}
if (cb) return cb(self.currentFeePerKb, self.availableMaxBalance, self.feeToSendMaxStr);
});
}
@ -399,7 +402,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setCurrentFeeLevel = function(level) {
self.currentFeeLevel = level || configService.getSync().wallet.settings.feeLevel || 'normal';
self.setSendMax();
self.setFeeAndSendMax();
};
@ -612,16 +615,18 @@ angular.module('copayApp.controllers').controller('indexController', function($r
// Address with Balance
self.balanceByAddress = balance.byAddress;
// SAT
// Spend unconfirmed funds
if (self.spendUnconfirmed) {
self.totalBalanceSat = balance.totalAmount;
self.lockedBalanceSat = balance.lockedAmount;
self.availableBalanceSat = balance.availableAmount;
self.totalBytesToSendMax = balance.totalBytesToSendMax;
self.pendingAmount = null;
} else {
self.totalBalanceSat = balance.totalConfirmedAmount;
self.lockedBalanceSat = balance.lockedConfirmedAmount;
self.availableBalanceSat = balance.availableConfirmedAmount;
self.totalBytesToSendMax = balance.totalBytesToSendConfirmedMax;
self.pendingAmount = balance.totalAmount - balance.totalConfirmedAmount;
}
@ -644,8 +649,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.alternativeName = config.alternativeName;
self.alternativeIsoCode = config.alternativeIsoCode;
// Other
self.totalBytesToSendMax = balance.totalBytesToSendMax;
// Set fee level and max value to send all
self.setCurrentFeeLevel();
// Check address
@ -1186,8 +1190,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
});
$rootScope.$on('Local/SpendUnconfirmedUpdated', function(event) {
self.setSpendUnconfirmed();
$rootScope.$on('Local/SpendUnconfirmedUpdated', function(event, spendUnconfirmed) {
self.setSpendUnconfirmed(spendUnconfirmed);
self.updateAll();
});
@ -1195,6 +1199,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setCurrentFeeLevel(level);
});
$rootScope.$on('Local/SetFeeSendMax', function(event, cb) {
self.setFeeAndSendMax(cb);
});
$rootScope.$on('Local/ProfileBound', function() {
storageService.getRemotePrefsStoredFlag(function(err, val) {
if (err || val) return;
@ -1450,4 +1458,5 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$apply();
});
});
});