From 11f063b85d1a1516448ac14e84c77e5f07e155d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 13 Dec 2016 16:32:22 -0300 Subject: [PATCH 1/6] save last five alt currency chosen, remove infinite scroll --- src/js/controllers/preferencesAltCurrency.js | 43 +++++++++++--------- src/js/services/storageService.js | 30 +++++++++----- www/views/preferencesAltCurrency.html | 18 ++++---- 3 files changed, 54 insertions(+), 37 deletions(-) diff --git a/src/js/controllers/preferencesAltCurrency.js b/src/js/controllers/preferencesAltCurrency.js index 5f9ab9910..421e2ad16 100644 --- a/src/js/controllers/preferencesAltCurrency.js +++ b/src/js/controllers/preferencesAltCurrency.js @@ -1,38 +1,34 @@ 'use strict'; angular.module('copayApp.controllers').controller('preferencesAltCurrencyController', - function($scope, $log, $timeout, $ionicHistory, configService, rateService, lodash, profileService, walletService) { + function($scope, $log, $timeout, $ionicHistory, configService, rateService, lodash, profileService, walletService, storageService) { var next = 10; var completeAlternativeList; - var config = configService.getSync(); - $scope.currentCurrency = config.wallet.settings.alternativeIsoCode; - $scope.listComplete = false; - var unusedCurrencyList = [{ isoCode: 'LTL' }, { isoCode: 'BTC' }]; - var idx = lodash.indexBy(unusedCurrencyList, 'isoCode'); + var config = configService.getSync(); + $scope.currentCurrency = config.wallet.settings.alternativeIsoCode; rateService.whenAvailable(function() { - completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) { - return idx[c.isoCode]; - }); - $scope.altCurrencyList = completeAlternativeList.slice(0, next); - }); + storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) { - $scope.loadMore = function() { - $timeout(function() { - $scope.altCurrencyList = completeAlternativeList.slice(0, next); - next += 10; - $scope.listComplete = $scope.altCurrencyList.length >= completeAlternativeList.length; - $scope.$broadcast('scroll.infiniteScrollComplete'); - }, 100); - }; + $scope.lastUsedAltCurrencyList = JSON.parse(lastUsedAltCurrency) || []; + + var idx = lodash.indexBy(unusedCurrencyList, 'isoCode'); + var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode'); + + completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) { + return idx[c.isoCode] || idx2[c.isoCode]; + }); + $scope.altCurrencyList = completeAlternativeList; + }); + }); $scope.save = function(newAltCurrency) { var opts = { @@ -48,9 +44,18 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl if (err) $log.warn(err); $ionicHistory.goBack(); + saveLastUsed(newAltCurrency); walletService.updateRemotePreferences(profileService.getWallets(), {}, function() { $log.debug('Remote preferences saved'); }); }); }; + + function saveLastUsed(newAltCurrency) { + $scope.lastUsedAltCurrencyList.unshift(newAltCurrency); + $scope.lastUsedAltCurrencyList = $scope.lastUsedAltCurrencyList.slice(0, 5); + $scope.lastUsedAltCurrencyList = lodash.uniq($scope.lastUsedAltCurrencyList, 'isoCode'); + storageService.setLastCurrencyUsed(JSON.stringify($scope.lastUsedAltCurrencyList), function() {}); + }; + }); diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index 7a82a1b90..f179dd1ab 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -77,25 +77,25 @@ angular.module('copayApp.services') //////////////////////////////////////////////////////////////////////////// // // UPGRADING STORAGE - // + // // 1. Write a function to upgrade the desired storage key(s). The function should have the protocol: - // + // // _upgrade_x(key, network, cb), where: - // + // // `x` is the name of the storage key - // `key` is the name of the storage key being upgraded + // `key` is the name of the storage key being upgraded // `network` is one of 'livenet', 'testnet' // // 2. Add the storage key to `_upgraders` object using the name of the key as the `_upgrader` object key // with the value being the name of the upgrade function (e.g., _upgrade_x). In order to avoid conflicts // when a storage key is involved in multiple upgraders as well as predicte the order in which upgrades - // occur the `_upgrader` object key should be prefixed with '##_' (e.g., '01_') to create a unique and + // occur the `_upgrader` object key should be prefixed with '##_' (e.g., '01_') to create a unique and // sortable name. This format is interpreted by the _upgrade() function. - // + // // Upgraders are executed in numerical order per the '##_' object key prefix. - // + // var _upgraders = { - '00_bitpayDebitCards' : _upgrade_bitpayDebitCards // 2016-11: Upgrade bitpayDebitCards-x to bitpayAccounts-x + '00_bitpayDebitCards': _upgrade_bitpayDebitCards // 2016-11: Upgrade bitpayDebitCards-x to bitpayAccounts-x }; function _upgrade_bitpayDebitCards(key, network, cb) { @@ -375,6 +375,14 @@ angular.module('copayApp.services') storage.remove('nextStep-' + service, cb); }; + root.setLastCurrencyUsed = function(lastCurrencyUsed, cb) { + storage.set('lastCurrencyUsed', lastCurrencyUsed, cb) + }; + + root.getLastCurrencyUsed = function(cb) { + storage.get('lastCurrencyUsed', cb) + }; + root.checkQuota = function() { var block = ''; // 50MB @@ -487,12 +495,14 @@ angular.module('copayApp.services') bitpayAccounts = bitpayAccounts || {}; Object.keys(bitpayAccounts).forEach(function(userId) { var data = bitpayAccounts[userId]['bitpayDebitCards-' + network]; - var newCards = lodash.reject(data.cards, {'eid': card.eid}); + var newCards = lodash.reject(data.cards, { + 'eid': card.eid + }); data.cards = newCards; root.setBitpayDebitCards(network, data, function(err) { if (err) cb(err); // If there are no more cards in storage then re-enable the next step entry. - root.getBitpayDebitCards(network, function(err, cards){ + root.getBitpayDebitCards(network, function(err, cards) { if (err) cb(err); if (cards.length == 0) { root.removeNextStep('BitpayCard', cb); diff --git a/www/views/preferencesAltCurrency.html b/www/views/preferencesAltCurrency.html index 0954fa8b5..322f58402 100644 --- a/www/views/preferencesAltCurrency.html +++ b/www/views/preferencesAltCurrency.html @@ -7,13 +7,15 @@ - {{altCurrency.name}} - - - +
+ {{lastUsedAltCurrency.name}} + +
+
+ {{altCurrency.name}} + +
From 39a2c801334f8a43a356928ac1e87c7644add7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 13 Dec 2016 16:48:22 -0300 Subject: [PATCH 2/6] search box for currency --- src/js/controllers/preferencesAltCurrency.js | 36 ++++++++++++++------ www/views/preferencesAltCurrency.html | 7 ++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/js/controllers/preferencesAltCurrency.js b/src/js/controllers/preferencesAltCurrency.js index 421e2ad16..5f5b83a6e 100644 --- a/src/js/controllers/preferencesAltCurrency.js +++ b/src/js/controllers/preferencesAltCurrency.js @@ -12,23 +12,36 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl isoCode: 'BTC' }]; - var config = configService.getSync(); - $scope.currentCurrency = config.wallet.settings.alternativeIsoCode; + function init() { + var config = configService.getSync(); + $scope.currentCurrency = config.wallet.settings.alternativeIsoCode; - rateService.whenAvailable(function() { - storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) { + rateService.whenAvailable(function() { + storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) { - $scope.lastUsedAltCurrencyList = JSON.parse(lastUsedAltCurrency) || []; + $scope.lastUsedAltCurrencyList = JSON.parse(lastUsedAltCurrency) || []; - var idx = lodash.indexBy(unusedCurrencyList, 'isoCode'); - var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode'); + var idx = lodash.indexBy(unusedCurrencyList, 'isoCode'); + var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode'); - completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) { - return idx[c.isoCode] || idx2[c.isoCode]; + $scope.completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) { + return idx[c.isoCode] || idx2[c.isoCode]; + }); + $scope.altCurrencyList = $scope.completeAlternativeList; }); - $scope.altCurrencyList = completeAlternativeList; }); - }); + } + + $scope.findCurrency = function(search) { + if (!search) init(); + $scope.altCurrencyList = lodash.filter($scope.completeAlternativeList, function(item) { + var val = item.name; + return lodash.includes(val.toLowerCase(), search.toLowerCase()); + }); + $timeout(function() { + $scope.$apply(); + }); + }; $scope.save = function(newAltCurrency) { var opts = { @@ -58,4 +71,5 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl storageService.setLastCurrencyUsed(JSON.stringify($scope.lastUsedAltCurrencyList), function() {}); }; + init(); }); diff --git a/www/views/preferencesAltCurrency.html b/www/views/preferencesAltCurrency.html index 322f58402..dc51757a2 100644 --- a/www/views/preferencesAltCurrency.html +++ b/www/views/preferencesAltCurrency.html @@ -7,6 +7,13 @@ +
+ +
{{lastUsedAltCurrency.name}} From 6aedf9a75fe8a27e129116219d9b339b75dfb8c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 13 Dec 2016 17:04:46 -0300 Subject: [PATCH 3/6] add margin bottom --- www/views/preferencesAltCurrency.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/views/preferencesAltCurrency.html b/www/views/preferencesAltCurrency.html index dc51757a2..1a59c60f3 100644 --- a/www/views/preferencesAltCurrency.html +++ b/www/views/preferencesAltCurrency.html @@ -7,7 +7,7 @@ -
+
+ +