diff --git a/public/views/walletHome.html b/public/views/walletHome.html
index a9353d02c..02d459b87 100644
--- a/public/views/walletHome.html
+++ b/public/views/walletHome.html
@@ -91,6 +91,12 @@
ng-if="index.totalBalanceAlternative">
{{index.totalBalanceAlternative}} {{index.alternativeIsoCode}}
+
+ Pending Confirmation:
+ {{index.pendingAmountStr}}
+
+
@@ -162,9 +168,9 @@
+ ng-show="index.lockedBalanceSat && !index.updatingStatus">
Total Locked Balance:
- {{index.lockedBalance}} {{index.unitName}}
+ {{index.lockedBalanceStr}}
{{index.lockedBalanceAlternative}}
{{index.alternativeIsoCode}}
@@ -288,12 +294,12 @@
Send All
-
+
Available Balance:
@@ -301,7 +307,7 @@
-
+
@@ -431,7 +437,7 @@
Fee policy for this transaction
-
+ ng-click="home.setFee(fee.level)" class="line-b p20">
{{index.feeOpts[fee.level]|translate}}
diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js
index e8a820836..0963c7a7d 100644
--- a/src/js/controllers/index.js
+++ b/src/js/controllers/index.js
@@ -89,17 +89,23 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (!fc) return;
// Clean status
- self.lockedBalance = null;
+ self.totalBalanceSat = null;
+ self.lockedBalanceSat = null;
+ self.availableBalanceSat = null;
+
+ self.totalBalanceStr = null;
self.availableBalanceStr = null;
- self.totalBalanceStr = null;
self.lockedBalanceStr = null;
- self.totalBalanceStr = null;
+
self.alternativeBalanceAvailable = false;
self.totalBalanceAlternative = null;
+
self.notAuthorized = false;
self.txHistory = [];
self.txHistoryPaging = false;
self.pendingTxProposalsCountForUs = null;
+ self.setSpendUnconfirmed();
+
$timeout(function() {
self.hasProfile = true;
self.noFocusedWallet = false;
@@ -278,8 +284,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}
$log.debug('Wallet Status:', walletStatus);
self.setPendingTxps(walletStatus.pendingTxps);
- self.setFees();
- self.setSpendUnconfirmed();
+ self.setFeesOpts();
// Status Shortcuts
self.walletName = walletStatus.wallet.name;
@@ -311,17 +316,37 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.spendUnconfirmed = configService.getSync().wallet.spendUnconfirmed;
};
- self.setCurrentFeeLevel = function(level) {
- self.currentFeeLevel = level || configService.getSync().wallet.settings.feeLevel || 'priority';
+ self.setSendMax = function() {
+
+ // Set Send max
+ if (self.currentFeeLevel && self.totalBytesToSendMax) {
+ feeService.getCurrentFeeValue(self.currentFeeLevel, function(err, feePerKb) {
+
+ // KB to send max
+ if (self.totalBytesToSendMax) {
+ var feeToSendMaxSat = parseInt(((self.totalBytesToSendMax * feePerKb ) / 1000.).toFixed(0));
+ self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit);
+ self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName;
+ } else {
+ self.feeToSendMaxStr = null;
+ }
+ });
+ }
+
};
- self.setFees = function() {
+ self.setCurrentFeeLevel = function(level) {
+ self.currentFeeLevel = level || configService.getSync().wallet.settings.feeLevel || 'priority';
+ self.setSendMax();
+ };
+
+
+ self.setFeesOpts = function() {
var fc = profileService.focusedClient;
if (!fc) return;
$timeout(function() {
feeService.getFeeLevels(function(levels) {
self.feeLevels = levels;
- self.setCurrentFeeLevel();
$rootScope.$apply();
});
});
@@ -550,47 +575,46 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var config = configService.getSync().wallet.settings;
var COIN = 1e8;
+
// Address with Balance
self.balanceByAddress = balance.byAddress;
// SAT
- self.totalBalanceSat = balance.totalAmount;
- self.lockedBalanceSat = balance.lockedAmount;
- self.availableBalanceSat = self.totalBalanceSat - self.lockedBalanceSat;
+ if (self.spendUnconfirmed) {
+ self.totalBalanceSat = balance.totalAmount;
+ self.lockedBalanceSat = balance.lockedAmount;
+ self.availableBalanceSat = balance.availableAmount;
+ self.pendingAmount = null;
+ } else {
+ self.totalBalanceSat = balance.totalConfirmedAmount;
+ self.lockedBalanceSat = balance.lockedConfirmedAmount;
+ self.availableBalanceSat = balance.availableConfirmedAmount;
+ self.pendingAmount = balance.totalAmount - balance.totalConfirmedAmount;
+ }
// Selected unit
self.unitToSatoshi = config.unitToSatoshi;
self.satToUnit = 1 / self.unitToSatoshi;
self.unitName = config.unitName;
- self.totalBalance = strip(self.totalBalanceSat * self.satToUnit);
- self.lockedBalance = strip(self.lockedBalanceSat * self.satToUnit);
- self.availableBalance = strip(self.availableBalanceSat * self.satToUnit);
-
- // BTC
- self.totalBalanceBTC = strip(self.totalBalanceSat / COIN);
- self.lockedBalanceBTC = strip(self.lockedBalanceSat / COIN);
- self.availableBalanceBTC = strip(self.availableBalanceBTC / COIN);
-
- // KB to send max
- self.feePerKbSat = config.feeValue || 10000;
- if (balance.totalKbToSendMax) {
- var feeToSendMaxSat = balance.totalKbToSendMax * self.feePerKbSat;
-
- self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit);
- self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName;
- } else {
- self.feeToSendMaxStr = null;
- }
-
//STR
self.totalBalanceStr = profileService.formatAmount(self.totalBalanceSat) + ' ' + self.unitName;
self.lockedBalanceStr = profileService.formatAmount(self.lockedBalanceSat) + ' ' + self.unitName;
self.availableBalanceStr = profileService.formatAmount(self.availableBalanceSat) + ' ' + self.unitName;
+ if (self.pendingAmount) {
+ self.pendingAmountStr = profileService.formatAmount(self.pendingAmount) + ' ' + self.unitName;
+ } else {
+ self.pendingAmountStr = null;
+ }
+
self.alternativeName = config.alternativeName;
self.alternativeIsoCode = config.alternativeIsoCode;
+ // Other
+ self.totalBytesToSendMax = balance.totalBytesToSendMax;
+ self.setCurrentFeeLevel();
+
// Check address
addressService.isUsed(self.walletId, balance.byAddress, function(err, used) {
if (used) {
@@ -601,8 +625,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
rateService.whenAvailable(function() {
- var totalBalanceAlternative = rateService.toFiat(self.totalBalance * self.unitToSatoshi, self.alternativeIsoCode);
- var lockedBalanceAlternative = rateService.toFiat(self.lockedBalance * self.unitToSatoshi, self.alternativeIsoCode);
+ var totalBalanceAlternative = rateService.toFiat(self.totalBalanceSat, self.alternativeIsoCode);
+ var lockedBalanceAlternative = rateService.toFiat(self.lockedBalanceSat, self.alternativeIsoCode);
var alternativeConversionRate = rateService.toFiat(100000000, self.alternativeIsoCode);
self.totalBalanceAlternative = $filter('noFractionNumber')(totalBalanceAlternative, 2);
@@ -866,6 +890,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/SpendUnconfirmedUpdated', function(event) {
self.setSpendUnconfirmed();
+ self.updateAll();
});
$rootScope.$on('Local/FeeLevelUpdated', function(event, level) {
diff --git a/src/js/controllers/preferences.js b/src/js/controllers/preferences.js
index c562785bb..468b74841 100644
--- a/src/js/controllers/preferences.js
+++ b/src/js/controllers/preferences.js
@@ -21,9 +21,8 @@ angular.module('copayApp.controllers').controller('preferencesController',
spendUnconfirmed: newVal
}
};
- $rootScope.$emit('Local/SpendUnconfirmedUpdated');
-
configService.set(opts, function(err) {
+ $rootScope.$emit('Local/SpendUnconfirmedUpdated');
if (err) $log.debug(err);
});
});
diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js
index ec96ba394..ff1d59536 100644
--- a/src/js/controllers/walletHome.js
+++ b/src/js/controllers/walletHome.js
@@ -714,6 +714,10 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
};
};
+ this.setFee = function(level) {
+ this.currentSendFeeLevel = level;
+ };
+
this.submitForm = function() {
var fc = profileService.focusedClient;
var unitToSat = this.unitToSatoshi;
@@ -748,6 +752,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
feeService.getCurrentFeeValue(self.currentSendFeeLevel, function(err, feePerKb) {
if (err) $log.debug(err);
+console.log('[walletHome.js.757:amount:]',amount, feePerKb); //TODO
fc.sendTxProposal({
toAddress: address,
amount: amount,
diff --git a/src/js/services/balanceService.js b/src/js/services/balanceService.js
deleted file mode 100644
index 432a2e10b..000000000
--- a/src/js/services/balanceService.js
+++ /dev/null
@@ -1,92 +0,0 @@
-'use strict';
-
-angular.module('copayApp.services')
- .factory('balanceService', function($rootScope, $filter, $timeout, bwcService) {
- var root = {};
- var _balanceCache = {};
- root.clearBalanceCache = function(w) {
- w.clearUnspentCache();
- delete _balanceCache[w.getId()];
- };
-
- root._fetchBalance = function(w, cb) {
- cb = cb || function() {};
- var satToUnit = 1 / w.settings.unitToSatoshi;
- var COIN = bwcService.Bitcore.util.COIN;
- w.getBalance(function(err, balanceSat, balanceByAddrSat, safeBalanceSat, safeUnspentCount) {
- if (err) return cb(err);
-
- var r = {};
- r.totalBalance = $filter('noFractionNumber')(balanceSat * satToUnit);
- r.totalBalanceBTC = (balanceSat / COIN);
- var availableBalanceNr = safeBalanceSat * satToUnit;
- r.availableBalance = $filter('noFractionNumber')(safeBalanceSat * satToUnit);
- r.availableBalanceBTC = (safeBalanceSat / COIN);
- r.safeUnspentCount = safeUnspentCount;
-
- var lockedBalance = (balanceSat - safeBalanceSat) * satToUnit;
- r.lockedBalance = lockedBalance ? $filter('noFractionNumber')(lockedBalance) : null;
- r.lockedBalanceBTC = (balanceSat - safeBalanceSat) / COIN;
-
-
- if (r.safeUnspentCount) {
- var estimatedFee = copay.Wallet.estimatedFee(r.safeUnspentCount);
- r.topAmount = (((availableBalanceNr * w.settings.unitToSatoshi).toFixed(0) - estimatedFee) / w.settings.unitToSatoshi);
- }
-
- var balanceByAddr = {};
- for (var ii in balanceByAddrSat) {
- balanceByAddr[ii] = balanceByAddrSat[ii] * satToUnit;
- }
- r.balanceByAddr = balanceByAddr;
-
- r.totalBalanceAlternative = $filter('noFractionNumber')(totalBalanceAlternative, 2);
- r.lockedBalanceAlternative = $filter('noFractionNumber')(lockedBalanceAlternative, 2);
- r.alternativeConversionRate = $filter('noFractionNumber')(alternativeConversionRate, 2);
-
- r.alternativeBalanceAvailable = true;
- r.alternativeIsoCode = w.settings.alternativeIsoCode;
-
- r.updatingBalance = false;
-
- return cb(null, r)
- });
- };
-
- root.update = function(w, cb, isFocused) {
- w = w || $rootScope.wallet;
- if (!w || !w.isComplete()) return;
-
- copay.logger.debug('Updating balance of:', w.getName(), isFocused);
- var wid = w.getId();
-
-
- // cache available? Set the cached values until we updated them
- if (_balanceCache[wid]) {
- w.balanceInfo = _balanceCache[wid];
- } else {
- if (isFocused)
- $rootScope.updatingBalance = true;
- }
-
- w.balanceInfo = w.balanceInfo || {};
- w.balanceInfo.updating = true;
-
- root._fetchBalance(w, function(err, res) {
- if (err) throw err;
- w.balanceInfo = _balanceCache[wid] = res;
- w.balanceInfo.updating = false;
-
- if (isFocused) {
- $rootScope.updatingBalance = false;
- }
- // we alwalys calltimeout because if balance is cached, we are still on the same
- // execution path
- if (cb) $timeout(function() {
- return cb();
- }, 1);
- });
- };
-
- return root;
- });
diff --git a/src/js/services/feeService.js b/src/js/services/feeService.js
index 3b7f810ce..1924d0ac8 100644
--- a/src/js/services/feeService.js
+++ b/src/js/services/feeService.js
@@ -22,7 +22,7 @@ angular.module('copayApp.services').factory('feeService', function($log, profile
}
else {
fee = lodash.find(levels, { level: feeLevel }).feePerKB;
- $log.debug('Dynamic fee for ' + feeLevel + ': ' + fee);
+ $log.debug('Dynamic fee for:' + feeLevel + ': ' + fee + ' SAT');
return cb(null, fee);
}
});