From 13d85c193d4f0967160166f69c7da7ad097c390f Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Sun, 16 Oct 2016 20:00:38 -0300 Subject: [PATCH 1/3] Fix flashing get started message --- src/js/controllers/bitpayCard.js | 2 ++ www/views/bitpayCard.html | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/js/controllers/bitpayCard.js b/src/js/controllers/bitpayCard.js index ef5364b0b..c3f6f4c63 100644 --- a/src/js/controllers/bitpayCard.js +++ b/src/js/controllers/bitpayCard.js @@ -7,7 +7,9 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi $scope.network = bitpayCardService.getEnvironment(); var getFromCache = function(cb) { + $scope.loadingCache = true; bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) { + $scope.loadingCache = false; if (err || lodash.isEmpty(data)) return cb(); $scope.historyCached = true; self.bitpayCardTransactionHistory = data.transactions; diff --git a/www/views/bitpayCard.html b/www/views/bitpayCard.html index 13954307e..5bdd29640 100644 --- a/www/views/bitpayCard.html +++ b/www/views/bitpayCard.html @@ -40,7 +40,7 @@
+ ng-if="!loadingCache && !loadingHistory && !bitpayCard.bitpayCardTransactionHistory[0] && !error">

Get started

Your BitPay Card is ready. Add funds to your card to start using your card at stores and ATMs worldwide.

@@ -74,11 +74,11 @@ {{tx.desc}}
--> -
+
-
+
+ class="m10t text-center padding ng-hide" + ng-show="bitpayCard.getStarted">

Get started

Your BitPay Card is ready. Add funds to your card to start using your card at stores and ATMs worldwide.

-
-
- -
-
+ +
@@ -78,14 +81,14 @@
-
+
{{tx.amount | currency:'$':2 }}
- + Pending
diff --git a/www/views/tab-home.html b/www/views/tab-home.html index 2229336dc..7869989d7 100644 --- a/www/views/tab-home.html +++ b/www/views/tab-home.html @@ -109,7 +109,7 @@

BitPay Visa® Card

-

Add your cards

+

Add your card

From 031268de9c1f473516804e11fa3e067f0bbb7d30 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Mon, 17 Oct 2016 10:01:51 -0300 Subject: [PATCH 3/3] Ref callbacks --- src/js/controllers/bitpayCard.js | 70 +++++++++++++++++--------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/src/js/controllers/bitpayCard.js b/src/js/controllers/bitpayCard.js index 728b5711c..9f0e15c74 100644 --- a/src/js/controllers/bitpayCard.js +++ b/src/js/controllers/bitpayCard.js @@ -6,12 +6,13 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi $scope.dateRange = { value: 'last30Days'}; $scope.network = bitpayCardService.getEnvironment(); - var getFromCache = function() { + var updateHistoryFromCache = function(cb) { bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) { - if (err || lodash.isEmpty(data)) return; + if (err || lodash.isEmpty(data)) return cb(); $scope.historyCached = true; self.bitpayCardTransactionHistory = data.transactions; self.bitpayCardCurrentBalance = data.balance; + return cb(); }); }; @@ -40,11 +41,14 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi }; }; - var setGetStarted = function() { - var dateRange = setDateRange('all'); - bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) { - if (lodash.isEmpty(history.transactionList)) self.getStarted = true; - }); + var setGetStarted = function(history, cb) { + if (lodash.isEmpty(history.transactionList)) { + var dateRange = setDateRange('all'); + bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) { + if (lodash.isEmpty(history.transactionList)) return cb(true); + return cb(false); + }); + } else return cb(false); }; this.update = function() { @@ -60,30 +64,32 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi return; } - if (lodash.isEmpty(history.transactionList)) setGetStarted(); + setGetStarted(history, function(getStarted) { + self.getStarted = getStarted; - var txs = lodash.clone(history.txs); - for (var i = 0; i < txs.length; i++) { - txs[i] = _getMerchantInfo(txs[i]); - txs[i].icon = _getIconName(txs[i]); - txs[i].desc = _processDescription(txs[i]); - } - self.bitpayCardTransactionHistory = txs; - self.bitpayCardCurrentBalance = history.currentCardBalance; + var txs = lodash.clone(history.txs); + for (var i = 0; i < txs.length; i++) { + txs[i] = _getMerchantInfo(txs[i]); + txs[i].icon = _getIconName(txs[i]); + txs[i].desc = _processDescription(txs[i]); + } + self.bitpayCardTransactionHistory = txs; + self.bitpayCardCurrentBalance = history.currentCardBalance; - if ($scope.dateRange.value == 'last30Days') { - $log.debug('BitPay Card: store cache history'); - var cacheHistory = { - balance: history.currentCardBalance, - transactions: history.txs - }; - bitpayCardService.setBitpayDebitCardsHistory($scope.cardId, cacheHistory, {}, function(err) { - if (err) $log.error(err); - $scope.historyCached = true; + if ($scope.dateRange.value == 'last30Days') { + $log.debug('BitPay Card: store cache history'); + var cacheHistory = { + balance: history.currentCardBalance, + transactions: history.txs + }; + bitpayCardService.setBitpayDebitCardsHistory($scope.cardId, cacheHistory, {}, function(err) { + if (err) $log.error(err); + $scope.historyCached = true; + }); + } + $timeout(function() { + $scope.$apply(); }); - } - $timeout(function() { - $scope.$apply(); }); }); }; @@ -121,13 +127,11 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi $state.go('tabs.home'); popupService.showAlert(null, msg); } else { - getFromCache(); + updateHistoryFromCache(function() { + self.update(); + }); } }); - $scope.$on("$ionicView.afterEnter", function(event, data) { - self.update(); - }); - });