Merge pull request #1669 from matiaspando/feature/importProfile
Import profile
This commit is contained in:
commit
53843a578d
14 changed files with 209 additions and 51 deletions
|
|
@ -27,7 +27,7 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
if ($scope.skipTxProposals)
|
||||
skipFields.push('txProposals');
|
||||
|
||||
$rootScope.iden.importEncryptedWallet(encryptedObj, password, skipFields, function(err, w) {
|
||||
$rootScope.iden.importEncryptedWallet(encryptedObj, password, skipFields, opts, function(err, w) {
|
||||
if (!w) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', err || 'Wrong password');
|
||||
|
|
@ -67,9 +67,11 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
reader.onloadend = function(evt) {
|
||||
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
|
||||
var encryptedObj = evt.target.result;
|
||||
|
||||
copay.Compatibility.importEncryptedWallet($rootScope.iden, encryptedObj, $scope.password, {},
|
||||
function(err, wallet){
|
||||
function(err, wallet) {
|
||||
if (err) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', 'Could not read wallet. Please check your password');
|
||||
} else {
|
||||
controllerUtils.installWalletHandlers($scope, wallet);
|
||||
|
|
@ -109,23 +111,22 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
|
||||
if (backupFile) {
|
||||
reader.readAsBinaryString(backupFile);
|
||||
}
|
||||
else {
|
||||
copay.Compatibility.importEncryptedWallet($rootScope.iden, backupText, $scope.password, {},
|
||||
function(err, wallet){
|
||||
if (err) {
|
||||
notification.error('Error', 'Could not read wallet. Please check your password');
|
||||
} else {
|
||||
copay.Compatibility.deleteOldWallet(backupOldWallet);
|
||||
controllerUtils.installWalletHandlers($scope, wallet);
|
||||
controllerUtils.setFocusedWallet(wallet);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
copay.Compatibility.importEncryptedWallet($rootScope.iden, backupText, $scope.password, {},
|
||||
function(err, wallet) {
|
||||
if (err) {
|
||||
notification.error('Error', 'Could not read wallet. Please check your password');
|
||||
} else {
|
||||
copay.Compatibility.deleteOldWallet(backupOldWallet);
|
||||
controllerUtils.installWalletHandlers($scope, wallet);
|
||||
controllerUtils.setFocusedWallet(wallet);
|
||||
return;
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
try {
|
||||
_importBackup(backupText);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
copay.Compatibility.importEncryptedWallet(backupText, $scope.password, $scope.skipPublicKeyRing, $scope.skipTxProposals);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
83
js/controllers/importProfile.js
Normal file
83
js/controllers/importProfile.js
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('ImportProfileController',
|
||||
function($scope, $rootScope, $location, controllerUtils, notification, isMobile, pluginManager) {
|
||||
controllerUtils.redirIfLogged();
|
||||
|
||||
$scope.title = 'Import a backup';
|
||||
$scope.importStatus = 'Importing wallet - Reading backup...';
|
||||
$scope.hideAdv = true;
|
||||
$scope.is_iOS = isMobile.iOS();
|
||||
|
||||
var reader = new FileReader();
|
||||
|
||||
var updateStatus = function(status) {
|
||||
$scope.importStatus = status;
|
||||
$scope.$digest();
|
||||
}
|
||||
|
||||
var _importBackup = function(str) {
|
||||
var password = $scope.password;
|
||||
updateStatus('Importing profile - Setting things up...');
|
||||
|
||||
copay.Identity.importFromEncryptedFullJson(str, password, {
|
||||
pluginManager: pluginManager,
|
||||
network: config.network,
|
||||
networkName: config.networkName,
|
||||
walletDefaults: config.wallet,
|
||||
passphraseConfig: config.passphraseConfig,
|
||||
}, function(err, iden) {
|
||||
if (err && !iden) {
|
||||
controllerUtils.onErrorDigest(
|
||||
$scope, (err.toString() || '').match('BADSTR') ? 'Bad password or corrupt profile file' : 'Unknown error');
|
||||
} else {
|
||||
notification.info('Success', 'Profile imported successfully');
|
||||
$location.path('/');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openFileDialog = function() {
|
||||
if (window.cshell) {
|
||||
return cshell.send('backup:import');
|
||||
}
|
||||
$scope.choosefile = !$scope.choosefile;
|
||||
};
|
||||
|
||||
$scope.getFile = function() {
|
||||
// If we use onloadend, we need to check the readyState.
|
||||
reader.onloadend = function(evt) {
|
||||
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
|
||||
var encryptedObj = evt.target.result;
|
||||
_importBackup(encryptedObj);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
$scope.import = function(form) {
|
||||
$scope.loading = true;
|
||||
|
||||
if (form.$invalid) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', 'There is an error in the form.');
|
||||
return;
|
||||
}
|
||||
|
||||
var backupFile = $scope.file;
|
||||
var backupText = form.backupText.$modelValue;
|
||||
var password = form.password.$modelValue;
|
||||
|
||||
if (!backupFile && !backupText) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', 'Please, select your backup file');
|
||||
$scope.loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (backupFile) {
|
||||
reader.readAsBinaryString(backupFile);
|
||||
} else {
|
||||
_importBackup(backupText);
|
||||
}
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue