Wallet/src/js/controllers/preferencesAltCurrency.js
2015-11-13 16:00:28 -03:00

61 lines
1.6 KiB
JavaScript

'use strict';
angular.module('copayApp.controllers').controller('preferencesAltCurrencyController',
function($scope, $timeout, $log, configService, rateService, lodash, go) {
this.hideAdv = true;
this.hidePriv = true;
this.hideSecret = true;
this.error = null;
this.success = null;
var config = configService.getSync();
this.selectedAlternative = {
name: config.wallet.settings.alternativeName,
isoCode: config.wallet.settings.alternativeIsoCode
};
this.alternativeOpts = [this.selectedAlternative]; //default value
var self = this;
rateService.whenAvailable(function() {
self.alternativeOpts = rateService.listAlternatives();
lodash.remove(self.alternativeOpts, function(n) {
return n.isoCode == 'BTC';
});
for (var ii in self.alternativeOpts) {
if (config.wallet.settings.alternativeIsoCode === self.alternativeOpts[ii].isoCode) {
self.selectedAlternative = self.alternativeOpts[ii];
}
}
$scope.$digest();
});
this.save = function(newAltCurrency) {
var opts = {
wallet: {
settings: {
alternativeName: newAltCurrency.name,
alternativeIsoCode: newAltCurrency.isoCode,
}
}
};
this.selectedAlternative = {
name: newAltCurrency.name,
isoCode: newAltCurrency.isoCode,
};
configService.set(opts, function(err) {
if (err) $log.warn(err);
go.preferencesGlobal();
$scope.$emit('Local/UnitSettingUpdated');
$timeout(function() {
$scope.$apply();
}, 100);
});
};
});