Removes cards. Fix history. New method getInvoiceHistory

This commit is contained in:
Gustavo Maximiliano Cortez 2016-10-07 15:51:15 -03:00
parent c14a3b0658
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.dateRange = 'last30Days';
$scope.network = bitpayCardService.getEnvironment(); $scope.network = bitpayCardService.getEnvironment();
var getFromCache = function() { var getFromCache = 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;
$scope.$apply(); return cb();
}); });
}; };
@ -53,7 +53,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
return; return;
} }
self.bitpayCardTransactionHistory = history.transactionList; self.bitpayCardTransactionHistory = history.txs;
self.bitpayCardCurrentBalance = history.currentCardBalance; self.bitpayCardCurrentBalance = history.currentCardBalance;
var cacheHistory = { var cacheHistory = {
@ -102,8 +102,9 @@ 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(); getFromCache(function() {
self.update(); self.update();
});
} }
}); });

View File

@ -1,6 +1,17 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $state, $timeout, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService) { 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) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
if (data.stateParams && data.stateParams.secret) { if (data.stateParams && data.stateParams.secret) {
@ -9,28 +20,31 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
email: data.stateParams.email, email: data.stateParams.email,
otp: data.stateParams.otp otp: data.stateParams.otp
}; };
bitpayCardService.bitAuthPair(obj, function(err, data) { checkOtp(obj, function(otp) {
if (err) { obj.otp = otp;
popupService.showAlert(null, err); bitpayCardService.bitAuthPair(obj, function(err, data) {
return; if (err) {
} popupService.showAlert(null, err);
var title = gettextCatalog.getString('Add BitPay Cards?'); return;
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');
});
} }
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 { } else {

View File

@ -1,17 +1,17 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('preferencesBitpayCardController', angular.module('copayApp.controllers').controller('preferencesBitpayCardController',
function($scope, $state, $timeout, $ionicHistory, bitpayCardService, popupService) { function($scope, $state, $timeout, $ionicHistory, bitpayCardService, popupService, gettextCatalog) {
$scope.logout = function() { $scope.remove = function() {
var msg = 'Are you sure you would like to log out of your BitPay Card account?'; 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) { popupService.showConfirm(null, msg, null, null, function(res) {
if (res) logout(); if (res) remove();
}); });
}; };
var logout = function() { var remove = function() {
bitpayCardService.logout(function() { bitpayCardService.remove(function() {
$ionicHistory.removeBackView(); $ionicHistory.removeBackView();
$timeout(function() { $timeout(function() {
$state.go('tabs.home'); $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;
});
});
}); });

View File

@ -887,6 +887,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
url: '/preferences', url: '/preferences',
views: { views: {
'tab-home@tabs': { 'tab-home@tabs': {
controller: 'preferencesBitpayCardController',
templateUrl: 'views/preferencesBitpayCard.html' templateUrl: 'views/preferencesBitpayCard.html'
} }
} }

View File

@ -194,15 +194,17 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
root.getHistory = function(cardId, params, cb) { root.getHistory = function(cardId, params, cb) {
params = params || {}; params = params || {};
var json = {}; var json = {};
// json = { json = {
// method: 'getInvoiceHistory' method: 'getInvoiceHistory',
// }; params: JSON.stringify(params)
};
root.getBitpayDebitCards(function(err, data) { root.getBitpayDebitCards(function(err, data) {
var card = lodash.find(data.cards, {id : cardId}); var card = lodash.find(data.cards, {id : cardId});
if (!card) return cb(_setError('No card available')); if (!card) return cb(_setError('No card available'));
// Get invoices // Get invoices
// $http(_postBitAuth('/api/v2/' + card.token, json)).then(function(data) { $http(_postBitAuth('/api/v2/' + card.token, json)).then(function(data) {
// var invoices = data.data.data; $log.info('BitPay Get Invoices: SUCCESS');
var invoices = data.data.data;
json = { json = {
method: 'getTransactionHistory', method: 'getTransactionHistory',
params: JSON.stringify(params) params: JSON.stringify(params)
@ -211,14 +213,14 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
$http(_postBitAuth('/api/v2/' + card.token, json)).then(function(data) { $http(_postBitAuth('/api/v2/' + card.token, json)).then(function(data) {
$log.info('BitPay Get Transactions: SUCCESS'); $log.info('BitPay Get Transactions: SUCCESS');
var history = data.data.data || data.data; var history = data.data.data || data.data;
// history['txs'] = _processTransactions(invoices, history.transactionList); history['txs'] = _processTransactions(invoices, history.transactionList);
return cb(null, history); return cb(null, history);
}, function(data) { }, function(data) {
return cb(_setError('BitPay Card Error: Get Transactions', data)); return cb(_setError('BitPay Card Error: Get Transactions', data));
}); });
// }, function(data) { }, function(data) {
// return cb(_setError('BitPay Card Error: Get Invoices', data)); return cb(_setError('BitPay Card Error: Get Invoices', data));
// }); });
}); });
}; };
@ -321,10 +323,13 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
}); });
}; };
root.logout = function(cb) { root.remove = function(cb) {
_setCredentials(); _setCredentials();
storageService.removeBitpayDebitCards(credentials.NETWORK, function(err) { storageService.removeBitpayDebitCards(credentials.NETWORK, function(err) {
$log.info('BitPay Logout: SUCCESS'); storageService.removeBitpayDebitCardsHistory(credentials.NETWORK, function(err) {
$log.info('BitPay Debit Cards Removed: SUCCESS');
return cb();
});
}); });
}; };

View File

@ -2,7 +2,7 @@
<ion-nav-bar class="bar-royal"> <ion-nav-bar class="bar-royal">
<ion-nav-back-button> <ion-nav-back-button>
</ion-nav-back-button> </ion-nav-back-button>
<ion-nav-title>BitPay Card</ion-nav-title> <ion-nav-title>BitPay Visa&reg; Card</ion-nav-title>
<ion-nav-buttons side="secondary"> <ion-nav-buttons side="secondary">
<button class="button back-button" ng-show="!error" ui-sref="tabs.bitpayCard.preferences"> <button class="button back-button" ng-show="!error" ui-sref="tabs.bitpayCard.preferences">
<i class="icon ion-ios-gear-outline"></i> <i class="icon ion-ios-gear-outline"></i>
@ -45,7 +45,7 @@
<h4>Your BitPay Card is ready. Add funds to your card to start using your card at stores and ATMs worldwide.</h4> <h4>Your BitPay Card is ready. Add funds to your card to start using your card at stores and ATMs worldwide.</h4>
</div> </div>
<div class="list" ng-show="bitpayCard.bitpayCardTransactionHistory[0]"> <div class="list" ng-if="bitpayCard.bitpayCardTransactionHistory[0] && !error" ng-init="cardTxs = bitpayCard.bitpayCardTransactionHistory">
<div class="item item-divider"> <div class="item item-divider">
<select class="select-style" ng-model="dateRange" ng-change="bitpayCard.update(dateRange)"> <select class="select-style" ng-model="dateRange" ng-change="bitpayCard.update(dateRange)">
<option value="last30Days">Recent Activity</option> <option value="last30Days">Recent Activity</option>
@ -54,7 +54,7 @@
</select> </select>
</div> </div>
<div <div
ng-repeat="tx in bitpayCard.bitpayCardTransactionHistory | orderBy: ['pending','-timestamp']" ng-repeat="tx in cardTxs | orderBy: ['pending','-timestamp']"
class="item row" class="item row"
ng-init="bitpayCard.getMerchantInfo(tx)"> ng-init="bitpayCard.getMerchantInfo(tx)">
<div class="col col-10" ng-init="icon = bitpayCard.getIconName(tx)"> <div class="col col-10" ng-init="icon = bitpayCard.getIconName(tx)">

View File

@ -2,14 +2,21 @@
<ion-nav-bar class="bar-royal"> <ion-nav-bar class="bar-royal">
<ion-nav-back-button> <ion-nav-back-button>
</ion-nav-back-button> </ion-nav-back-button>
<ion-nav-title>Preferences</ion-nav-title> <ion-nav-title>BitPay Visa&reg; Cards</ion-nav-title>
</ion-nav-bar> </ion-nav-bar>
<ion-content ng-controller="preferencesBitpayCardController"> <ion-content>
<ul class="list"> <div class="list">
<li class="item assertive" ng-click="logout()"> <div class="item item-divider" translate>
Log out Cards
</li> </div>
</ul> <div class="item" ng-repeat="card in bitpayCards">
xxxx-xxxx-xxxx-{{card.lastFourDigits}}
</div>
<div class="item item-divider"></div>
<div class="item assertive" ng-click="remove()">
Removes all data from this device
</div>
</div>
</ion-content> </ion-content>
</ion-view> </ion-view>