Removes cards. Fix history. New method getInvoiceHistory

This commit is contained in:
Gustavo Maximiliano Cortez 2016-10-07 15:51:15 -03:00
commit 63916402a3
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
7 changed files with 89 additions and 54 deletions

View file

@ -6,13 +6,13 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
$scope.dateRange = 'last30Days';
$scope.network = bitpayCardService.getEnvironment();
var getFromCache = function() {
var getFromCache = 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;
$scope.$apply();
return cb();
});
};
@ -53,7 +53,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
return;
}
self.bitpayCardTransactionHistory = history.transactionList;
self.bitpayCardTransactionHistory = history.txs;
self.bitpayCardCurrentBalance = history.currentCardBalance;
var cacheHistory = {
@ -102,8 +102,9 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
$state.go('tabs.home');
popupService.showAlert(null, msg);
} else {
getFromCache();
self.update();
getFromCache(function() {
self.update();
});
}
});

View file

@ -1,6 +1,17 @@
'use strict';
angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $state, $timeout, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService) {
var checkOtp = function(obj, cb) {
if (obj.otp) {
var msg = gettextCatalog.getString('Enter Two Factor for BitPay Cards');
popupService.showPrompt(null, msg, null, function(res) {
cb(res);
});
} else {
cb();
}
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
if (data.stateParams && data.stateParams.secret) {
@ -9,28 +20,31 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
email: data.stateParams.email,
otp: data.stateParams.otp
};
bitpayCardService.bitAuthPair(obj, function(err, data) {
if (err) {
popupService.showAlert(null, err);
return;
}
var title = gettextCatalog.getString('Add BitPay Cards?');
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');
popupService.showConfirm(title, msg, ok, cancel, function(res) {
if (res) {
// Set flag for nextStep
storageService.setNextStep('BitpayCard', true, function(err) {});
// Save data
bitpayCardService.setBitpayDebitCards(data, function(err) {
if (err) return;
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$state.go('tabs.home');
});
checkOtp(obj, function(otp) {
obj.otp = otp;
bitpayCardService.bitAuthPair(obj, function(err, data) {
if (err) {
popupService.showAlert(null, err);
return;
}
var title = gettextCatalog.getString('Add BitPay Cards?');
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');
popupService.showConfirm(title, msg, ok, cancel, function(res) {
if (res) {
// Set flag for nextStep
storageService.setNextStep('BitpayCard', true, function(err) {});
// Save data
bitpayCardService.setBitpayDebitCards(data, function(err) {
if (err) return;
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$state.go('tabs.home');
});
}
});
});
});
} else {

View file

@ -1,17 +1,17 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesBitpayCardController',
function($scope, $state, $timeout, $ionicHistory, bitpayCardService, popupService) {
function($scope, $state, $timeout, $ionicHistory, bitpayCardService, popupService, gettextCatalog) {
$scope.logout = function() {
var msg = 'Are you sure you would like to log out of your BitPay Card account?';
$scope.remove = function() {
var msg = gettextCatalog.getString('Are you sure you would like to remove your BitPay Card account from this device?');
popupService.showConfirm(null, msg, null, null, function(res) {
if (res) logout();
if (res) remove();
});
};
var logout = function() {
bitpayCardService.logout(function() {
var remove = function() {
bitpayCardService.remove(function() {
$ionicHistory.removeBackView();
$timeout(function() {
$state.go('tabs.home');
@ -19,4 +19,11 @@ angular.module('copayApp.controllers').controller('preferencesBitpayCardControll
});
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
bitpayCardService.getBitpayDebitCards(function(err, data) {
if (err) return;
$scope.bitpayCards = data.cards;
});
});
});