mirror of https://github.com/BTCPrivate/copay.git
Ref callbacks
This commit is contained in:
parent
2e9b9d7443
commit
031268de9c
|
@ -6,12 +6,13 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
|||
$scope.dateRange = { value: 'last30Days'};
|
||||
$scope.network = bitpayCardService.getEnvironment();
|
||||
|
||||
var getFromCache = function() {
|
||||
var updateHistoryFromCache = function(cb) {
|
||||
bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) {
|
||||
if (err || lodash.isEmpty(data)) return;
|
||||
if (err || lodash.isEmpty(data)) return cb();
|
||||
$scope.historyCached = true;
|
||||
self.bitpayCardTransactionHistory = data.transactions;
|
||||
self.bitpayCardCurrentBalance = data.balance;
|
||||
return cb();
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -40,11 +41,14 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
|||
};
|
||||
};
|
||||
|
||||
var setGetStarted = function() {
|
||||
var setGetStarted = function(history, cb) {
|
||||
if (lodash.isEmpty(history.transactionList)) {
|
||||
var dateRange = setDateRange('all');
|
||||
bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) {
|
||||
if (lodash.isEmpty(history.transactionList)) self.getStarted = true;
|
||||
if (lodash.isEmpty(history.transactionList)) return cb(true);
|
||||
return cb(false);
|
||||
});
|
||||
} else return cb(false);
|
||||
};
|
||||
|
||||
this.update = function() {
|
||||
|
@ -60,7 +64,8 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
|||
return;
|
||||
}
|
||||
|
||||
if (lodash.isEmpty(history.transactionList)) setGetStarted();
|
||||
setGetStarted(history, function(getStarted) {
|
||||
self.getStarted = getStarted;
|
||||
|
||||
var txs = lodash.clone(history.txs);
|
||||
for (var i = 0; i < txs.length; i++) {
|
||||
|
@ -86,6 +91,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
|||
$scope.$apply();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var _getMerchantInfo = function(tx) {
|
||||
|
@ -121,13 +127,11 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
|||
$state.go('tabs.home');
|
||||
popupService.showAlert(null, msg);
|
||||
} else {
|
||||
getFromCache();
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.afterEnter", function(event, data) {
|
||||
updateHistoryFromCache(function() {
|
||||
self.update();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue