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

View file

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

View file

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

View file

@ -247,6 +247,7 @@ Compatibility.kdf = function(password) {
}; };
Compatibility.deleteOldWallet = function(walletObj) { Compatibility.deleteOldWallet = function(walletObj) {
console.log('[Compatibility.js:249]',walletObj); //TODO
localStorage.removeItem('wallet::' + walletObj.id + '_' + walletObj.name); localStorage.removeItem('wallet::' + walletObj.id + '_' + walletObj.name);
log.info('Old wallet ' + walletObj.name + ' deleted: ' + walletObj.id); 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) { BackupService.prototype.profileEncrypted = function(iden) {
iden.setBackupDone();
return iden.exportEncryptedWithWalletInfo(iden.password); return iden.exportEncryptedWithWalletInfo(iden.password);
} }
BackupService.prototype.profileDownload = function(iden) { BackupService.prototype.profileDownload = function(iden) {
var ew = this.profileEncrypted(iden); var ew = this.profileEncrypted(iden);
iden.setBackupDone();
var name = iden.fullName; var name = iden.fullName;
var filename = name + '-profile.json'; var filename = name + '-profile.json';
this._download(ew, name, filename) this._download(ew, name, filename)

View file

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

View file

@ -1,9 +1,9 @@
<div class="import" ng-controller="ImportController"> <div class="import" ng-controller="ImportController">
<div ng-show="loading"> <div ng-show="$root.starting">
<div ng-include="'views/includes/loading.html'" ng-init="title = importStatus"></div> <div ng-include="'views/includes/loading.html'" ng-init="title = importStatus"></div>
</div> </div>
<div ng-show="!loading"> <div ng-show="!$root.starting">
<div class="row hide-for-large-up"> <div class="row hide-for-large-up">
<div class="large-12 medium-12 small-12 columns"> <div class="large-12 medium-12 small-12 columns">
<h1>{{$root.title}}</h1> <h1>{{$root.title}}</h1>
@ -13,19 +13,23 @@
<div class="large-12 columns"> <div class="large-12 columns">
<div class="panel"> <div class="panel">
<form name="importForm" ng-submit="import(importForm)" novalidate> <form name="importForm" ng-submit="import(importForm)" novalidate>
<div class="text-warning size-12 m20b" ng-show="error"> <div class="box-notification" ng-show="error">
<i class="fi-x"></i> {{error|translate}} <div class="box-icon error">
<i class="fi-x size-24"></i>
</div>
<span class="text-warning size-14">
{{error|translate}}
</span>
</div> </div>
<div ng-show="!isSafari && !isCordova && !backupOldWallet">
<div ng-show="!is_iOS && !backupOldWallet">
<legend for="backupFile" class="m10b"> <legend for="backupFile" class="m10b">
<span translate>Choose backup file from your computer</span> <i class="fi-laptop"></i> <span translate>Choose backup file from your computer</span> <i class="fi-laptop"></i>
</legend> </legend>
<input type="file" class="form-control" placeholder="{{'Select a backup file'|translate}}" name="backupFile" ng-model="backupFile" ng-file-select> <input type="file" class="form-control" placeholder="{{'Select a backup file'|translate}}" name="backupFile" ng-model="backupFile" ng-file-select>
</div> </div>
<div ng-show="is_iOS && !backupOldWallet"> <div ng-show="isSafari || isCordova && !backupOldWallet">
<label for="backupText" class="m10b"> <label for="backupText" class="m10b">
<span translate>Paste backup plain text code</span> <i class="fi-clipboard"></i> <span translate>Paste backup plain text code</span> <i class="fi-clipboard"></i>
</label> </label>
@ -81,7 +85,8 @@
<div class="text-right m20t"> <div class="text-right m20t">
<button translate type="submit" class="button expand black m0" ng-disabled="importForm.$invalid"> <button translate type="submit" class="button expand black m0"
ng-disabled="importForm.$invalid || $root.starting">
Import backup Import backup
</button> </button>
</div> </div>

View file

@ -1,10 +1,10 @@
<div class="import-profile" ng-controller="ImportProfileController"> <div class="import-profile" ng-controller="ImportProfileController">
<div ng-show="loading"> <div ng-show="$root.starting">
<div ng-include="'views/includes/loading.html'" ng-init="title = importStatus"></div> <div ng-include="'views/includes/loading.html'" ng-init="title = importStatus"></div>
</div> </div>
<div ng-show="!loading"> <div ng-show="!$root.starting">
<div class="large-4 large-centered medium-6 medium-centered columns"> <div class="large-4 large-centered medium-6 medium-centered columns">
<div class="logo-setup show-for-large-up"> <div class="logo-setup show-for-large-up">
<img src="img/logo-negative-beta.svg" alt="Copay" width="100"> <img src="img/logo-negative-beta.svg" alt="Copay" width="100">
@ -22,14 +22,14 @@
</span> </span>
</div> </div>
<div ng-show="!is_iOS"> <div ng-show="!isSafari && !isCordova">
<div class="input"> <div class="input">
<input type="file" class="db form-control" <input type="file" class="db form-control"
placeholder="{{'Select a backup file'|translate}}" name="backupFile" ng-model="backupFile" ng-file-select> placeholder="{{'Select a backup file'|translate}}" name="backupFile" ng-model="backupFile" ng-file-select>
</div> </div>
</div> </div>
<div ng-show="is_iOS"> <div ng-show="isSafari || isCordova">
<div class="input"> <div class="input">
<textarea <textarea
placeholder="Paste backup plain text code" placeholder="Paste backup plain text code"
@ -41,13 +41,13 @@
</div> </div>
</div> </div>
<div class="input"> <div class="input">
<input type="password" class="form-control" placeholder="{{'Your wallet password'|translate}}" name="password" ng-model="password" required> <input type="password" class="form-control" placeholder="{{'Your profile password'|translate}}" name="password" ng-model="password" required>
<i class="icon-locked"></i> <i class="icon-locked"></i>
</div> </div>
<button translate type="submit" <button translate type="submit"
class="button primary radius expand m0" class="button primary radius expand m0"
ng-disabled="importProfileForm.$invalid || loading"> ng-disabled="importProfileForm.$invalid || $root.starting">
Import backup Import backup
</button> </button>
</form> </form>

View file

@ -24,9 +24,9 @@
<div class="row" ng-show="!backupWalletPlainText && !error"> <div class="row" ng-show="!backupWalletPlainText && !error">
<div class="large-6 medium-6 small-12 columns"> <div class="large-6 medium-6 small-12 columns">
<button class="primary expand" ng-click="downloadWalletBackup()" ng-disabled="loading" <button class="primary expand" ng-click="downloadWalletBackup()" ng-disabled="loading"
ng-show="!isSafari"><i class="fi-download"></i> Download backup</button> ng-show="!isSafari && !isCordova"><i class="fi-download"></i> Download backup</button>
<button class="primary expand" ng-click="viewWalletBackup()" ng-disabled="loading" <button class="primary expand" ng-click="viewWalletBackup()" ng-disabled="loading"
ng-show="isSafari"><i class="fi-eye"></i> View Backup</button> ng-show="isSafari || isCordova"><i class="fi-eye"></i> View Backup</button>
</div> </div>
<div class="large-6 medium-6 small-12 columns"> <div class="large-6 medium-6 small-12 columns">
<button class="warning expand" ng-disabled="loading" <button class="warning expand" ng-disabled="loading"