Merge pull request #5242 from gabrielbazan7/fix/repeatedCurrencies

fix repeated currencies
This commit is contained in:
Javier Donadío 2016-12-15 16:48:25 -03:00 committed by GitHub
commit 6858054e5a
2 changed files with 11 additions and 7 deletions

View file

@ -19,15 +19,12 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode');
completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) {
completeAlternativeList = lodash.reject(rateService.listAlternatives(true), function(c) {
return idx[c.isoCode] || idx2[c.isoCode];
});
completeAlternativeList = completeAlternativeList.sort(function(a, b) {
return a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1;
});
$scope.altCurrencyList = completeAlternativeList.slice(0, 10);
$timeout(function() {
$scope.$apply();
});
@ -85,6 +82,7 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl
$scope.$on("$ionicView.beforeEnter", function(event, data) {
var config = configService.getSync();
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) {
$scope.lastUsedAltCurrencyList = lastUsedAltCurrency ? JSON.parse(lastUsedAltCurrency) : [];
init();

View file

@ -111,18 +111,24 @@ RateService.prototype.fromFiat = function(amount, code) {
return amount / this.getRate(code) * this.BTC_TO_SAT;
};
RateService.prototype.listAlternatives = function() {
RateService.prototype.listAlternatives = function(sort) {
var self = this;
if (!this.isAvailable()) {
return [];
}
return self.lodash.map(this.getAlternatives(), function(item) {
var alternatives = self.lodash.map(this.getAlternatives(), function(item) {
return {
name: item.name,
isoCode: item.isoCode
}
});
if (sort) {
alternatives.sort(function(a, b) {
return a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1;
});
}
return self.lodash.uniq(alternatives, 'isoCode');
};
angular.module('copayApp.services').factory('rateService', function($http, lodash) {