2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('preferencesAltCurrencyController',
|
2016-09-22 11:55:23 -03:00
|
|
|
function($scope, $log, $timeout, $ionicHistory, gettextCatalog, configService, rateService, lodash, profileService, walletService) {
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2016-06-10 16:49:35 -03:00
|
|
|
var next = 10;
|
|
|
|
|
var completeAlternativeList;
|
|
|
|
|
|
2016-09-22 11:55:23 -03:00
|
|
|
var config = configService.getSync();
|
|
|
|
|
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
|
|
|
|
|
$scope.listComplete = false;
|
2016-08-15 17:42:04 -03:00
|
|
|
|
2016-09-22 11:55:23 -03:00
|
|
|
rateService.whenAvailable(function() {
|
|
|
|
|
completeAlternativeList = rateService.listAlternatives();
|
|
|
|
|
lodash.remove(completeAlternativeList, function(c) {
|
|
|
|
|
return c.isoCode == 'BTC';
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|
2016-09-22 11:55:23 -03:00
|
|
|
$scope.altCurrencyList = completeAlternativeList.slice(0, next);
|
|
|
|
|
});
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2016-06-10 16:49:35 -03:00
|
|
|
$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);
|
|
|
|
|
};
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2016-06-10 09:27:14 -03:00
|
|
|
$scope.save = function(newAltCurrency) {
|
2015-03-06 12:00:10 -03:00
|
|
|
var opts = {
|
|
|
|
|
wallet: {
|
|
|
|
|
settings: {
|
|
|
|
|
alternativeName: newAltCurrency.name,
|
|
|
|
|
alternativeIsoCode: newAltCurrency.isoCode,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
configService.set(opts, function(err) {
|
2015-11-13 16:00:28 -03:00
|
|
|
if (err) $log.warn(err);
|
2016-08-23 12:01:09 -03:00
|
|
|
|
2016-08-29 16:48:15 -03:00
|
|
|
$ionicHistory.goBack();
|
2016-08-23 12:01:09 -03:00
|
|
|
walletService.updateRemotePreferences(profileService.getWallets(), {}, function() {
|
2016-06-07 10:37:39 -03:00
|
|
|
$log.debug('Remote preferences saved');
|
2016-06-06 18:26:45 -03:00
|
|
|
});
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
});
|