2017-03-10 12:10:00 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2017-03-30 17:45:57 -03:00
|
|
|
angular.module('copayApp.controllers').controller('lockController', function($state, $scope, $timeout, $log, configService, popupService, gettextCatalog, appConfigService, fingerprintService, profileService, lodash) {
|
2017-03-10 12:10:00 -03:00
|
|
|
|
|
|
|
|
$scope.$on("$ionicView.beforeEnter", function(event) {
|
|
|
|
|
var config = configService.getSync();
|
2017-03-29 09:25:18 -03:00
|
|
|
$scope.fingerprintAvailable = fingerprintService.isAvailable();
|
2017-03-10 12:10:00 -03:00
|
|
|
|
2017-03-29 11:30:16 -03:00
|
|
|
$scope.usePin = {
|
|
|
|
|
enabled: config.lock && config.lock.method == 'pin' ? true : false
|
2017-03-10 12:10:00 -03:00
|
|
|
};
|
|
|
|
|
$scope.useFingerprint = {
|
2017-03-29 11:30:16 -03:00
|
|
|
enabled: config.lock && config.lock.method == 'fingerprint' ? true : false
|
2017-03-10 12:10:00 -03:00
|
|
|
};
|
2017-03-30 17:45:57 -03:00
|
|
|
|
|
|
|
|
processWallets();
|
2017-03-10 12:10:00 -03:00
|
|
|
});
|
|
|
|
|
|
2017-03-30 17:45:57 -03:00
|
|
|
function processWallets() {
|
|
|
|
|
var wallets = profileService.getWallets();
|
|
|
|
|
var singleLivenetWallet = wallets.length == 1 && wallets[0].network == 'livenet' && wallets[0].needsBackup;
|
|
|
|
|
var atLeastOneLivenetWallet = lodash.any(wallets, function(w) {
|
|
|
|
|
return w.network == 'livenet' && w.needsBackup;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (singleLivenetWallet) {
|
|
|
|
|
$scope.errorMsg = gettextCatalog.getString('Backup your wallet before using this function');
|
|
|
|
|
} else if (atLeastOneLivenetWallet) {
|
|
|
|
|
$scope.errorMsg = gettextCatalog.getString('Backup all livenet wallets before using this function');
|
|
|
|
|
} else $scope.errorMsg = null;
|
|
|
|
|
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-03-29 11:30:16 -03:00
|
|
|
$scope.usePinChange = function() {
|
2017-03-30 17:45:57 -03:00
|
|
|
$scope.usePin.enabled = !$scope.usePin.enabled;
|
|
|
|
|
$state.transitionTo('tabs.lock.pin', {
|
2017-03-10 12:10:00 -03:00
|
|
|
fromSettings: true,
|
2017-03-30 17:45:57 -03:00
|
|
|
locking: !$scope.usePin.enabled
|
|
|
|
|
}).then(function() {
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.usePin.enabled = !$scope.usePin.enabled;
|
|
|
|
|
}, 1000);
|
2017-03-10 12:10:00 -03:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.useFingerprintChange = function() {
|
2017-03-29 11:30:16 -03:00
|
|
|
if ($scope.usePin.enabled) {
|
2017-03-30 17:45:57 -03:00
|
|
|
var message = gettextCatalog.getString('{{appName}} is protected by Pin. Are you sure you want to disable it?', {
|
2017-03-10 12:10:00 -03:00
|
|
|
appName: appConfigService.nameCase
|
|
|
|
|
});
|
2017-03-30 17:45:57 -03:00
|
|
|
var okText = gettextCatalog.getString('Continue');
|
2017-03-10 12:10:00 -03:00
|
|
|
var cancelText = gettextCatalog.getString('Cancel');
|
|
|
|
|
popupService.showConfirm(null, message, okText, cancelText, function(ok) {
|
|
|
|
|
if (!ok) {
|
|
|
|
|
$scope.useFingerprint = {
|
|
|
|
|
enabled: false
|
|
|
|
|
};
|
2017-03-10 14:17:23 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
});
|
2017-03-10 12:10:00 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
saveConfig();
|
|
|
|
|
});
|
|
|
|
|
} else
|
|
|
|
|
saveConfig();
|
|
|
|
|
|
|
|
|
|
function saveConfig() {
|
2017-03-29 11:30:16 -03:00
|
|
|
$scope.usePin = {
|
2017-03-10 12:10:00 -03:00
|
|
|
enabled: false
|
|
|
|
|
};
|
2017-03-10 14:17:23 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
});
|
2017-03-10 12:10:00 -03:00
|
|
|
var opts = {
|
2017-03-29 11:30:16 -03:00
|
|
|
lock: {
|
|
|
|
|
method: $scope.useFingerprint.enabled ? 'fingerprint' : '',
|
|
|
|
|
value: '',
|
2017-03-10 12:10:00 -03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
configService.set(opts, function(err) {
|
|
|
|
|
if (err) $log.debug(err);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
});
|