2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('preferencesController',
|
2016-05-09 15:56:44 -03:00
|
|
|
function($scope, $rootScope, $timeout, $log, configService, profileService, fingerprintService, walletService) {
|
2015-11-18 15:14:09 -03:00
|
|
|
|
|
|
|
|
var fc = profileService.focusedClient;
|
2016-05-09 15:56:44 -03:00
|
|
|
var config = configService.getSync();
|
2015-11-18 15:14:09 -03:00
|
|
|
$scope.deleted = false;
|
2016-05-17 18:59:31 -03:00
|
|
|
|
2015-11-18 15:14:09 -03:00
|
|
|
if (fc.credentials && !fc.credentials.mnemonicEncrypted && !fc.credentials.mnemonic) {
|
|
|
|
|
$scope.deleted = true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-07 16:17:19 -03:00
|
|
|
this.init = function() {
|
|
|
|
|
if (fc) {
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.encryptEnabled = walletService.isEncrypted(fc);
|
2015-10-07 16:17:19 -03:00
|
|
|
this.externalSource = fc.getPrivKeyExternalSourceName() == 'ledger' ? "Ledger" : null;
|
|
|
|
|
// TODO externalAccount
|
|
|
|
|
//this.externalIndex = fc.getExternalIndex();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-09 15:56:44 -03:00
|
|
|
this.touchidAvailable = fingerprintService.isAvailable();
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.touchidEnabled = config.touchIdFor ? config.touchIdFor[fc.credentials.walletId] : null;
|
2016-05-09 15:56:44 -03:00
|
|
|
};
|
2016-04-18 09:33:48 -03:00
|
|
|
|
2016-05-09 15:56:44 -03:00
|
|
|
var handleEncryptedWallet = function(client, cb) {
|
|
|
|
|
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
|
|
|
|
|
if (err) return cb(err);
|
|
|
|
|
return cb(walletService.unlock(client, password));
|
|
|
|
|
});
|
2015-10-07 16:17:19 -03:00
|
|
|
};
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.encryptChange = function() {
|
2015-05-13 12:41:05 -03:00
|
|
|
if (!fc) return;
|
2016-05-17 18:59:31 -03:00
|
|
|
var val = $scope.encryptEnabled;
|
2015-05-13 12:41:05 -03:00
|
|
|
|
2016-05-09 15:56:44 -03:00
|
|
|
if (val && !walletService.isEncrypted(fc)) {
|
2015-03-06 12:00:10 -03:00
|
|
|
$rootScope.$emit('Local/NeedsPassword', true, function(err, password) {
|
|
|
|
|
if (err || !password) {
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.encryptEnabled = false;
|
2015-03-06 12:00:10 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
profileService.setPrivateKeyEncryptionFC(password, function() {
|
2015-11-10 20:05:05 -03:00
|
|
|
$rootScope.$emit('Local/NewEncryptionSetting');
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.encryptEnabled = true;
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2016-05-09 15:56:44 -03:00
|
|
|
if (!val && walletService.isEncrypted(fc)) {
|
|
|
|
|
handleEncryptedWallet(fc, function(err) {
|
2015-03-06 12:00:10 -03:00
|
|
|
if (err) {
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.encryptEnabled = true;
|
2015-03-06 12:00:10 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
profileService.disablePrivateKeyEncryptionFC(function(err) {
|
2015-11-10 20:05:05 -03:00
|
|
|
$rootScope.$emit('Local/NewEncryptionSetting');
|
2015-03-06 12:00:10 -03:00
|
|
|
if (err) {
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.encryptEnabled = true;
|
2015-03-06 12:00:10 -03:00
|
|
|
$log.error(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.encryptEnabled = false;
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-17 18:59:31 -03:00
|
|
|
};
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.touchidChange = function() {
|
2016-05-09 15:56:44 -03:00
|
|
|
var walletId = fc.credentials.walletId;
|
2015-10-07 16:17:19 -03:00
|
|
|
|
|
|
|
|
var opts = {
|
|
|
|
|
touchIdFor: {}
|
|
|
|
|
};
|
2016-05-17 18:59:31 -03:00
|
|
|
opts.touchIdFor[walletId] = $scope.touchidEnabled;
|
2015-10-07 16:17:19 -03:00
|
|
|
|
2016-05-09 15:56:44 -03:00
|
|
|
fingerprintService.check(fc, function(err) {
|
2015-11-18 15:14:09 -03:00
|
|
|
if (err) {
|
2015-10-07 16:17:19 -03:00
|
|
|
$log.debug(err);
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.touchidError = true;
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.touchidEnabled = false;
|
2015-10-07 16:17:19 -03:00
|
|
|
}, 100);
|
2016-05-09 15:56:44 -03:00
|
|
|
return;
|
2015-10-07 16:17:19 -03:00
|
|
|
}
|
2016-05-09 15:56:44 -03:00
|
|
|
configService.set(opts, function(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
$log.debug(err);
|
|
|
|
|
$scope.touchidError = true;
|
2016-05-17 18:59:31 -03:00
|
|
|
$scope.touchidEnabled = false;
|
2016-05-09 15:56:44 -03:00
|
|
|
}
|
|
|
|
|
});
|
2015-10-07 16:17:19 -03:00
|
|
|
});
|
2016-05-17 18:59:31 -03:00
|
|
|
};
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|