encrypted wallet feat migrated to BWC 4.0.0

This commit is contained in:
Matias Alejo Garcia 2016-08-29 15:17:41 -03:00
commit 392d8f7292
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
6 changed files with 69 additions and 101 deletions

View file

@ -189,7 +189,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
};
var setSendError = function(msg) {
showAlert(gettext('Error creating transaction'), msg);
showAlert(gettext('Error at confirm:'), msg);
};
function apply(txp) {

View file

@ -31,71 +31,39 @@ angular.module('copayApp.controllers').controller('preferencesController',
}
};
var handleEncryptedWallet = function(cb) {
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
if (err) return cb(err);
return cb(walletService.unlock(wallet, password));
});
};
$scope.encryptChange = function() {
if (!wallet) return;
var val = $scope.encryptEnabled;
var setPrivateKeyEncryption = function(password, cb) {
$log.debug('Encrypting private key for', wallet.credentials.walletName);
wallet.setPrivateKeyEncryption(password);
wallet.lock();
profileService.updateCredentials(JSON.parse(wallet.export()), function() {
$log.debug('Wallet encrypted');
return cb();
});
};
var disablePrivateKeyEncryption = function(cb) {
$log.debug('Disabling private key encryption for', wallet.credentials.walletName);
try {
wallet.disablePrivateKeyEncryption();
} catch (e) {
return cb(e);
}
profileService.updateCredentials(JSON.parse(wallet.export()), function() {
$log.debug('Wallet encryption disabled');
return cb();
});
};
if (val && !walletService.isEncrypted(wallet)) {
$rootScope.$emit('Local/NeedsPassword', true, function(err, password) {
if (err || !password) {
$log.debug('Encrypting private key for', wallet.name);
walletService.encrypt(wallet, function(err) {
if (err) {
$log.warn(err);
// ToDo show error?
$scope.encryptEnabled = false;
return;
}
setPrivateKeyEncryption(password, function() {
$rootScope.$emit('Local/NewEncryptionSetting');
profileService.updateCredentials(JSON.parse(wallet.export()), function() {
$log.debug('Wallet encrypted');
return;
});
})
} else if (!val && walletService.isEncrypted(wallet)) {
walletService.decrypt(wallet, function(err) {
if (err) {
$log.warn(err);
// ToDo show error?
$scope.encryptEnabled = true;
return;
}
profileService.updateCredentials(JSON.parse(wallet.export()), function() {
$log.debug('Wallet decrypted');
return;
});
});
} else {
if (!val && walletService.isEncrypted(wallet)) {
handleEncryptedWallet(function(err) {
if (err) {
$scope.encryptEnabled = true;
return;
}
disablePrivateKeyEncryption(function(err) {
$rootScope.$emit('Local/NewEncryptionSetting');
if (err) {
$scope.encryptEnabled = true;
$log.error(err);
return;
}
$scope.encryptEnabled = false;
});
});
}
})
}
};

View file

@ -37,7 +37,6 @@ angular.module('copayApp.controllers').controller('tabHomeController',
walletService.getNotifications(wallet, {
timeSpan: timeSpan
}, function(err, n) {
console.log('[tab-home.js.39]', wallet.name, n); //TODO
if (err) {
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
return;