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