82 lines
No EOL
2.3 KiB
JavaScript
82 lines
No EOL
2.3 KiB
JavaScript
'use strict';
|
|
|
|
angular.module('copayApp.controllers').controller('wordsController',
|
|
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 successMsg = gettext('Backup words deleted');
|
|
var self = this;
|
|
self.show = false;
|
|
var fc = profileService.focusedClient;
|
|
|
|
if (fc.isPrivKeyEncrypted()) self.credentialsEncrypted = true;
|
|
else setWords(fc.getMnemonic());
|
|
|
|
if (fc.credentials && !fc.credentials.mnemonicEncrypted && !fc.credentials.mnemonic) {
|
|
self.deleted = true;
|
|
}
|
|
|
|
self.toggle = function() {
|
|
self.error = "";
|
|
self.show = !self.show;
|
|
if (self.show)
|
|
$rootScope.$emit('Local/BackupDone');
|
|
|
|
if (self.credentialsEncrypted)
|
|
self.passwordRequest();
|
|
|
|
$timeout(function() {
|
|
$scope.$apply();
|
|
}, 1);
|
|
};
|
|
|
|
self.delete = function() {
|
|
confirmDialog.show(msg, function(ok) {
|
|
if (ok) {
|
|
fc.clearMnemonic();
|
|
profileService.updateCredentialsFC(function() {
|
|
self.deleted = true;
|
|
notification.success(successMsg);
|
|
go.walletHome();
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
$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;
|
|
}
|
|
};
|
|
|
|
self.passwordRequest = function() {
|
|
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
|
|
self.show = !self.show;
|
|
return;
|
|
}
|
|
self.credentialsEncrypted = false;
|
|
setWords(fc.getMnemonic());
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}); |