Wallet/src/js/controllers/preferencesAltCurrency.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.controllers').controller('preferencesAltCurrencyController',
2016-12-12 17:29:11 -03:00
function($scope, $log, $timeout, $ionicHistory, 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;
var config = configService.getSync();
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
$scope.listComplete = false;
2016-08-15 17:42:04 -03:00
2016-12-07 16:57:04 -03:00
var unusedCurrencyList = [{
isoCode: 'LTL'
}, {
isoCode: 'BTC'
}];
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
rateService.whenAvailable(function() {
2016-12-07 16:57:04 -03:00
completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) {
return idx[c.isoCode];
2015-03-06 12:00:10 -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) {
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
});
};
});