Merge pull request #3370 from gabrielbazan7/fix/backupEncryptedPKey3

Fix/backup encrypted p key3
This commit is contained in:
Gustavo Maximiliano Cortez 2015-10-29 16:20:13 -03:00
commit 7aca195ded
2 changed files with 57 additions and 45 deletions

View file

@ -8,7 +8,6 @@
<div class="content preferences" ng-controller="wordsController as wordsC"> <div class="content preferences" ng-controller="wordsController as wordsC">
<h4></h4> <h4></h4>
<div class="box-notification" ng-show="wordsC.error"> <div class="box-notification" ng-show="wordsC.error">
<span class="text-warning"> <span class="text-warning">
{{wordsC.error|translate}} {{wordsC.error|translate}}
@ -17,7 +16,7 @@
<div ng-show="wordsC.mnemonicWords"> <div ng-show="wordsC.mnemonicWords || (wordsC.credentialsEncrypted && !wordsC.deleted)">
<div class="row" ng-show="index.n==1"> <div class="row" ng-show="index.n==1">
<div class="m10t columns size-14 text-gray"> <div class="m10t columns size-14 text-gray">
<span translate> <span translate>
@ -33,11 +32,11 @@
<span translate> <span translate>
To restore this {{index.m}}-{{index.n}} <b>shared</b> wallet you will need To restore this {{index.m}}-{{index.n}} <b>shared</b> wallet you will need
</span>: </span>:
<ol class="m10t columns size-14 text-gray"> <ol class="m10t columns size-14 text-gray">
<li translate>Your wallet seed and access to the server that coordinated the initial wallet creation. You still need {{index.m}} keys to spend.</li> <li translate>Your wallet seed and access to the server that coordinated the initial wallet creation. You still need {{index.m}} keys to spend.</li>
<li translate><b>OR</b> the wallet seed of <b>all</b> copayers in the wallet</li> <li translate><b>OR</b> the wallet seed of <b>all</b> copayers in the wallet</li>
<li translate><b>OR</b> 1 wallet export file and the remaining quorum of wallet seeds (e.g. in a 3-5 wallet: 1 wallet export file + 2 wallet seeds of any of the other copayers).</li> <li translate><b>OR</b> 1 wallet export file and the remaining quorum of wallet seeds (e.g. in a 3-5 wallet: 1 wallet export file + 2 wallet seeds of any of the other copayers).</li>
</ol> </ol>
</span> </span>
</div> </div>
</div> </div>
@ -46,22 +45,22 @@
<span translate> <span translate>
To restore this {{index.m}}-{{index.n}} <b>shared</b> wallet you will need To restore this {{index.m}}-{{index.n}} <b>shared</b> wallet you will need
</span>: </span>:
<ol class="m10t columns size-14 text-gray"> <ol class="m10t columns size-14 text-gray">
<li translate>Your wallet seed and access to the server that coordinated the initial wallet creation. You still need {{index.m}} keys to spend.</li> <li translate>Your wallet seed and access to the server that coordinated the initial wallet creation. You still need {{index.m}} keys to spend.</li>
<li translate><b>OR</b> the wallet seeds of <b>all</b> copayers in the wallet</li> <li translate><b>OR</b> the wallet seeds of <b>all</b> copayers in the wallet</li>
</ol> </ol>
</span> </span>
</div> </div>
</div> </div>
</div> </div>
<div class="row m20t" ng-show="!wordsC.mnemonicWords && !wordsC.credentialsEncrypted"> <div class="row m20t" ng-show="wordsC.deleted">
<div class="columns size-14 text-gray text-center" translate> <div class="columns size-14 text-gray text-center" translate>
Wallet seed not available. You can still export it from Advanced &gt; Export. Wallet seed not available. You can still export it from Advanced &gt; Export.
</div> </div>
</div> </div>
<div ng-show="wordsC.mnemonicWords"> <div ng-show="wordsC.mnemonicWords || (wordsC.credentialsEncrypted && !wordsC.deleted)">
<div class="row"> <div class="row">
<div class="m10t columns"> <div class="m10t columns">
<a class="button outline light-gray expand tiny" ng-click="wordsC.toggle()"> <a class="button outline light-gray expand tiny" ng-click="wordsC.toggle()">

View file

@ -5,27 +5,38 @@ angular.module('copayApp.controllers').controller('wordsController',
var msg = gettext('Are you sure you want to delete the backup words?'); var msg = gettext('Are you sure you want to delete the backup words?');
var successMsg = gettext('Backup words deleted'); var successMsg = gettext('Backup words deleted');
this.show = false;
var self = this; var self = this;
self.show = false;
var fc = profileService.focusedClient;
this.toggle = function() { if (fc.isPrivKeyEncrypted()) self.credentialsEncrypted = true;
this.show = !this.show; else {
setWords(fc.getMnemonic());
$rootScope.$emit('Local/BackupDone');
}
if (fc.credentials && !fc.credentials.mnemonicEncrypted && !fc.credentials.mnemonic) {
self.deleted = true;
}
if (this.show) self.toggle = function() {
$rootScope.$emit('Local/BackupDone'); self.error = "";
if (!self.credentialsEncrypted)
self.show = !self.show;
$timeout(function(){ if (self.credentialsEncrypted)
self.passwordRequest();
$timeout(function() {
$scope.$apply(); $scope.$apply();
}, 1); }, 1);
}; };
this.delete = function() { self.delete = function() {
var fc = profileService.focusedClient;
confirmDialog.show(msg, function(ok) { confirmDialog.show(msg, function(ok) {
if (ok) { if (ok) {
fc.clearMnemonic(); fc.clearMnemonic();
profileService.updateCredentialsFC(function() { profileService.updateCredentialsFC(function() {
self.deleted = true;
notification.success(successMsg); notification.success(successMsg);
go.walletHome(); go.walletHome();
}); });
@ -33,12 +44,10 @@ angular.module('copayApp.controllers').controller('wordsController',
}); });
}; };
$scope.$on('$destroy', function() { $scope.$on('$destroy', function() {
profileService.lockFC(); profileService.lockFC();
}); });
function setWords(words) { function setWords(words) {
if (words) { if (words) {
self.mnemonicWords = words.split(/[\u3000\s]+/); self.mnemonicWords = words.split(/[\u3000\s]+/);
@ -47,26 +56,30 @@ angular.module('copayApp.controllers').controller('wordsController',
} }
}; };
var fc = profileService.focusedClient; self.passwordRequest = function() {
try { try {
setWords(fc.getMnemonic()); setWords(fc.getMnemonic());
} catch (e) { } catch (e) {
if (e.message && e.message.match(/encrypted/) && fc.isPrivKeyEncrypted()) { if (e.message && e.message.match(/encrypted/) && fc.isPrivKeyEncrypted()) {
self.credentialsEncrypted = true; self.credentialsEncrypted = true;
$timeout(function(){ $timeout(function() {
$scope.$apply(); $scope.$apply();
}, 1); }, 1);
profileService.unlockFC(function(err) { profileService.unlockFC(function(err) {
if (err) { if (err) {
self.error = bwsError.msg(err, gettext('Could not decrypt')); self.error = bwsError.msg(err, gettext('Could not decrypt'));
$log.warn('Error decrypting credentials:',self.error); //TODO $log.warn('Error decrypting credentials:', self.error); //TODO
return; return;
} }
self.credentialsEncrypted = false; if (!self.show && self.credentialsEncrypted)
setWords(fc.getMnemonic()); self.show = !self.show;
}); self.credentialsEncrypted = false;
setWords(fc.getMnemonic());
$rootScope.$emit('Local/BackupDone');
});
}
} }
} }
}); });