From e73091ae469e29d5a3ce61c180a710b59621688f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Wed, 31 Aug 2016 11:49:28 -0300 Subject: [PATCH 1/3] hidden balance feature refactor --- public/views/tab-home.html | 5 ++++- public/views/walletDetails.html | 4 ++-- src/js/controllers/walletDetails.js | 11 +---------- src/js/services/profileService.js | 4 ++++ 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/public/views/tab-home.html b/public/views/tab-home.html index dad46a8b3..d74cebb31 100644 --- a/public/views/tab-home.html +++ b/public/views/tab-home.html @@ -50,9 +50,12 @@ Incomplete - + {{item.status.availableBalanceStr}} + + [Balance Hidden] + BitPay Card diff --git a/public/views/walletDetails.html b/public/views/walletDetails.html index c69b571a6..498be236f 100644 --- a/public/views/walletDetails.html +++ b/public/views/walletDetails.html @@ -44,7 +44,7 @@ -
+
{{status.totalBalanceStr}}
{{status.totalBalanceAlternative}} {{status.alternativeIsoCode}}
@@ -52,7 +52,7 @@
-
+
[Balance Hidden]
Tap and hold to show diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index 91222f9e3..ce4deae08 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -175,16 +175,8 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.updateTxHistory(cb); } - var hideBalance = function() { - storageService.getHideBalanceFlag(wallet.credentials.walletId, function(err, shouldHideBalance) { - if (err) $scope.shouldHideBalance = false; - else $scope.shouldHideBalance = (shouldHideBalance == 'true') ? true : false; - }); - } - $scope.hideToggle = function() { - $scope.shouldHideBalance = !$scope.shouldHideBalance; - storageService.setHideBalanceFlag(wallet.credentials.walletId, $scope.shouldHideBalance.toString(), function() {}); + profileService.setHideBalanceFlag(wallet.credentials.walletId); } var currentTxHistoryPage; @@ -204,7 +196,6 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.requiresMultipleSignatures = wallet.credentials.m > 1; $scope.newTx = false; - hideBalance(); $ionicNavBarDelegate.title(wallet.name); $scope.updateAll(function() { diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 7085baa34..6ab120752 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -727,5 +727,9 @@ angular.module('copayApp.services') }, 'createdOn']); }; + root.setHideBalanceFlag = function(walletId) { + root.wallet[walletId].balanceHidden = !root.wallet[walletId].balanceHidden; + } + return root; }); From a2261ae572c278e4289e99a4943043ca8395dd62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Wed, 31 Aug 2016 12:03:44 -0300 Subject: [PATCH 2/3] persist balance hidden on local storage --- src/js/controllers/walletDetails.js | 6 ++++-- src/js/services/profileService.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index ce4deae08..bfe7b6730 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $ionicNavBarDelegate, $state, $stateParams, bwcError, profileService, lodash, configService, gettext, gettextCatalog, platformInfo, walletService, storageService, $ionicPopup) { +angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $ionicNavBarDelegate, $state, $stateParams, bwcError, profileService, lodash, configService, gettext, gettextCatalog, platformInfo, walletService, $ionicPopup) { var isCordova = platformInfo.isCordova; var isWP = platformInfo.isWP; @@ -176,7 +176,9 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun } $scope.hideToggle = function() { - profileService.setHideBalanceFlag(wallet.credentials.walletId); + profileService.setHideBalanceFlag(wallet.credentials.walletId, function(err) { + if (err) $log.error(err); + }); } var currentTxHistoryPage; diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 6ab120752..9397962d4 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -65,6 +65,13 @@ angular.module('copayApp.services') }); }; + function _balanceIsHidden(wallet, cb) { + storageService.getHideBalanceFlag(wallet.credentials.walletId, function(err, shouldHideBalance) { + if (err) $log.error(err); + var hideBalance = (shouldHideBalance == 'true') ? true : false; + return cb(hideBalance); + }); + }; // Adds a wallet client to profileService root.bindWalletClient = function(wallet, opts) { var opts = opts || {}; @@ -90,6 +97,10 @@ angular.module('copayApp.services') wallet.needsBackup = val; }); + _balanceIsHidden(wallet, function(val) { + wallet.balanceHidden = val; + }); + wallet.removeAllListeners(); wallet.on('report', function(n) { @@ -729,6 +740,7 @@ angular.module('copayApp.services') root.setHideBalanceFlag = function(walletId) { root.wallet[walletId].balanceHidden = !root.wallet[walletId].balanceHidden; + storageService.setHideBalanceFlag(walletId, root.wallet[walletId].balanceHidden.toString(), cb); } return root; From e63b8cc1e2928fbc217db17c377dec0208621401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Wed, 31 Aug 2016 12:18:04 -0300 Subject: [PATCH 3/3] rename function --- src/js/controllers/walletDetails.js | 2 +- src/js/services/profileService.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index bfe7b6730..4422a5d22 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -176,7 +176,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun } $scope.hideToggle = function() { - profileService.setHideBalanceFlag(wallet.credentials.walletId, function(err) { + profileService.toggleHideBalanceFlag(wallet.credentials.walletId, function(err) { if (err) $log.error(err); }); } diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 9397962d4..1d6e5ffdb 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -738,7 +738,7 @@ angular.module('copayApp.services') }, 'createdOn']); }; - root.setHideBalanceFlag = function(walletId) { + root.toggleHideBalanceFlag = function(walletId, cb) { root.wallet[walletId].balanceHidden = !root.wallet[walletId].balanceHidden; storageService.setHideBalanceFlag(walletId, root.wallet[walletId].balanceHidden.toString(), cb); }