Wallet/src/js/controllers/preferencesAltCurrency.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.controllers').controller('preferencesAltCurrencyController',
function($scope, $rootScope, configService, go, rateService, lodash) {
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) console.log(err);
2015-04-25 12:37:04 -03:00
$scope.$emit('Local/UnitSettingUpdated');
2015-03-06 12:00:10 -03:00
});
};
});