better history refresh logic

This commit is contained in:
Matias Alejo Garcia 2015-09-18 13:59:18 -03:00
commit fe14cfd3ed
2 changed files with 38 additions and 17 deletions

View file

@ -88,9 +88,13 @@
<span class="text-warning" ng-show="!btx.confirmations || btx.confirmations == 0" translate> <span class="text-warning" ng-show="!btx.confirmations || btx.confirmations == 0" translate>
Unconfirmed Unconfirmed
</span> </span>
<span class="label gray radius" ng-show="btx.confirmations>0"> <span class="label gray radius" ng-show="btx.confirmations>0 && !btx.safeConfirmed">
{{btx.confirmations}} {{btx.confirmations}}
</span> </span>
<span class="label gray radius" ng-show="btx.safeConfirmed">
{{btx.safeConfirmed}}
</span>
</span> </span>
</li> </li>
</ul> </ul>

View file

@ -439,6 +439,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
}; };
self.debouncedUpdateHistory = lodash.throttle(function() {
self.updateTxHistory();
}, 5000);
// This handles errors from BWS/index with are nomally // This handles errors from BWS/index with are nomally
// trigger from async events (like updates) // trigger from async events (like updates)
self.handleError = function(err) { self.handleError = function(err) {
@ -510,11 +515,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.txps = txps; self.txps = txps;
}; };
var SAFE_CONFIRMATIONS = 6;
self.setTxHistory = function(txs) { self.setTxHistory = function(txs) {
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
var now = Math.floor(Date.now() / 1000); var now = Math.floor(Date.now() / 1000);
var c = 0; var c = 0;
self.txHistoryPaging = txs[self.limitHistory] ? true : false; self.txHistoryPaging = txs[self.limitHistory] ? true : false;
self.hasUnsafeConfirmed = false;
lodash.each(txs, function(tx) { lodash.each(txs, function(tx) {
tx = txFormatService.processTx(tx); tx = txFormatService.processTx(tx);
@ -522,6 +530,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (tx.time > now) if (tx.time > now)
tx.time = now; tx.time = now;
if (tx.confirmations >= SAFE_CONFIRMATIONS) {
tx.safeConfirmed = SAFE_CONFIRMATIONS + '+';
} else {
tx.safeConfirmed = false;
self.hasUnsafeConfirmed = true;
}
if (c < self.limitHistory) { if (c < self.limitHistory) {
self.txHistory.push(tx); self.txHistory.push(tx);
c++; c++;
@ -849,11 +864,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.glideraLoading = null; self.glideraLoading = null;
if (err) { if (err) {
self.glideraError = err; self.glideraError = err;
} } else {
else {
self.glideraToken = accessToken; self.glideraToken = accessToken;
self.glideraPermissions = p; self.glideraPermissions = p;
self.updateGlidera({ fullUpdate: true}); self.updateGlidera({
fullUpdate: true
});
} }
}); });
} }
@ -999,10 +1015,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
trailing: true trailing: true
}); });
self.debouncedUpdateHistory = lodash.throttle(function() {
self.updateTxHistory();
}, 60000);
$rootScope.$on('Local/Resume', function(event) { $rootScope.$on('Local/Resume', function(event) {
$log.debug('### Resume event'); $log.debug('### Resume event');
self.debouncedUpdate(); self.debouncedUpdate();
@ -1041,13 +1053,18 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('NewBlock', function() { $rootScope.$on('NewBlock', function() {
if (self.pendingAmount) { if (self.pendingAmount) {
self.updateAll(); self.updateAll({
} walletStatus: null,
untilItChanges: null,
if (self.network == 'testnet') { triggerTxUpdate: true,
self.debouncedUpdateHistory(); });
} else { } else if (self.hasUnsafeConfirmed) {
self.updateTxHistory(); $log.debug('Wallet has transactions with few confirmations. Updating.')
if (self.network == 'testnet') {
self.debouncedUpdateHistory();
} else {
self.updateTxHistory();
}
} }
}); });