2015-11-09 15:20:15 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('preferencesGlobalController',
|
2016-04-07 12:58:32 -03:00
|
|
|
function($scope, $rootScope, $log, configService, uxLanguage, isCordova, isMobile, pushNotificationsService, profileService, feeService) {
|
2015-12-23 14:17:24 -03:00
|
|
|
|
2015-11-09 15:20:15 -03:00
|
|
|
this.init = function() {
|
|
|
|
|
var config = configService.getSync();
|
|
|
|
|
this.unitName = config.wallet.settings.unitName;
|
|
|
|
|
this.currentLanguageName = uxLanguage.getCurrentLanguageName();
|
|
|
|
|
this.selectedAlternative = {
|
|
|
|
|
name: config.wallet.settings.alternativeName,
|
|
|
|
|
isoCode: config.wallet.settings.alternativeIsoCode
|
2015-12-23 14:17:24 -03:00
|
|
|
};
|
2016-02-22 19:56:53 -03:00
|
|
|
this.feeOpts = feeService.feeOpts;
|
|
|
|
|
this.currentFeeLevel = feeService.getCurrentFeeLevel();
|
2016-04-07 12:58:32 -03:00
|
|
|
this.usePushNotifications = isCordova && !isMobile.Windows();
|
2016-03-31 11:33:59 -04:00
|
|
|
$scope.PNEnabledByUser = true;
|
2016-04-13 17:46:25 +02:00
|
|
|
$scope.isIOSApp = isMobile.iOS() && isCordova;
|
|
|
|
|
if ($scope.isIOSApp) {
|
2016-03-30 17:49:48 -04:00
|
|
|
cordova.plugins.diagnostic.isRemoteNotificationsEnabled(function(isEnabled) {
|
|
|
|
|
$scope.PNEnabledByUser = isEnabled;
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-11-09 15:20:15 -03:00
|
|
|
$scope.spendUnconfirmed = config.wallet.spendUnconfirmed;
|
|
|
|
|
$scope.glideraEnabled = config.glidera.enabled;
|
2016-04-13 14:08:03 -03:00
|
|
|
$scope.coinbaseEnabled = config.coinbase.enabled;
|
2016-01-20 13:20:47 -03:00
|
|
|
$scope.pushNotifications = config.pushNotifications.enabled;
|
2015-11-09 15:20:15 -03:00
|
|
|
};
|
|
|
|
|
|
2016-03-30 17:49:48 -04:00
|
|
|
this.openSettings = function() {
|
|
|
|
|
cordova.plugins.diagnostic.switchToSettings(function() {
|
|
|
|
|
$log.debug('switched to settings');
|
|
|
|
|
}, function(err) {
|
|
|
|
|
$log.debug(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-09 15:20:15 -03:00
|
|
|
var unwatchSpendUnconfirmed = $scope.$watch('spendUnconfirmed', function(newVal, oldVal) {
|
|
|
|
|
if (newVal == oldVal) return;
|
|
|
|
|
var opts = {
|
|
|
|
|
wallet: {
|
|
|
|
|
spendUnconfirmed: newVal
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
configService.set(opts, function(err) {
|
2015-12-23 18:05:22 -03:00
|
|
|
$rootScope.$emit('Local/SpendUnconfirmedUpdated', newVal);
|
2015-11-09 15:20:15 -03:00
|
|
|
if (err) $log.debug(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-01-20 13:20:47 -03:00
|
|
|
var unwatchPushNotifications = $scope.$watch('pushNotifications', function(newVal, oldVal) {
|
2015-12-23 14:17:24 -03:00
|
|
|
if (newVal == oldVal) return;
|
|
|
|
|
var opts = {
|
2016-01-15 11:59:29 -03:00
|
|
|
pushNotifications: {
|
2015-12-23 14:17:24 -03:00
|
|
|
enabled: newVal
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
configService.set(opts, function(err) {
|
2016-01-13 10:12:10 -03:00
|
|
|
if (opts.pushNotifications.enabled)
|
2016-01-26 14:44:17 -03:00
|
|
|
pushNotificationsService.enableNotifications(profileService.walletClients);
|
2016-01-04 14:11:24 -03:00
|
|
|
else
|
2016-01-26 14:44:17 -03:00
|
|
|
pushNotificationsService.disableNotifications(profileService.walletClients);
|
2015-12-23 14:17:24 -03:00
|
|
|
if (err) $log.debug(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-11-09 15:20:15 -03:00
|
|
|
var unwatchGlideraEnabled = $scope.$watch('glideraEnabled', function(newVal, oldVal) {
|
|
|
|
|
if (newVal == oldVal) return;
|
|
|
|
|
var opts = {
|
|
|
|
|
glidera: {
|
|
|
|
|
enabled: newVal
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
configService.set(opts, function(err) {
|
|
|
|
|
$rootScope.$emit('Local/GlideraUpdated');
|
|
|
|
|
if (err) $log.debug(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-04-13 14:08:03 -03:00
|
|
|
var unwatchCoinbaseEnabled = $scope.$watch('coinbaseEnabled', function(newVal, oldVal) {
|
2015-11-09 15:20:15 -03:00
|
|
|
if (newVal == oldVal) return;
|
|
|
|
|
var opts = {
|
2016-04-13 14:08:03 -03:00
|
|
|
coinbase: {
|
|
|
|
|
enabled: newVal
|
2015-11-09 15:20:15 -03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
configService.set(opts, function(err) {
|
2016-04-13 14:08:03 -03:00
|
|
|
$rootScope.$emit('Local/CoinbaseUpdated');
|
2015-11-09 15:20:15 -03:00
|
|
|
if (err) $log.debug(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function() {
|
|
|
|
|
unwatchSpendUnconfirmed();
|
|
|
|
|
unwatchGlideraEnabled();
|
2016-04-13 14:08:03 -03:00
|
|
|
unwatchCoinbaseEnabled();
|
2016-01-20 13:20:47 -03:00
|
|
|
unwatchPushNotifications();
|
2015-11-09 15:20:15 -03:00
|
|
|
});
|
|
|
|
|
});
|