diff --git a/src/js/controllers/bitpayCard.js b/src/js/controllers/bitpayCard.js
index 4479b8a3a..54a9c09a5 100644
--- a/src/js/controllers/bitpayCard.js
+++ b/src/js/controllers/bitpayCard.js
@@ -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;
});
});
diff --git a/src/js/controllers/preferencesBitpayCard.js b/src/js/controllers/preferencesBitpayCard.js
index 9e4c9da8a..2abf6a8c4 100644
--- a/src/js/controllers/preferencesBitpayCard.js
+++ b/src/js/controllers/preferencesBitpayCard.js
@@ -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);
});
};
diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js
index ae0f7cb3c..0dec2cc7f 100644
--- a/src/js/controllers/tab-home.js
+++ b/src/js/controllers/tab-home.js
@@ -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();
diff --git a/src/js/services/bitpayCardService.js b/src/js/services/bitpayCardService.js
index d01b1cf89..c49bc5ffa 100644
--- a/src/js/services/bitpayCardService.js
+++ b/src/js/services/bitpayCardService.js
@@ -187,8 +187,38 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
});
};
+ root.getCacheData = function(cb) {
+ _setCredentials();
+ storageService.getBitpayCardCache(credentials.NETWORK, function(err, data) {
+ if (err) return cb(err);
+ if (lodash.isString(data)) {
+ data = JSON.parse(data);
+ }
+ data = data || {};
+ return cb(null, data);
+ });
+ };
+
+ root.setCacheData = function(data, cb) {
+ _setCredentials();
+ data = JSON.stringify(data);
+ storageService.setBitpayCardCache(credentials.NETWORK, data, function(err) {
+ if (err) return cb(err);
+ return cb();
+ });
+ };
+
+ root.removeCacheData = function(cb) {
+ _setCredentials();
+ storageService.removeBitpayCardCache(credentials.NETWORK, function(err) {
+ if (err) return cb(err);
+ return cb();
+ });
+ };
+
root.logout = function(cb) {
_setCredentials();
+ root.removeCacheData(function() {});
storageService.removeBitpayCard(credentials.NETWORK, function(err) {
$http(_getBitPay('/visa-api/logout')).then(function(data) {
$log.info('BitPay Logout: SUCCESS');
diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js
index a1daeb36e..3e07547ac 100644
--- a/src/js/services/storageService.js
+++ b/src/js/services/storageService.js
@@ -337,6 +337,18 @@ angular.module('copayApp.services')
storage.remove('bitpayCard-' + network, cb);
};
+ root.setBitpayCardCache = function(network, data, cb) {
+ storage.set('bitpayCardCache-' + network, data, cb);
+ };
+
+ root.getBitpayCardCache = function(network, cb) {
+ storage.get('bitpayCardCache-' + network, cb);
+ };
+
+ root.removeBitpayCardCache = function(network, cb) {
+ storage.remove('bitpayCardCache-' + network, cb);
+ };
+
root.removeAllWalletData = function(walletId, cb) {
root.clearLastAddress(walletId, function(err) {
if (err) return cb(err);