2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2015-11-18 18:37:42 -03:00
|
|
|
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) {
|
2015-08-08 10:58:30 -03:00
|
|
|
|
2015-09-25 17:24:15 -03:00
|
|
|
var self = this;
|
2015-10-28 15:57:08 -03:00
|
|
|
var fc = profileService.focusedClient;
|
|
|
|
|
|
2015-11-18 18:37:42 -03:00
|
|
|
if (fc.isPrivKeyEncrypted()) {
|
2015-11-18 12:29:56 -03:00
|
|
|
self.credentialsEncrypted = true;
|
2015-11-18 18:37:42 -03:00
|
|
|
passwordRequest();
|
|
|
|
|
} else
|
2015-10-29 14:45:26 -03:00
|
|
|
setWords(fc.getMnemonic());
|
2015-11-18 12:29:56 -03:00
|
|
|
|
2015-09-25 17:24:15 -03:00
|
|
|
function setWords(words) {
|
|
|
|
|
if (words) {
|
|
|
|
|
self.mnemonicWords = words.split(/[\u3000\s]+/);
|
|
|
|
|
self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
|
|
|
|
self.useIdeograms = words.indexOf("\u3000") >= 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-11-18 18:37:42 -03:00
|
|
|
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-11-18 18:37:42 -03:00
|
|
|
|
2015-10-28 15:57:08 -03:00
|
|
|
self.credentialsEncrypted = false;
|
|
|
|
|
setWords(fc.getMnemonic());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-25 17:24:15 -03:00
|
|
|
}
|
2015-11-11 17:52:29 -03:00
|
|
|
});
|