mirror of https://github.com/BTCPrivate/copay.git
Enable cache for bitpay card
This commit is contained in:
parent
da931600e2
commit
104209de5d
|
@ -3,9 +3,9 @@
|
||||||
<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 Card</ion-nav-title>
|
||||||
<ion-nav-buttons side="secondary">
|
<ion-nav-buttons side="secondary" ng-show="bitpayCard.bitpayCardAuthenticated">
|
||||||
<button class="button back-button">
|
<button class="button back-button" ui-sref="tabs.bitpayCard.preferences">
|
||||||
<i class="icon ion-ios-search-strong"></i>
|
<i class="icon ion-ios-gear-outline"></i>
|
||||||
</button>
|
</button>
|
||||||
</ion-nav-buttons>
|
</ion-nav-buttons>
|
||||||
</ion-nav-bar>
|
</ion-nav-bar>
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
<form
|
<form
|
||||||
ng-show="!bitpayCard.bitpayCardTwoFactorPending"
|
ng-show="!bitpayCard.bitpayCardTwoFactorPending"
|
||||||
name="authenticateForm"
|
name="authenticateForm"
|
||||||
ng-submit="bitpayCard.authenticate()"
|
ng-submit="bitpayCard.authenticate(email, password)"
|
||||||
novalidate>
|
novalidate>
|
||||||
|
|
||||||
<div class="card list">
|
<div class="card list">
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
<form
|
<form
|
||||||
ng-show="bitpayCard.bitpayCardTwoFactorPending"
|
ng-show="bitpayCard.bitpayCardTwoFactorPending"
|
||||||
name="authenticate2FAForm"
|
name="authenticate2FAForm"
|
||||||
ng-submit="bitpayCard.authenticate2FA()"
|
ng-submit="bitpayCard.authenticate2FA(twoFactorCode)"
|
||||||
novalidate>
|
novalidate>
|
||||||
|
|
||||||
<div class="list">
|
<div class="list">
|
||||||
|
@ -98,24 +98,22 @@
|
||||||
<i class="icon ion-ios-plus-empty"></i> {{'Add Funds'|translate}}
|
<i class="icon ion-ios-plus-empty"></i> {{'Add Funds'|translate}}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div ng-if="loadingHistory" class="m20t">
|
<div ng-if="loadingHistory" class="m10t">
|
||||||
<strong class="size-36">...</strong>
|
<strong class="size-36">...</strong>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="oh pr m20t text-gray size-12 text-center"
|
class="m10t text-center padding"
|
||||||
ng-show="!bitpayCard.bitpayCardTransactionHistory[0] &&
|
ng-show="!bitpayCard.bitpayCardTransactionHistory[0] &&
|
||||||
!bitpayCard.bitpayCardInvoiceHistory[0] && !loadingHistory">
|
!bitpayCard.bitpayCardInvoiceHistory[0] && (!loadingHistory || !bitpayCardCached)">
|
||||||
No transactions yet
|
<i class="icon ion-ios-arrow-thin-up size-24"></i>
|
||||||
|
<h1>Get started</h1>
|
||||||
|
<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 ng-show="loadingHistory" class="oh pr m20t text-gray text-center">
|
<div class="list" ng-if="bitpayCardCached">
|
||||||
<i class="icon ion-android-sync"></i>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="list" ng-show="!loadingHistory">
|
|
||||||
<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>
|
||||||
|
|
|
@ -83,7 +83,8 @@
|
||||||
<div class="bg icon-bitpay-card"></div>
|
<div class="bg icon-bitpay-card"></div>
|
||||||
</i>
|
</i>
|
||||||
<h2>BitPay Card</h2>
|
<h2>BitPay Card</h2>
|
||||||
<p translate>Add funds to get started</p>
|
<p ng-if="!bitpayCard" translate>Add funds to get started</p>
|
||||||
|
<span ng-if="bitpayCard">${{bitpayCard.balance}}</span>
|
||||||
<i class="icon nav-item-arrow-right"></i>
|
<i class="icon nav-item-arrow-right"></i>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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) {
|
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 self = this;
|
||||||
var wallet;
|
$scope.dateRange = 'last30Days';
|
||||||
|
$scope.network = bitpayCardService.getEnvironment();
|
||||||
|
|
||||||
$scope.$on('Wallet/Changed', function(event, w) {
|
bitpayCardService.getCacheData(function(err, data) {
|
||||||
if (lodash.isEmpty(w)) {
|
if (err || lodash.isEmpty(data)) return;
|
||||||
$log.debug('No wallet provided');
|
$scope.bitpayCardCached = true;
|
||||||
return;
|
self.bitpayCardTransactionHistory = data.transactions;
|
||||||
}
|
self.bitpayCardCurrentBalance = data.balance;
|
||||||
wallet = w;
|
|
||||||
$log.debug('Wallet changed: ' + w.name);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var processTransactions = function(invoices, history) {
|
var processTransactions = function(invoices, history) {
|
||||||
|
@ -89,6 +88,14 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
||||||
|
|
||||||
self.bitpayCardTransactionHistory = processTransactions(invoices, history.transactionList);
|
self.bitpayCardTransactionHistory = processTransactions(invoices, history.transactionList);
|
||||||
self.bitpayCardCurrentBalance = history.currentCardBalance;
|
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 = {
|
var data = {
|
||||||
emailAddress : $scope.email,
|
emailAddress : email,
|
||||||
hashedPassword : pbkdf2Service.pbkdf2Sync($scope.password, '..............', 200, 64).toString('hex')
|
hashedPassword : pbkdf2Service.pbkdf2Sync(password, '..............', 200, 64).toString('hex')
|
||||||
};
|
};
|
||||||
|
|
||||||
// POST /authenticate
|
// POST /authenticate
|
||||||
|
@ -123,10 +130,10 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.authenticate2FA = function() {
|
this.authenticate2FA = function(twoFactorCode) {
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
twoFactorCode : $scope.twoFactorCode
|
twoFactorCode : twoFactorCode
|
||||||
};
|
};
|
||||||
|
|
||||||
self.authenticating = true;
|
self.authenticating = true;
|
||||||
|
@ -167,20 +174,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.$on("$ionicView.beforeEnter", function(event, data){
|
$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();
|
self.update();
|
||||||
|
|
||||||
wallet = $scope.wallets[0];
|
|
||||||
|
|
||||||
if (wallet && wallet.credentials.n > 1)
|
|
||||||
self.isMultisigWallet = true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesBitpayCardController',
|
angular.module('copayApp.controllers').controller('preferencesBitpayCardController',
|
||||||
function($scope, $state, $timeout, bitpayCardService, popupService) {
|
function($scope, $state, $timeout, $ionicHistory, bitpayCardService, popupService) {
|
||||||
|
|
||||||
$scope.logout = function() {
|
$scope.logout = function() {
|
||||||
var title = 'Are you sure you would like to log out of your Bitpay Card account?';
|
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() {
|
var logout = function() {
|
||||||
bitpayCardService.logout(function() {
|
bitpayCardService.logout(function() {
|
||||||
|
$ionicHistory.removeBackView();
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$state.go('bitpayCard.main');
|
$state.go('tabs.home');
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('tabHomeController',
|
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;
|
var wallet;
|
||||||
$scope.externalServices = {};
|
$scope.externalServices = {};
|
||||||
$scope.bitpayCardEnabled = true; // TODO
|
$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.$on("$ionicView.enter", function(event, data) {
|
||||||
|
$scope.bitpayCard = null;
|
||||||
configService.whenAvailable(function() {
|
configService.whenAvailable(function() {
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
|
var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
|
||||||
|
@ -217,6 +225,8 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
$scope.bitpayCardEnabled = config.bitpayCard.enabled;
|
$scope.bitpayCardEnabled = config.bitpayCard.enabled;
|
||||||
$scope.nextStepEnabled = $scope.glideraEnabled || $scope.coinbaseEnabled || $scope.amazonEnabled || $scope.bitpayCardEnabled;
|
$scope.nextStepEnabled = $scope.glideraEnabled || $scope.coinbaseEnabled || $scope.amazonEnabled || $scope.bitpayCardEnabled;
|
||||||
$scope.recentTransactionsEnabled = config.recentTransactions.enabled;
|
$scope.recentTransactionsEnabled = config.recentTransactions.enabled;
|
||||||
|
|
||||||
|
if ($scope.bitpayCardEnabled) bitpayCardCache();
|
||||||
});
|
});
|
||||||
$scope.nextStep();
|
$scope.nextStep();
|
||||||
$scope.updateAllWallets();
|
$scope.updateAllWallets();
|
||||||
|
|
|
@ -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) {
|
root.logout = function(cb) {
|
||||||
_setCredentials();
|
_setCredentials();
|
||||||
|
root.removeCacheData(function() {});
|
||||||
storageService.removeBitpayCard(credentials.NETWORK, function(err) {
|
storageService.removeBitpayCard(credentials.NETWORK, function(err) {
|
||||||
$http(_getBitPay('/visa-api/logout')).then(function(data) {
|
$http(_getBitPay('/visa-api/logout')).then(function(data) {
|
||||||
$log.info('BitPay Logout: SUCCESS');
|
$log.info('BitPay Logout: SUCCESS');
|
||||||
|
|
|
@ -337,6 +337,18 @@ angular.module('copayApp.services')
|
||||||
storage.remove('bitpayCard-' + network, cb);
|
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.removeAllWalletData = function(walletId, cb) {
|
||||||
root.clearLastAddress(walletId, function(err) {
|
root.clearLastAddress(walletId, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
Loading…
Reference in New Issue