Merge pull request #5219 from gabrielbazan7/fix/alternativeCurrency
Preferences Alt Currency improves
This commit is contained in:
commit
1cace8ac37
3 changed files with 93 additions and 32 deletions
|
|
@ -1,29 +1,38 @@
|
|||
'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;
|
||||
function init() {
|
||||
var unusedCurrencyList = [{
|
||||
isoCode: 'LTL'
|
||||
}, {
|
||||
isoCode: 'BTC'
|
||||
}];
|
||||
rateService.whenAvailable(function() {
|
||||
|
||||
var unusedCurrencyList = [{
|
||||
isoCode: 'LTL'
|
||||
}, {
|
||||
isoCode: 'BTC'
|
||||
}];
|
||||
$scope.listComplete = false;
|
||||
|
||||
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
|
||||
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
|
||||
var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode');
|
||||
|
||||
rateService.whenAvailable(function() {
|
||||
completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) {
|
||||
return idx[c.isoCode];
|
||||
completeAlternativeList = lodash.reject(rateService.listAlternatives(), 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();
|
||||
});
|
||||
});
|
||||
$scope.altCurrencyList = completeAlternativeList.slice(0, next);
|
||||
});
|
||||
}
|
||||
|
||||
$scope.loadMore = function() {
|
||||
$timeout(function() {
|
||||
|
|
@ -34,6 +43,17 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl
|
|||
}, 100);
|
||||
};
|
||||
|
||||
$scope.findCurrency = function(search) {
|
||||
if (!search) init();
|
||||
$scope.altCurrencyList = lodash.filter(completeAlternativeList, function(item) {
|
||||
var val = item.name;
|
||||
return lodash.includes(val.toLowerCase(), search.toLowerCase());
|
||||
});
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.save = function(newAltCurrency) {
|
||||
var opts = {
|
||||
wallet: {
|
||||
|
|
@ -48,9 +68,26 @@ 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 = lodash.uniq($scope.lastUsedAltCurrencyList, 'isoCode');
|
||||
$scope.lastUsedAltCurrencyList = $scope.lastUsedAltCurrencyList.slice(0, 3);
|
||||
storageService.setLastCurrencyUsed(JSON.stringify($scope.lastUsedAltCurrencyList), function() {});
|
||||
};
|
||||
|
||||
$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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue