2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('preferencesAltCurrencyController',
|
2016-06-10 09:27:14 -03:00
|
|
|
function($scope, $log, configService, rateService, lodash, go, profileService, walletService) {
|
2015-03-06 12:00:10 -03:00
|
|
|
|
|
|
|
|
var config = configService.getSync();
|
|
|
|
|
|
2016-06-10 09:27:14 -03:00
|
|
|
$scope.currentCurrency = {
|
2015-03-06 12:00:10 -03:00
|
|
|
name: config.wallet.settings.alternativeName,
|
|
|
|
|
isoCode: config.wallet.settings.alternativeIsoCode
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
rateService.whenAvailable(function() {
|
2016-06-10 09:27:14 -03:00
|
|
|
$scope.altCurrencyList = rateService.listAlternatives();
|
|
|
|
|
|
|
|
|
|
lodash.remove($scope.altCurrencyList, function(c) {
|
|
|
|
|
return c.isoCode == 'BTC';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
lodash.each($scope.altCurrencyList, function(altCurrency) {
|
|
|
|
|
if (config.wallet.settings.alternativeIsoCode === altCurrency.isoCode)
|
|
|
|
|
$scope.currentCurrency = altCurrency;
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
});
|
|
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
});
|