show pending update

This commit is contained in:
Matias Alejo Garcia 2015-08-11 17:45:57 -03:00
commit ba40323b7b
4 changed files with 41 additions and 121 deletions

View file

@ -91,6 +91,12 @@
ng-if="index.totalBalanceAlternative">
{{index.totalBalanceAlternative}} {{index.alternativeIsoCode}}
</div>
<div class="size-14"
ng-if="index.pendingAmount">
<span translate>Pending Confirmation</span>:
{{index.pendingAmountStr}}
</div>
</div>
</div>
@ -162,9 +168,9 @@
</div>
<div class="text-gray text-center size-12 p10t"
ng-show="index.lockedBalance && !index.updatingStatus">
ng-show="index.lockedBalanceSat && !index.updatingStatus">
<span translate>Total Locked Balance</span>:
<b>{{index.lockedBalance}} {{index.unitName}} </b>
<b>{{index.lockedBalanceStr}} </b>
<span> {{index.lockedBalanceAlternative}}
{{index.alternativeIsoCode}} </span>
</div>
@ -288,12 +294,12 @@
<h4 class="title m0">
<a class="right lh"
ng-if="index.feeToSendMaxStr && index.availableBalance > 0 && !home.blockUx && !home.lockAmount"
ng-if="index.feeToSendMaxStr && index.availableBalanceSat > 0 && !home.blockUx && !home.lockAmount"
ng-click="home.sendAll(index.availableMaxBalance, index.feeToSendMaxStr)"
translate> Send All
</a>
<div ng-show="!index.lockedBalance && index.availableBalanceStr">
<div ng-show="!index.lockedBalanceSat && index.availableBalanceStr">
<div class="size-10">
<span class="db text-bold">
<span translate>Available Balance</span>:
@ -301,7 +307,7 @@
</span>
</div>
</div>
<div ng-show="index.lockedBalance">
<div ng-show="index.lockedBalanceSat">
<div class="left">
<i class="fi-info size-24 m10r"></i>
</div>

View file

@ -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) {

View file

@ -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);
});
});

View file

@ -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;
});