copay/js/controllers/import.js

99 lines
2.8 KiB
JavaScript
Raw Normal View History

2014-04-25 13:34:24 -07:00
'use strict';
2014-06-03 13:42:36 -07:00
angular.module('copayApp.controllers').controller('ImportController',
2014-11-29 13:35:48 -08:00
function($scope, $rootScope, $location, identityService, notification, isMobile, Compatibility) {
2014-08-04 07:27:46 -07:00
2014-11-14 10:05:00 -08:00
$rootScope.title = 'Import wallet';
2014-06-25 11:49:02 -07:00
$scope.importStatus = 'Importing wallet - Reading backup...';
$scope.hideAdv = true;
$scope.is_iOS = isMobile.iOS();
2014-11-14 10:05:00 -08:00
$scope.importOpts = {};
2014-06-25 11:49:02 -07:00
2014-10-30 12:13:56 -07:00
Compatibility.check($scope);
2014-05-01 15:39:01 -07:00
var reader = new FileReader();
2014-06-25 11:49:02 -07:00
var updateStatus = function(status) {
$scope.importStatus = status;
$scope.$digest();
}
$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;
updateStatus('Importing wallet - Procesing backup...');
identityService.importWallet(encryptedObj, $scope.password, {}, function(err) {
if (err) {
$scope.loading = false;
$scope.error = 'Could not read wallet. Please check your password';
}
});
}
2014-06-03 12:48:27 -07:00
}
};
$scope.import = function(form) {
$scope.loading = true;
2014-04-25 15:12:13 -07:00
if (form.$invalid) {
$scope.loading = false;
$scope.error = 'There is an error in the form';
return;
}
var backupFile = $scope.file;
var backupText = form.backupText.$modelValue;
var backupOldWallet = form.backupOldWallet.$modelValue;
var password = form.password.$modelValue;
2014-05-05 09:16:56 -07:00
if (backupOldWallet) {
backupText = backupOldWallet.value;
}
2014-05-05 09:16:56 -07:00
if (!backupFile && !backupText) {
$scope.loading = false;
$scope.error = 'Please, select your backup file';
return;
}
2014-10-30 12:13:56 -07:00
$scope.importOpts = {};
2014-05-05 09:16:56 -07:00
var skipFields = [];
2014-11-14 10:05:00 -08:00
if ($scope.skipPublicKeyRing)
skipFields.push('publicKeyRing');
2014-11-14 10:05:00 -08:00
if ($scope.skipTxProposals)
skipFields.push('txProposals');
2014-11-14 10:05:00 -08:00
if (skipFields)
$scope.importOpts.skipFields = skipFields;
2014-11-14 10:05:00 -08:00
<< << << < HEAD
if (backupFile) {
reader.readAsBinaryString(backupFile);
} else {
updateStatus('Importing wallet - Procesing backup...');
identityService.importWallet(encryptedObj, $scope.password, $scope.importOpts, function(err) {
if (err) {
$scope.loading = false;
$scope.error = 'Could not read wallet. Please check your password';
}
copay.Compatibility.deleteOldWallet(backupOldWallet);
});
}
};
}); === === =
if (backupFile) {
reader.readAsBinaryString(backupFile);
} else {
$scope._doImport(backupText, $scope.password);
copay.Compatibility.deleteOldWallet(backupOldWallet);
}
};
}); >>> >>> > Added needBackup flag when importing a wallet