bitpay card integration in home. Cache TODO

This commit is contained in:
Matias Alejo Garcia 2017-01-31 09:30:27 -03:00
commit 24c2d735cc
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
4 changed files with 52 additions and 48 deletions

View file

@ -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, $window, gettextCatalog, lodash, popupService, ongoingProcess, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, bitpayCardService, startupService, addressbookService, feedbackService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService) { function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, startupService, addressbookService, feedbackService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService) {
var wallet; var wallet;
var listeners = []; var listeners = [];
var notifications = []; var notifications = [];
@ -98,6 +98,10 @@ angular.module('copayApp.controllers').controller('tabHomeController',
$scope.buyAndSellItems = buyAndSellService.getLinked(); $scope.buyAndSellItems = buyAndSellService.getLinked();
$scope.homeIntegrations = homeIntegrationsService.get(); $scope.homeIntegrations = homeIntegrationsService.get();
bitpayCardService.get(function(err, cards) {
$scope.bitpayCardItems = cards;
});
configService.whenAvailable(function() { configService.whenAvailable(function() {
var config = configService.getSync(); var config = configService.getSync();
$scope.recentTransactionsEnabled = config.recentTransactions.enabled; $scope.recentTransactionsEnabled = config.recentTransactions.enabled;
@ -252,29 +256,6 @@ angular.module('copayApp.controllers').controller('tabHomeController',
}); });
}; };
var bitpayCardCache = function() {
bitpayCardService.getCards(function(err, data) {
if (err) return;
if (lodash.isEmpty(data)) {
$scope.bitpayCards = null;
return;
}
$scope.bitpayCards = data;
$timeout(function() {
$scope.$digest();
}, 100);
});
// TODO
// bitpayCardService.getCardsHistoryCache(function(err, data) {
// if (err) return;
// if (lodash.isEmpty(data)) {
// $scope.cardsHistory = null;
// return;
// }
// $scope.cardsHistory = data;
// });
};
$scope.onRefresh = function() { $scope.onRefresh = function() {
$timeout(function() { $timeout(function() {

View file

@ -60,8 +60,8 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
n.eid = x.eid; n.eid = x.eid;
n.id = x.id; n.id = x.id;
n.lastFourDigits = x.lastFourDigits; n.lastFourDigits = x.lastFourDigits;
n.token = x.token; n.token = x.token;
cards.push(n); cards.push(n);
}); });
@ -210,6 +210,28 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
}); });
}; };
root.get = function(cb) {
root.getCards(function(err, cards) {
if (err) return;
if (lodash.isEmpty(cards)) {
return cb();
}
// TODO
// bitpayCardService.getCardsHistoryCache(function(err, data) {
// if (err) return;
// if (lodash.isEmpty(data)) {
// $scope.cardsHistory = null;
// return;
// }
// $scope.cardsHistory = data;
// });
return cb(null, cards);
});
};
/* /*
* CONSTANTS * CONSTANTS
*/ */

View file

@ -0,0 +1,21 @@
<div class="list card">
<div class="item item-icon-right item-heading">
<span translate>Cards</span>
<a ui-sref="tabs.bitpayCardIntro"><i class="icon ion-ios-plus-empty list-add-button"></i></a>
</div>
<div>
<a ng-repeat="card in bitpayCardItems"
ui-sref="tabs.bitpayCard({id:card.id})"
class="item item-sub item-icon-left item-big-icon-left item-icon-right">
<i class="icon big-icon-svg">
<div class="bg icon-bitpay-card"></div>
</i>
<span>BitPay Visa&reg; Card ({{card.lastFourDigits}})</span>
<p>{{card.balance ? '$' + card.balance : 'Add funds to get started'|translate}}</p>
<i class="icon bp-arrow-right"></i>
</a>
</div>
</div>

View file

@ -95,27 +95,7 @@
</a> </a>
</div> </div>
</div> </div>
<div class="ng-hide" ng-show="wallets[0] && bitpayCardItems.length>0" ng-include="'views/includes/bitpayCardsCard.html'"></div>
<div class="list card" ng-if="bitpayCardEnabled && bitpayCards[0] && externalServices.BitpayCard">
<div class="item item-icon-right item-heading">
<span translate>Cards</span>
<a ui-sref="tabs.bitpayCardIntro"><i class="icon ion-ios-plus-empty list-add-button"></i></a>
</div>
<div>
<a ng-repeat="card in bitpayCards"
ui-sref="tabs.bitpayCard({id:card.id})"
class="item item-sub item-icon-left item-big-icon-left item-icon-right">
<i class="icon big-icon-svg">
<div class="bg icon-bitpay-card"></div>
</i>
<span>BitPay Visa&reg; Card ({{card.lastFourDigits}})</span>
<p>{{cardsHistory[card.id].balance ? '$' + cardsHistory[card.id].balance : 'Add funds to get started'|translate}}</p>
<i class="icon bp-arrow-right"></i>
</a>
</div>
</div>
<div class="ng-hide" ng-show="wallets[0] && buyAndSellItems.length>0" ng-include="'views/includes/buyAndSellCard.html'"></div> <div class="ng-hide" ng-show="wallets[0] && buyAndSellItems.length>0" ng-include="'views/includes/buyAndSellCard.html'"></div>
<div class="ng-hide" ng-show="homeIntegrations.length>0" ng-include="'views/includes/homeIntegrations.html'"></div> <div class="ng-hide" ng-show="homeIntegrations.length>0" ng-include="'views/includes/homeIntegrations.html'"></div>
<div class="ng-hide" ng-show="nextStepsItems.length>0" ng-include="'views/includes/nextSteps.html'"></div> <div class="ng-hide" ng-show="nextStepsItems.length>0" ng-include="'views/includes/nextSteps.html'"></div>