Ref callbacks
This commit is contained in:
parent
2e9b9d7443
commit
031268de9c
1 changed files with 39 additions and 35 deletions
|
|
@ -6,12 +6,13 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
||||||
$scope.dateRange = { value: 'last30Days'};
|
$scope.dateRange = { value: 'last30Days'};
|
||||||
$scope.network = bitpayCardService.getEnvironment();
|
$scope.network = bitpayCardService.getEnvironment();
|
||||||
|
|
||||||
var getFromCache = function() {
|
var updateHistoryFromCache = function(cb) {
|
||||||
bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) {
|
bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) {
|
||||||
if (err || lodash.isEmpty(data)) return;
|
if (err || lodash.isEmpty(data)) return cb();
|
||||||
$scope.historyCached = true;
|
$scope.historyCached = true;
|
||||||
self.bitpayCardTransactionHistory = data.transactions;
|
self.bitpayCardTransactionHistory = data.transactions;
|
||||||
self.bitpayCardCurrentBalance = data.balance;
|
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) {
|
||||||
var dateRange = setDateRange('all');
|
if (lodash.isEmpty(history.transactionList)) {
|
||||||
bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) {
|
var dateRange = setDateRange('all');
|
||||||
if (lodash.isEmpty(history.transactionList)) self.getStarted = true;
|
bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) {
|
||||||
});
|
if (lodash.isEmpty(history.transactionList)) return cb(true);
|
||||||
|
return cb(false);
|
||||||
|
});
|
||||||
|
} else return cb(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.update = function() {
|
this.update = function() {
|
||||||
|
|
@ -60,30 +64,32 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lodash.isEmpty(history.transactionList)) setGetStarted();
|
setGetStarted(history, function(getStarted) {
|
||||||
|
self.getStarted = getStarted;
|
||||||
|
|
||||||
var txs = lodash.clone(history.txs);
|
var txs = lodash.clone(history.txs);
|
||||||
for (var i = 0; i < txs.length; i++) {
|
for (var i = 0; i < txs.length; i++) {
|
||||||
txs[i] = _getMerchantInfo(txs[i]);
|
txs[i] = _getMerchantInfo(txs[i]);
|
||||||
txs[i].icon = _getIconName(txs[i]);
|
txs[i].icon = _getIconName(txs[i]);
|
||||||
txs[i].desc = _processDescription(txs[i]);
|
txs[i].desc = _processDescription(txs[i]);
|
||||||
}
|
}
|
||||||
self.bitpayCardTransactionHistory = txs;
|
self.bitpayCardTransactionHistory = txs;
|
||||||
self.bitpayCardCurrentBalance = history.currentCardBalance;
|
self.bitpayCardCurrentBalance = history.currentCardBalance;
|
||||||
|
|
||||||
if ($scope.dateRange.value == 'last30Days') {
|
if ($scope.dateRange.value == 'last30Days') {
|
||||||
$log.debug('BitPay Card: store cache history');
|
$log.debug('BitPay Card: store cache history');
|
||||||
var cacheHistory = {
|
var cacheHistory = {
|
||||||
balance: history.currentCardBalance,
|
balance: history.currentCardBalance,
|
||||||
transactions: history.txs
|
transactions: history.txs
|
||||||
};
|
};
|
||||||
bitpayCardService.setBitpayDebitCardsHistory($scope.cardId, cacheHistory, {}, function(err) {
|
bitpayCardService.setBitpayDebitCardsHistory($scope.cardId, cacheHistory, {}, function(err) {
|
||||||
if (err) $log.error(err);
|
if (err) $log.error(err);
|
||||||
$scope.historyCached = true;
|
$scope.historyCached = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
$timeout(function() {
|
|
||||||
$scope.$apply();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -121,13 +127,11 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
||||||
$state.go('tabs.home');
|
$state.go('tabs.home');
|
||||||
popupService.showAlert(null, msg);
|
popupService.showAlert(null, msg);
|
||||||
} else {
|
} else {
|
||||||
getFromCache();
|
updateHistoryFromCache(function() {
|
||||||
|
self.update();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.$on("$ionicView.afterEnter", function(event, data) {
|
|
||||||
self.update();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue