Wallet/src/js/controllers/preferencesAltCurrency.js

50 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.controllers').controller('preferencesAltCurrencyController',
2016-06-10 16:49:35 -03:00
function($scope, $log, $timeout, configService, rateService, lodash, go, profileService, walletService) {
2015-03-06 12:00:10 -03:00
var config = configService.getSync();
2016-06-10 16:49:35 -03:00
var next = 10;
var completeAlternativeList;
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
$scope.listComplete = false;
$scope.init = function() {
rateService.whenAvailable(function() {
completeAlternativeList = rateService.listAlternatives();
lodash.remove(completeAlternativeList, function(c) {
return c.isoCode == 'BTC';
});
$scope.altCurrencyList = completeAlternativeList.slice(0, next);
2015-03-06 12:00:10 -03:00
});
2016-06-10 16:49:35 -03:00
};
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) {
if (err) $log.warn(err);
go.preferencesGlobal();
2015-04-25 12:37:04 -03:00
$scope.$emit('Local/UnitSettingUpdated');
2016-06-10 09:27:14 -03:00
walletService.updateRemotePreferences(profileService.getClients(), {}, 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
});
};
});