fix selection of cards at .get

This commit is contained in:
Matias Alejo Garcia 2017-02-01 11:42:18 -03:00
commit 96764917c7
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
2 changed files with 16 additions and 12 deletions

View file

@ -143,6 +143,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
$state.go('tabs.home'); $state.go('tabs.home');
} }
bitpayCardService.get({ bitpayCardService.get({
cardId: $scope.cardId, cardId: $scope.cardId,
noRefresh: true, noRefresh: true,

View file

@ -176,18 +176,18 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
}; };
root.getLastKnownBalance = function(cardId, cb) { root.getLastKnownBalance = function(cardId, cb) {
storageService.getBalanceCache(cardId, cb); storageService.getBalanceCache(cardId, cb);
}; };
root.addLastKnownBalance = function(card, cb) { root.addLastKnownBalance = function(card, cb) {
var now = Math.floor(Date.now()/1000); var now = Math.floor(Date.now() / 1000);
var showRange = 600 ; // 10min; var showRange = 600; // 10min;
root.getLastKnownBalance(card.eid, function(err, data){ root.getLastKnownBalance(card.eid, function(err, data) {
if (data) { if (data) {
data = JSON.parse(data); data = JSON.parse(data);
card.balance = data.balance; card.balance = data.balance;
card.updatedOn = ( data.updatedOn < now - showRange) ? data.updatedOn : null; card.updatedOn = (data.updatedOn < now - showRange) ? data.updatedOn : null;
} }
return cb(); return cb();
}); });
@ -197,7 +197,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
storageService.setBalanceCache(cardId, { storageService.setBalanceCache(cardId, {
balance: balance, balance: balance,
updatedOn: Math.floor(Date.now()/1000), updatedOn: Math.floor(Date.now() / 1000),
}, cb); }, cb);
}; };
@ -232,15 +232,18 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
return cb(); return cb();
} }
// Async, no problem if (opts.cardId) {
lodash.each(cards, function(x){ cards = lodash.filter(cards, function(x) {
return opts.cardId == x.eid;
});
}
if (opts.cardId) { // Async, no problem
if (opts.cardId != x.eid) return; lodash.each(cards, function(x) {
}
root.addLastKnownBalance(x, function() {}); root.addLastKnownBalance(x, function() {});
// async refresh
if (!opts.noRefresh) { if (!opts.noRefresh) {
root.getHistory(x.id, {}, function(err, data) { root.getHistory(x.id, {}, function(err, data) {
if (err) return; if (err) return;