Merge pull request #3233 from matiu/bug/mnemonics-encrypted

fix mnemonics with priv key is encrypted
This commit is contained in:
Gustavo Maximiliano Cortez 2015-09-28 14:16:53 -03:00
commit ba12a0e5de
3 changed files with 48 additions and 10 deletions

View File

@ -5,9 +5,17 @@
</div> </div>
<div class="content p20v" ng-controller="wordsController as wordsC"> <div class="content p20v" ng-controller="wordsController as wordsC">
<div class="box-notification" ng-show="wordsC.error">
<span class="text-warning">
{{wordsC.error|translate}}
</span>
</div>
<div ng-show="wordsC.mnemonicWords"> <div ng-show="wordsC.mnemonicWords">
<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">
@ -46,7 +54,7 @@
</div> </div>
</div> </div>
<div class="row m20t" ng-show="!wordsC.mnemonicWords"> <div class="row m20t" ng-show="!wordsC.mnemonicWords && !wordsC.credentialsEncrypted">
<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>

View File

@ -1,13 +1,14 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('wordsController', angular.module('copayApp.controllers').controller('wordsController',
function($rootScope, $scope, $timeout, profileService, go, gettext, confirmDialog, notification) { function($rootScope, $scope, $timeout, profileService, go, gettext, confirmDialog, notification, bwsError, $log) {
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; this.show = false;
var self = this;
this.toggle = function() { this.toggle = function() {
this.show = !this.show; this.show = !this.show;
@ -32,13 +33,40 @@ angular.module('copayApp.controllers').controller('wordsController',
}); });
}; };
var fc = profileService.focusedClient;
var words = fc.getMnemonic();
if (words) {
this.mnemonicWords = words.split(/[\u3000\s]+/);
this.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
this.useIdeograms = words.indexOf("\u3000") >= 0;
}
$scope.$on('$destroy', function() {
profileService.lockFC();
});
function setWords(words) {
if (words) {
self.mnemonicWords = words.split(/[\u3000\s]+/);
self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
self.useIdeograms = words.indexOf("\u3000") >= 0;
}
};
var fc = profileService.focusedClient;
try {
setWords(fc.getMnemonic());
} catch (e) {
if (e.message && e.message.match(/encrypted/) && fc.isPrivKeyEncrypted()) {
self.credentialsEncrypted = true;
$timeout(function(){
$scope.$apply();
}, 1);
profileService.unlockFC(function(err) {
if (err) {
self.error = bwsError.msg(err, gettext('Could not decrypt'));
$log.warn('Error decrypting credentials:',self.error); //TODO
return;
}
self.credentialsEncrypted = false;
setWords(fc.getMnemonic());
});
}
}
}); });

View File

@ -103,6 +103,8 @@ angular.module('copayApp.services')
body = err.message || err.code; body = err.message || err.code;
break; break;
} }
} else if (err.message) {
body = gettextCatalog.getString(err.message);
} else { } else {
body = gettextCatalog.getString(err); body = gettextCatalog.getString(err);
} }