replace all toggle buttons

This commit is contained in:
Javier 2016-05-17 18:59:31 -03:00
commit a54df263e2
7 changed files with 76 additions and 98 deletions

View file

@ -6,20 +6,21 @@ angular.module('copayApp.controllers').controller('preferencesController',
var fc = profileService.focusedClient;
var config = configService.getSync();
$scope.deleted = false;
if (fc.credentials && !fc.credentials.mnemonicEncrypted && !fc.credentials.mnemonic) {
$scope.deleted = true;
}
this.init = function() {
if (fc) {
$scope.encrypt = walletService.isEncrypted(fc);
$scope.encryptEnabled = walletService.isEncrypted(fc);
this.externalSource = fc.getPrivKeyExternalSourceName() == 'ledger' ? "Ledger" : null;
// TODO externalAccount
//this.externalIndex = fc.getExternalIndex();
}
this.touchidAvailable = fingerprintService.isAvailable();
$scope.touchid = config.touchIdFor ? config.touchIdFor[fc.credentials.walletId] : null;
$scope.touchidEnabled = config.touchIdFor ? config.touchIdFor[fc.credentials.walletId] : null;
};
var handleEncryptedWallet = function(client, cb) {
@ -29,60 +30,56 @@ angular.module('copayApp.controllers').controller('preferencesController',
});
};
var unwatchEncrypt = $scope.$watch('encrypt', function(val) {
var fc = profileService.focusedClient;
$scope.encryptChange = function() {
if (!fc) return;
var val = $scope.encryptEnabled;
if (val && !walletService.isEncrypted(fc)) {
$rootScope.$emit('Local/NeedsPassword', true, function(err, password) {
if (err || !password) {
$scope.encrypt = false;
$scope.encryptEnabled = false;
return;
}
profileService.setPrivateKeyEncryptionFC(password, function() {
$rootScope.$emit('Local/NewEncryptionSetting');
$scope.encrypt = true;
$scope.encryptEnabled = true;
});
});
} else {
if (!val && walletService.isEncrypted(fc)) {
handleEncryptedWallet(fc, function(err) {
if (err) {
$scope.encrypt = true;
$scope.encryptEnabled = true;
return;
}
profileService.disablePrivateKeyEncryptionFC(function(err) {
$rootScope.$emit('Local/NewEncryptionSetting');
if (err) {
$scope.encrypt = true;
$scope.encryptEnabled = true;
$log.error(err);
return;
}
$scope.encrypt = false;
$scope.encryptEnabled = false;
});
});
}
}
});
};
var unwatchRequestTouchid = $scope.$watch('touchid', function(newVal, oldVal) {
if (newVal == oldVal || $scope.touchidError) {
$scope.touchidError = false;
return;
}
$scope.touchidChange = function() {
var walletId = fc.credentials.walletId;
var opts = {
touchIdFor: {}
};
opts.touchIdFor[walletId] = newVal;
opts.touchIdFor[walletId] = $scope.touchidEnabled;
fingerprintService.check(fc, function(err) {
if (err) {
$log.debug(err);
$timeout(function() {
$scope.touchidError = true;
$scope.touchid = oldVal;
$scope.touchidEnabled = false;
}, 100);
return;
}
@ -90,14 +87,9 @@ angular.module('copayApp.controllers').controller('preferencesController',
if (err) {
$log.debug(err);
$scope.touchidError = true;
$scope.touchid = oldVal;
$scope.touchidEnabled = false;
}
});
});
});
$scope.$on('$destroy', function() {
unwatchEncrypt();
unwatchRequestTouchid();
});
};
});