Merge pull request #488 from cmgustavo/bug/bitpay-card-flash-get-started

Bug/bitpay card Get Started message
This commit is contained in:
Matias Alejo Garcia 2016-10-17 11:09:53 -03:00 committed by GitHub
commit b48438be8c
5 changed files with 59 additions and 41 deletions

View file

@ -6,7 +6,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
$scope.dateRange = { value: 'last30Days'};
$scope.network = bitpayCardService.getEnvironment();
var getFromCache = function(cb) {
var updateHistoryFromCache = function(cb) {
bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) {
if (err || lodash.isEmpty(data)) return cb();
$scope.historyCached = true;
@ -41,40 +41,55 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
};
};
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)) return cb(true);
return cb(false);
});
} else return cb(false);
};
this.update = function() {
var dateRange = setDateRange($scope.dateRange.value);
$scope.loadingHistory = true;
bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) {
$scope.loadingHistory = false;
if (err) {
$log.error(err);
$scope.error = gettextCatalog.getString('Could not get transactions');
return;
}
var txs = lodash.clone(history.txs);
for (var i = 0; i < txs.length; i++) {
txs[i] = _getMerchantInfo(txs[i]);
txs[i].icon = _getIconName(txs[i]);
txs[i].desc = _processDescription(txs[i]);
}
self.bitpayCardTransactionHistory = txs;
self.bitpayCardCurrentBalance = history.currentCardBalance;
setGetStarted(history, function(getStarted) {
self.getStarted = getStarted;
if ($scope.dateRange.value == 'last30Days') {
$log.debug('BitPay Card: store cache history');
var cacheHistory = {
balance: history.currentCardBalance,
transactions: history.txs
};
bitpayCardService.setBitpayDebitCardsHistory($scope.cardId, cacheHistory, {}, function(err) {
if (err) $log.error(err);
$scope.historyCached = true;
var txs = lodash.clone(history.txs);
for (var i = 0; i < txs.length; i++) {
txs[i] = _getMerchantInfo(txs[i]);
txs[i].icon = _getIconName(txs[i]);
txs[i].desc = _processDescription(txs[i]);
}
self.bitpayCardTransactionHistory = txs;
self.bitpayCardCurrentBalance = history.currentCardBalance;
if ($scope.dateRange.value == 'last30Days') {
$log.debug('BitPay Card: store cache history');
var cacheHistory = {
balance: history.currentCardBalance,
transactions: history.txs
};
bitpayCardService.setBitpayDebitCardsHistory($scope.cardId, cacheHistory, {}, function(err) {
if (err) $log.error(err);
$scope.historyCached = true;
});
}
$timeout(function() {
$scope.$apply();
});
}
$timeout(function() {
$scope.$apply();
});
});
};
@ -112,7 +127,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
$state.go('tabs.home');
popupService.showAlert(null, msg);
} else {
getFromCache(function() {
updateHistoryFromCache(function() {
self.update();
});
}

View file

@ -3,7 +3,7 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
var checkOtp = function(obj, cb) {
if (obj.otp) {
var msg = gettextCatalog.getString('Enter Two Factor for BitPay Cards');
var msg = gettextCatalog.getString('Enter Two Factor for BitPay Card');
popupService.showPrompt(null, msg, null, function(res) {
cb(res);
});
@ -27,7 +27,7 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
popupService.showAlert(null, err);
return;
}
var title = gettextCatalog.getString('Add BitPay Cards?');
var title = gettextCatalog.getString('Add BitPay Card?');
var msg = gettextCatalog.getString('Would you like to add this account ({{email}}) to your wallet?', {email: obj.email});
var ok = gettextCatalog.getString('Add cards');
var cancel = gettextCatalog.getString('Go back');