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