performance improvements

This commit is contained in:
Gabriel Bazán 2016-12-14 09:48:36 -03:00
commit f515e24b57

View file

@ -9,21 +9,17 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl
}, { }, {
isoCode: 'BTC' isoCode: 'BTC'
}]; }];
var config = configService.getSync(); rateService.whenAvailable(function() {
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode; var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode');
storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) { $scope.completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) {
$scope.lastUsedAltCurrencyList = lastUsedAltCurrency ? JSON.parse(lastUsedAltCurrency) : []; return idx[c.isoCode] || idx2[c.isoCode];
rateService.whenAvailable(function() { });
$scope.altCurrencyList = $scope.completeAlternativeList;
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode'); $timeout(function() {
var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode'); $scope.$apply();
$scope.completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) {
return idx[c.isoCode] || idx2[c.isoCode];
});
$scope.altCurrencyList = $scope.completeAlternativeList;
}); });
}); });
} }
@ -62,12 +58,25 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl
function saveLastUsed(newAltCurrency) { function saveLastUsed(newAltCurrency) {
$scope.lastUsedAltCurrencyList.unshift(newAltCurrency); $scope.lastUsedAltCurrencyList.unshift(newAltCurrency);
$scope.lastUsedAltCurrencyList = $scope.lastUsedAltCurrencyList.slice(0, 3);
$scope.lastUsedAltCurrencyList = lodash.uniq($scope.lastUsedAltCurrencyList, 'isoCode'); $scope.lastUsedAltCurrencyList = lodash.uniq($scope.lastUsedAltCurrencyList, 'isoCode');
$scope.lastUsedAltCurrencyList = $scope.lastUsedAltCurrencyList.slice(0, 3);
storageService.setLastCurrencyUsed(JSON.stringify($scope.lastUsedAltCurrencyList), function() {}); storageService.setLastCurrencyUsed(JSON.stringify($scope.lastUsedAltCurrencyList), function() {});
}; };
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
init(); var config = configService.getSync();
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) {
$scope.lastUsedAltCurrencyList = lastUsedAltCurrency ? JSON.parse(lastUsedAltCurrency) : [];
$timeout(function() {
$scope.$apply();
});
});
});
$scope.$on("$ionicView.enter", function(event, data) {
$timeout(function() {
init();
});
}); });
}); });