Enable cache for bitpay card

This commit is contained in:
Gustavo Maximiliano Cortez 2016-09-28 21:09:41 -03:00
commit 104209de5d
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
7 changed files with 91 additions and 45 deletions

View file

@ -3,15 +3,14 @@
angular.module('copayApp.controllers').controller('bitpayCardController', function($scope, $timeout, $log, lodash, bitpayCardService, configService, profileService, walletService, ongoingProcess, pbkdf2Service, moment, popupService, gettextCatalog, bwcError) {
var self = this;
var wallet;
$scope.dateRange = 'last30Days';
$scope.network = bitpayCardService.getEnvironment();
$scope.$on('Wallet/Changed', function(event, w) {
if (lodash.isEmpty(w)) {
$log.debug('No wallet provided');
return;
}
wallet = w;
$log.debug('Wallet changed: ' + w.name);
bitpayCardService.getCacheData(function(err, data) {
if (err || lodash.isEmpty(data)) return;
$scope.bitpayCardCached = true;
self.bitpayCardTransactionHistory = data.transactions;
self.bitpayCardCurrentBalance = data.balance;
});
var processTransactions = function(invoices, history) {
@ -89,6 +88,14 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
self.bitpayCardTransactionHistory = processTransactions(invoices, history.transactionList);
self.bitpayCardCurrentBalance = history.currentCardBalance;
var cacheData = {
balance: self.bitpayCardCurrentBalance,
transactions: self.bitpayCardTransactionHistory
};
bitpayCardService.setCacheData(cacheData, function(err) {
if (err) $log.error(err);
});
});
});
}
@ -98,11 +105,11 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
});
};
this.authenticate = function() {
this.authenticate = function(email, password) {
var data = {
emailAddress : $scope.email,
hashedPassword : pbkdf2Service.pbkdf2Sync($scope.password, '..............', 200, 64).toString('hex')
emailAddress : email,
hashedPassword : pbkdf2Service.pbkdf2Sync(password, '..............', 200, 64).toString('hex')
};
// POST /authenticate
@ -123,10 +130,10 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
});
};
this.authenticate2FA = function() {
this.authenticate2FA = function(twoFactorCode) {
var data = {
twoFactorCode : $scope.twoFactorCode
twoFactorCode : twoFactorCode
};
self.authenticating = true;
@ -167,20 +174,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
};
$scope.$on("$ionicView.beforeEnter", function(event, data){
$scope.dateRange = 'last30Days';
$scope.network = bitpayCardService.getEnvironment();
$scope.wallets = profileService.getWallets({
network: $scope.network,
onlyComplete: true
});
self.update();
wallet = $scope.wallets[0];
if (wallet && wallet.credentials.n > 1)
self.isMultisigWallet = true;
});
});

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesBitpayCardController',
function($scope, $state, $timeout, bitpayCardService, popupService) {
function($scope, $state, $timeout, $ionicHistory, bitpayCardService, popupService) {
$scope.logout = function() {
var title = 'Are you sure you would like to log out of your Bitpay Card account?';
@ -12,8 +12,9 @@ angular.module('copayApp.controllers').controller('preferencesBitpayCardControll
var logout = function() {
bitpayCardService.logout(function() {
$ionicHistory.removeBackView();
$timeout(function() {
$state.go('bitpayCard.main');
$state.go('tabs.home');
}, 100);
});
};

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('tabHomeController',
function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, gettextCatalog, lodash, popupService, ongoingProcess, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, $window) {
function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, gettextCatalog, lodash, popupService, ongoingProcess, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, $window, bitpayCardService) {
var wallet;
$scope.externalServices = {};
$scope.bitpayCardEnabled = true; // TODO
@ -206,7 +206,15 @@ angular.module('copayApp.controllers').controller('tabHomeController',
});
});
var bitpayCardCache = function() {
bitpayCardService.getCacheData(function(err, data) {
if (err || lodash.isEmpty(data)) return;
$scope.bitpayCard = data;
});
};
$scope.$on("$ionicView.enter", function(event, data) {
$scope.bitpayCard = null;
configService.whenAvailable(function() {
var config = configService.getSync();
var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
@ -217,6 +225,8 @@ angular.module('copayApp.controllers').controller('tabHomeController',
$scope.bitpayCardEnabled = config.bitpayCard.enabled;
$scope.nextStepEnabled = $scope.glideraEnabled || $scope.coinbaseEnabled || $scope.amazonEnabled || $scope.bitpayCardEnabled;
$scope.recentTransactionsEnabled = config.recentTransactions.enabled;
if ($scope.bitpayCardEnabled) bitpayCardCache();
});
$scope.nextStep();
$scope.updateAllWallets();