2015-11-09 15:20:15 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('preferencesGlobalController',
|
2016-05-31 19:02:00 -03:00
|
|
|
function($scope, $rootScope, $log, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService) {
|
2015-12-23 14:17:24 -03:00
|
|
|
|
2016-06-13 14:49:43 -03:00
|
|
|
$scope.init = function() {
|
2015-11-09 15:20:15 -03:00
|
|
|
var config = configService.getSync();
|
2016-08-15 17:42:04 -03:00
|
|
|
var isCordova = platformInfo.isCordova;
|
|
|
|
|
|
|
|
|
|
if (isCordova && StatusBar.isVisible) {
|
|
|
|
|
StatusBar.backgroundColorByHexString("#4B6178");
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-13 14:49:43 -03:00
|
|
|
$scope.unitName = config.wallet.settings.unitName;
|
|
|
|
|
$scope.currentLanguageName = uxLanguage.getCurrentLanguageName();
|
|
|
|
|
$scope.selectedAlternative = {
|
2015-11-09 15:20:15 -03:00
|
|
|
name: config.wallet.settings.alternativeName,
|
|
|
|
|
isoCode: config.wallet.settings.alternativeIsoCode
|
2015-12-23 14:17:24 -03:00
|
|
|
};
|
2016-06-13 14:49:43 -03:00
|
|
|
$scope.feeOpts = feeService.feeOpts;
|
|
|
|
|
$scope.currentFeeLevel = feeService.getCurrentFeeLevel();
|
|
|
|
|
$scope.usePushNotifications = isCordova && !platformInfo.isWP;
|
2016-03-31 11:33:59 -04:00
|
|
|
$scope.PNEnabledByUser = true;
|
2016-05-31 19:02:00 -03:00
|
|
|
$scope.isIOSApp = platformInfo.isIOS && isCordova;
|
2016-04-13 17:46:25 +02:00
|
|
|
if ($scope.isIOSApp) {
|
2016-03-30 17:49:48 -04:00
|
|
|
cordova.plugins.diagnostic.isRemoteNotificationsEnabled(function(isEnabled) {
|
|
|
|
|
$scope.PNEnabledByUser = isEnabled;
|
2016-06-15 11:42:01 -03:00
|
|
|
$scope.$digest();
|
2016-03-30 17:49:48 -04:00
|
|
|
});
|
|
|
|
|
}
|
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-06-13 14:49:43 -03:00
|
|
|
$scope.openSettings = function() {
|
2016-03-30 17:49:48 -04:00
|
|
|
cordova.plugins.diagnostic.switchToSettings(function() {
|
|
|
|
|
$log.debug('switched to settings');
|
|
|
|
|
}, function(err) {
|
|
|
|
|
$log.debug(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.spendUnconfirmedChange = function() {
|
2015-11-09 15:20:15 -03:00
|
|
|
var opts = {
|
|
|
|
|
wallet: {
|
2016-05-17 18:59:31 -03:00
|
|
|
spendUnconfirmed: $scope.spendUnconfirmed
|
2015-11-09 15:20:15 -03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
configService.set(opts, function(err) {
|
|
|
|
|
if (err) $log.debug(err);
|
|
|
|
|
});
|
2016-05-17 18:59:31 -03:00
|
|
|
};
|
2015-11-09 15:20:15 -03:00
|
|
|
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.pushNotificationsChange = function() {
|
2015-12-23 14:17:24 -03:00
|
|
|
var opts = {
|
2016-01-15 11:59:29 -03:00
|
|
|
pushNotifications: {
|
2016-05-17 18:59:31 -03:00
|
|
|
enabled: $scope.pushNotifications
|
2015-12-23 14:17:24 -03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
});
|
2016-05-17 18:59:31 -03:00
|
|
|
};
|
2015-12-23 14:17:24 -03:00
|
|
|
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.glideraChange = function() {
|
2015-11-09 15:20:15 -03:00
|
|
|
var opts = {
|
|
|
|
|
glidera: {
|
2016-05-17 18:59:31 -03:00
|
|
|
enabled: $scope.glideraEnabled
|
2015-11-09 15:20:15 -03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
configService.set(opts, function(err) {
|
|
|
|
|
$rootScope.$emit('Local/GlideraUpdated');
|
|
|
|
|
if (err) $log.debug(err);
|
|
|
|
|
});
|
2016-05-17 18:59:31 -03:00
|
|
|
};
|
2015-11-09 15:20:15 -03:00
|
|
|
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.coinbaseChange = function() {
|
2015-11-09 15:20:15 -03:00
|
|
|
var opts = {
|
2016-04-13 14:08:03 -03:00
|
|
|
coinbase: {
|
2016-05-17 18:59:31 -03:00
|
|
|
enabled: $scope.coinbaseEnabled
|
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);
|
|
|
|
|
});
|
2016-05-17 18:59:31 -03:00
|
|
|
};
|
2015-11-09 15:20:15 -03:00
|
|
|
});
|