Wallet/src/js/controllers/backup.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.controllers').controller('backupController',
2015-11-17 15:42:06 -03:00
function($rootScope, $scope, $timeout, $log, $compile, lodash, profileService, go, gettext, confirmDialog, notification, bwsError) {
var self = this;
2015-10-28 15:57:08 -03:00
var fc = profileService.focusedClient;
if (fc.isPrivKeyEncrypted()) {
2015-11-18 12:29:56 -03:00
self.credentialsEncrypted = true;
passwordRequest();
} else
2015-10-29 14:45:26 -03:00
setWords(fc.getMnemonic());
2015-11-18 12:29:56 -03:00
function setWords(words) {
if (words) {
self.mnemonicWords = words.split(/[\u3000\s]+/);
self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
self.useIdeograms = words.indexOf("\u3000") >= 0;
}
};
function passwordRequest() {
2015-10-28 15:57:08 -03:00
try {
setWords(fc.getMnemonic());
} catch (e) {
if (e.message && e.message.match(/encrypted/) && fc.isPrivKeyEncrypted()) {
2015-09-03 16:49:46 -03:00
2015-10-28 15:57:08 -03:00
$timeout(function() {
$scope.$apply();
}, 1);
2015-09-03 16:49:46 -03:00
2015-10-28 15:57:08 -03:00
profileService.unlockFC(function(err) {
if (err) {
self.error = bwsError.msg(err, gettext('Could not decrypt'));
$log.warn('Error decrypting credentials:', self.error); //TODO
return;
}
2015-10-28 15:57:08 -03:00
self.credentialsEncrypted = false;
setWords(fc.getMnemonic());
});
}
}
}
2015-11-11 17:52:29 -03:00
});