From ba40323b7b1402392cfc84e50842e28cf9b476d9 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 11 Aug 2015 17:45:57 -0300 Subject: [PATCH] show pending update --- public/views/walletHome.html | 16 ++++-- src/js/controllers/index.js | 51 +++++++++-------- src/js/controllers/preferences.js | 3 +- src/js/services/balanceService.js | 92 ------------------------------- 4 files changed, 41 insertions(+), 121 deletions(-) delete mode 100644 src/js/services/balanceService.js diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 57f28cd22..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 @@
-
+
diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 6559dbd7f..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; @@ -279,7 +285,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r $log.debug('Wallet Status:', walletStatus); self.setPendingTxps(walletStatus.pendingTxps); self.setFeesOpts(); - self.setSpendUnconfirmed(); // Status Shortcuts self.walletName = walletStatus.wallet.name; @@ -322,9 +327,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r var feeToSendMaxSat = parseInt(((self.totalBytesToSendMax * feePerKb ) / 1000.).toFixed(0)); self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit); self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName; - -console.log('[index.js.595]', self.currentFeeLevel, feePerKb, self.totalBytesToSendMax, feeToSendMaxSat, self.feeToSendMaxStr, "AVAIL", self.availableBalanceSat,self.availableMaxBalance); //TODO - } else { self.feeToSendMaxStr = null; } @@ -578,35 +580,39 @@ console.log('[index.js.595]', self.currentFeeLevel, feePerKb, self.totalBytesToS 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); - //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 @@ -619,8 +625,8 @@ console.log('[index.js.595]', self.currentFeeLevel, feePerKb, self.totalBytesToS 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); @@ -884,6 +890,7 @@ console.log('[index.js.595]', self.currentFeeLevel, feePerKb, self.totalBytesToS $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/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; - });