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) {

View file

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

View file

@ -1,10 +1,10 @@
<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>
<div ng-show="!loading">
<div ng-show="!$root.starting">
<div class="large-4 large-centered medium-6 medium-centered columns">
<div class="logo-setup show-for-large-up">
<img src="img/logo-negative-beta.svg" alt="Copay" width="100">
@ -22,14 +22,14 @@
</span>
</div>
<div ng-show="!is_iOS">
<div ng-show="!isSafari && !isCordova">
<div class="input">
<input type="file" class="db form-control"
placeholder="{{'Select a backup file'|translate}}" name="backupFile" ng-model="backupFile" ng-file-select>
</div>
</div>
<div ng-show="is_iOS">
<div ng-show="isSafari || isCordova">
<div class="input">
<textarea
placeholder="Paste backup plain text code"
@ -41,13 +41,13 @@
</div>
</div>
<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>
</div>
<button translate type="submit"
class="button primary radius expand m0"
ng-disabled="importProfileForm.$invalid || loading">
ng-disabled="importProfileForm.$invalid || $root.starting">
Import backup
</button>
</form>

View file

@ -24,9 +24,9 @@
<div class="row" ng-show="!backupWalletPlainText && !error">
<div class="large-6 medium-6 small-12 columns">
<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"
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 class="large-6 medium-6 small-12 columns">
<button class="warning expand" ng-disabled="loading"