Merge pull request #2161 from cmgustavo/bug/import-text-plain-backup

Fixes importing a plain text backup
This commit is contained in:
Matias Alejo Garcia 2014-12-18 19:40:26 -03:00
commit abf552aa5c
9 changed files with 51 additions and 39 deletions

View file

@ -1,12 +1,13 @@
'use strict';
angular.module('copayApp.controllers').controller('ImportController',
function($scope, $rootScope, $location, $timeout, identityService, notification, isMobile, Compatibility) {
function($scope, $rootScope, $location, $timeout, identityService, notification, isMobile, isCordova, Compatibility) {
$rootScope.title = 'Import wallet';
$scope.importStatus = 'Importing wallet - Reading backup...';
$scope.hideAdv = true;
$scope.is_iOS = isMobile.iOS();
$scope.isSafari = isMobile.Safari();
$scope.isCordova = isCordova;
$scope.importOpts = {};
window.ignoreMobilePause = true;
@ -22,7 +23,6 @@ angular.module('copayApp.controllers').controller('ImportController',
var updateStatus = function(status) {
$scope.importStatus = status;
$scope.$digest();
}
@ -34,8 +34,11 @@ angular.module('copayApp.controllers').controller('ImportController',
updateStatus('Importing wallet - Procesing backup...');
identityService.importWallet(encryptedObj, $scope.password, {}, function(err) {
if (err) {
$scope.loading = false;
$rootScope.starting = false;
$scope.error = 'Could not read wallet. Please check your password';
$timeout(function() {
$rootScope.$digest();
}, 1);
}
});
}
@ -43,10 +46,8 @@ angular.module('copayApp.controllers').controller('ImportController',
};
$scope.import = function(form) {
$scope.loading = true;
if (form.$invalid) {
$scope.loading = false;
$scope.error = 'There is an error in the form';
return;
}
@ -61,11 +62,12 @@ angular.module('copayApp.controllers').controller('ImportController',
}
if (!backupFile && !backupText) {
$scope.loading = false;
$scope.error = 'Please, select your backup file';
return;
}
$rootScope.starting = true;
$scope.importOpts = {};
var skipFields = [];
@ -79,19 +81,18 @@ angular.module('copayApp.controllers').controller('ImportController',
if (skipFields)
$scope.importOpts.skipFields = skipFields;
if (backupFile) {
reader.readAsBinaryString(backupFile);
} else {
updateStatus('Importing wallet - Procesing backup...');
identityService.importWallet(encryptedObj, $scope.password, $scope.importOpts, function(err) {
identityService.importWallet(backupText, $scope.password, $scope.importOpts, function(err) {
if (err) {
$scope.loading = false;
$rootScope.starting = false;
$scope.error = 'Could not read wallet. Please check your password';
$rootScope.$digest();
return;
$timeout(function() {
$rootScope.$digest();
}, 1);
}
copay.Compatibility.deleteOldWallet(backupOldWallet);
});
}
};

View file

@ -1,11 +1,12 @@
'use strict';
angular.module('copayApp.controllers').controller('ImportProfileController',
function($scope, $rootScope, $location, $timeout, notification, isMobile, identityService) {
function($scope, $rootScope, $location, $timeout, notification, isMobile, isCordova, identityService) {
$scope.title = 'Import a backup';
$scope.importStatus = 'Importing wallet - Reading backup...';
$scope.importStatus = 'Importing profile - Reading backup...';
$scope.hideAdv = true;
$scope.is_iOS = isMobile.iOS();
$scope.isSafari = isMobile.Safari();
$scope.isCordova = isCordova;
window.ignoreMobilePause = true;
$scope.$on('$destroy', function() {
@ -18,7 +19,6 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
var updateStatus = function(status) {
$scope.importStatus = status;
$scope.$digest();
}
var _importBackup = function(str) {
@ -26,8 +26,8 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
updateStatus('Importing profile - Setting things up...');
identityService.importProfile(str,password, function(err, iden) {
$scope.loading = false;
if (err) {
$rootScope.starting = false;
copay.logger.warn(err);
if ((err.toString() || '').match('BADSTR')) {
$scope.error = 'Bad password or corrupt profile file';
@ -36,6 +36,9 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
} else {
$scope.error = 'Unknown error';
}
$timeout(function() {
$rootScope.$digest();
}, 1);
}
});
};
@ -64,8 +67,9 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
$scope.error = 'Please, select your backup file';
return;
}
$rootScope.starting = true;
$scope.loading = true;
if (backupFile) {
reader.readAsBinaryString(backupFile);
} else {

View file

@ -1,8 +1,8 @@
'use strict';
angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, $filter, $timeout, backupService, identityService, isMobile) {
angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, $filter, $timeout, backupService, identityService, isMobile, isCordova) {
$scope.username = $rootScope.iden.getName();
$scope.isSafari = isMobile.Safari();
$scope.isCordova = !!window.cordova;
$scope.isCordova = isCordova;
$rootScope.title = 'Profile';
$scope.hideAdv = true;
@ -62,6 +62,7 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
var ModalInstanceCtrl = function($scope, $modalInstance) {
if (!w) return;
$scope.isSafari = isMobile.Safari();
$scope.isCordova = isCordova;
$scope.item = w;
$scope.error = null;
$scope.success = null;

View file

@ -247,6 +247,7 @@ Compatibility.kdf = function(password) {
};
Compatibility.deleteOldWallet = function(walletObj) {
console.log('[Compatibility.js:249]',walletObj); //TODO
localStorage.removeItem('wallet::' + walletObj.id + '_' + walletObj.name);
log.info('Old wallet ' + walletObj.name + ' deleted: ' + walletObj.id);
};

View file

@ -72,12 +72,12 @@ BackupService.prototype.walletDownload = function(wallet) {
};
BackupService.prototype.profileEncrypted = function(iden) {
iden.setBackupDone();
return iden.exportEncryptedWithWalletInfo(iden.password);
}
BackupService.prototype.profileDownload = function(iden) {
var ew = this.profileEncrypted(iden);
iden.setBackupDone();
var name = iden.fullName;
var filename = name + '-profile.json';
this._download(ew, name, filename)

View file

@ -140,7 +140,7 @@ angular.module('copayApp.services')
pendingTxsService.update();
$timeout(function() {
$rootScope.$digest();
})
}, 1);
};
root.notifyTxProposalEvent = function(w, e) {