From 24c2d735cc2f91ac351b9437012b0ba8a6a68a90 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 31 Jan 2017 09:30:27 -0300 Subject: [PATCH] bitpay card integration in home. Cache TODO --- src/js/controllers/tab-home.js | 29 +++++-------------------- src/js/services/bitpayCardService.js | 28 +++++++++++++++++++++--- www/views/includes/bitpayCardsCard.html | 21 ++++++++++++++++++ www/views/tab-home.html | 22 +------------------ 4 files changed, 52 insertions(+), 48 deletions(-) create mode 100644 www/views/includes/bitpayCardsCard.html diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 329d1c7fd..40a3ba6fc 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, $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 listeners = []; var notifications = []; @@ -98,6 +98,10 @@ angular.module('copayApp.controllers').controller('tabHomeController', $scope.buyAndSellItems = buyAndSellService.getLinked(); $scope.homeIntegrations = homeIntegrationsService.get(); + bitpayCardService.get(function(err, cards) { + $scope.bitpayCardItems = cards; + }); + configService.whenAvailable(function() { var config = configService.getSync(); $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() { $timeout(function() { diff --git a/src/js/services/bitpayCardService.js b/src/js/services/bitpayCardService.js index 08fbe8a77..b63eb7bac 100644 --- a/src/js/services/bitpayCardService.js +++ b/src/js/services/bitpayCardService.js @@ -60,8 +60,8 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log, n.eid = x.eid; n.id = x.id; - n.lastFourDigits = x.lastFourDigits; - n.token = x.token; + n.lastFourDigits = x.lastFourDigits; + n.token = x.token; cards.push(n); }); @@ -188,7 +188,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log, // storageService.setBitpayDebitCardHistory(cardId, data, cb); // }; // - + root.remove = function(cardId, cb) { storageService.removeBitpayDebitCard(bitpayService.getEnvironment().network, cardId, function(err) { if (err) { @@ -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 */ diff --git a/www/views/includes/bitpayCardsCard.html b/www/views/includes/bitpayCardsCard.html new file mode 100644 index 000000000..89787d080 --- /dev/null +++ b/www/views/includes/bitpayCardsCard.html @@ -0,0 +1,21 @@ + +
+
+ Cards + +
+
+ + +
+
+ BitPay Visa® Card ({{card.lastFourDigits}}) +

{{card.balance ? '$' + card.balance : 'Add funds to get started'|translate}}

+ +
+
+
+ + diff --git a/www/views/tab-home.html b/www/views/tab-home.html index 82fdb4d6a..c84614a10 100644 --- a/www/views/tab-home.html +++ b/www/views/tab-home.html @@ -95,27 +95,7 @@ - -
-
- Cards - -
-
- - -
-
- BitPay Visa® Card ({{card.lastFourDigits}}) -

{{cardsHistory[card.id].balance ? '$' + cardsHistory[card.id].balance : 'Add funds to get started'|translate}}

- -
-
-
- - +