WIP passphrase confirm - add passphrase view and separate controllers
This commit is contained in:
parent
afdb26de1e
commit
4d94121ec6
11 changed files with 234 additions and 134 deletions
56
src/js/controllers/bachupWords.js
Normal file
56
src/js/controllers/bachupWords.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupWordsController',
|
||||
function($rootScope, $scope, $timeout, $log, $compile, lodash, profileService, go, gettext, confirmDialog, notification, bwsError) {
|
||||
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
var customSortWords = [];
|
||||
self.sorted = false;
|
||||
|
||||
setWords(fc.getMnemonic());
|
||||
|
||||
function setWords(words) {
|
||||
if (words) {
|
||||
self.mnemonicWords = words.split(/[\u3000\s]+/);
|
||||
self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
||||
self.useIdeograms = words.indexOf("\u3000") >= 0;
|
||||
}
|
||||
};
|
||||
|
||||
self.enableButton = function(word) {
|
||||
document.getElementById(word).disabled = false;
|
||||
lodash.remove(customSortWords, function(v) {
|
||||
return v == word;
|
||||
});
|
||||
}
|
||||
|
||||
self.disableButton = function(word) {
|
||||
document.getElementById(word).disabled = true;
|
||||
customSortWords.push(word);
|
||||
self.addButton(word);
|
||||
}
|
||||
|
||||
self.addButton = function(word) {
|
||||
var btnhtml = '<button class="button radius tiny" style="white-space:nowrap" ' +
|
||||
'data-ng-click="backupWordsC.removeButton($event)" id="_' + word + '" > ' + word + ' </button>';
|
||||
var temp = $compile(btnhtml)($scope);
|
||||
angular.element(document.getElementById('addWord')).append(temp);
|
||||
self.shouldContinue(customSortWords);
|
||||
}
|
||||
|
||||
self.removeButton = function(event) {
|
||||
var id = (event.target.id);
|
||||
var element = document.getElementById(id);
|
||||
element.remove();
|
||||
self.enableButton(id.substring(1));
|
||||
self.shouldContinue(customSortWords);
|
||||
}
|
||||
|
||||
self.shouldContinue = function(customSortWords) {
|
||||
if (lodash.isEqual(self.mnemonicWords, customSortWords))
|
||||
self.sorted = true;
|
||||
else
|
||||
self.sorted = false;
|
||||
}
|
||||
});
|
||||
|
|
@ -1,57 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('wordsController',
|
||||
angular.module('copayApp.controllers').controller('backupController',
|
||||
function($rootScope, $scope, $timeout, $log, $compile, lodash, profileService, go, gettext, confirmDialog, notification, bwsError) {
|
||||
|
||||
var msg = gettext('Are you sure you want to delete the backup words?');
|
||||
var successMsg = gettext('Backup words deleted');
|
||||
var self = this;
|
||||
var customSortWords = [];
|
||||
var fc = profileService.focusedClient;
|
||||
self.show = false;
|
||||
self.sorted = false;
|
||||
|
||||
if (fc.isPrivKeyEncrypted())
|
||||
if (fc.isPrivKeyEncrypted()) {
|
||||
self.credentialsEncrypted = true;
|
||||
else
|
||||
passwordRequest();
|
||||
} else
|
||||
setWords(fc.getMnemonic());
|
||||
|
||||
if (fc.credentials && !fc.credentials.mnemonicEncrypted && !fc.credentials.mnemonic)
|
||||
self.deleted = true;
|
||||
|
||||
self.toggle = function() {
|
||||
self.error = "";
|
||||
if (!self.credentialsEncrypted) {
|
||||
if (!self.show)
|
||||
$rootScope.$emit('Local/BackupDone');
|
||||
self.show = !self.show;
|
||||
}
|
||||
|
||||
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]+/);
|
||||
|
|
@ -60,12 +20,11 @@ angular.module('copayApp.controllers').controller('wordsController',
|
|||
}
|
||||
};
|
||||
|
||||
self.passwordRequest = function() {
|
||||
function passwordRequest() {
|
||||
try {
|
||||
setWords(fc.getMnemonic());
|
||||
} catch (e) {
|
||||
if (e.message && e.message.match(/encrypted/) && fc.isPrivKeyEncrypted()) {
|
||||
self.credentialsEncrypted = true;
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
|
|
@ -77,50 +36,12 @@ angular.module('copayApp.controllers').controller('wordsController',
|
|||
$log.warn('Error decrypting credentials:', self.error); //TODO
|
||||
return;
|
||||
}
|
||||
if (!self.show && self.credentialsEncrypted)
|
||||
self.show = !self.show;
|
||||
|
||||
self.credentialsEncrypted = false;
|
||||
setWords(fc.getMnemonic());
|
||||
$rootScope.$emit('Local/BackupDone');
|
||||
// $rootScope.$emit('Local/BackupDone');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.enableButton = function(word) {
|
||||
document.getElementById(word).disabled = false;
|
||||
lodash.remove(customSortWords, function(v) {
|
||||
return v == word;
|
||||
});
|
||||
}
|
||||
|
||||
self.disableButton = function(word) {
|
||||
document.getElementById(word).disabled = true;
|
||||
customSortWords.push(word);
|
||||
self.addButton(word);
|
||||
}
|
||||
|
||||
self.addButton = function(word) {
|
||||
var asd = 'apospodk';
|
||||
var btnhtml = '<button class="button radius tiny" style="white-space:nowrap" ' +
|
||||
'data-ng-click="wordsC.removeButton($event)" id="_' + word + '" > ' + word + ' </button>';
|
||||
var temp = $compile(btnhtml)($scope);
|
||||
angular.element(document.getElementById('addWord')).append(temp);
|
||||
self.shouldContinue(customSortWords);
|
||||
}
|
||||
|
||||
self.removeButton = function(event) {
|
||||
var id = (event.target.id);
|
||||
var element = document.getElementById(id);
|
||||
element.remove();
|
||||
self.enableButton(id.substring(1));
|
||||
self.shouldContinue(customSortWords);
|
||||
}
|
||||
|
||||
self.shouldContinue = function(customSortWords) {
|
||||
if (lodash.isEqual(self.mnemonicWords, customSortWords))
|
||||
self.sorted = true;
|
||||
else
|
||||
self.sorted = false;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
22
src/js/controllers/backupConfirm.js
Normal file
22
src/js/controllers/backupConfirm.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupConfirmController',
|
||||
function($rootScope, $scope, $timeout, $log, $compile, lodash, profileService, go, gettext, confirmDialog, notification, bwsError) {
|
||||
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
|
||||
setWords(fc.getMnemonic());
|
||||
|
||||
function setWords(words) {
|
||||
if (words) {
|
||||
self.mnemonicWords = words.split(/[\u3000\s]+/);
|
||||
self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
||||
self.useIdeograms = words.indexOf("\u3000") >= 0;
|
||||
}
|
||||
};
|
||||
|
||||
self.confirm = function() {
|
||||
$rootScope.$emit('Local/BackupDone');
|
||||
}
|
||||
});
|
||||
34
src/js/controllers/backupPassphrase.js
Normal file
34
src/js/controllers/backupPassphrase.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupPassphraseController',
|
||||
function($rootScope, $scope, $timeout, $log, $compile, bwcService, lodash, profileService, go, gettext, confirmDialog, notification, bwsError) {
|
||||
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
self.passphraseSuccess = false;
|
||||
self.error = "";
|
||||
|
||||
setWords(fc.getMnemonic());
|
||||
var words = fc.getMnemonic();
|
||||
|
||||
function setWords(words) {
|
||||
if (words) {
|
||||
self.mnemonicWords = words.split(/[\u3000\s]+/);
|
||||
self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
||||
self.useIdeograms = words.indexOf("\u3000") >= 0;
|
||||
}
|
||||
};
|
||||
|
||||
self.confirm = function() {
|
||||
var walletClient = bwcService.getClient();
|
||||
|
||||
walletClient.importFromMnemonic(words, {
|
||||
network: 'livenet',
|
||||
passphrase: $scope.passphrase,
|
||||
account: 0,
|
||||
}, function(err) {
|
||||
if (err)
|
||||
self.error = err.message;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupController',
|
||||
angular.module('copayApp.controllers').controller('exportController',
|
||||
function($rootScope, $scope, $timeout, $log, backupService, storageService, profileService, isMobile, notification, go, gettext, gettextCatalog) {
|
||||
var self = this;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue