fix import profile and wallet. digest fix

This commit is contained in:
Gustavo Maximiliano Cortez 2014-12-15 13:18:44 -03:00
commit 88edec1779
5 changed files with 38 additions and 37 deletions

View file

@ -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,21 +81,19 @@ angular.module('copayApp.controllers').controller('ImportController',
if (skipFields) if (skipFields)
$scope.importOpts.skipFields = skipFields; $scope.importOpts.skipFields = skipFields;
if (backupFile) {
$timeout(function() { reader.readAsBinaryString(backupFile);
if (backupFile) { } else {
reader.readAsBinaryString(backupFile); updateStatus('Importing wallet - Procesing backup...');
} else { identityService.importWallet(backupText, $scope.password, $scope.importOpts, function(err) {
updateStatus('Importing wallet - Procesing backup...'); if (err) {
identityService.importWallet(backupText, $scope.password, $scope.importOpts, function(err) { $rootScope.starting = false;
if (err) { $scope.error = 'Could not read wallet. Please check your password';
$scope.loading = false; $timeout(function() {
$scope.error = 'Could not read wallet. Please check your password';
$rootScope.$digest(); $rootScope.$digest();
return; }, 1);
} }
}); });
} }
}, 1);
}; };
}); });

View file

@ -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);
} }
}); });
}; };
@ -51,10 +54,8 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
}; };
$scope.import = function(form) { $scope.import = function(form) {
$scope.loading = true;
if (form.$invalid) { if (form.$invalid) {
$scope.loading = false;
$scope.error = 'Please enter the required fields'; $scope.error = 'Please enter the required fields';
return; return;
} }
@ -63,17 +64,16 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
var password = form.password.$modelValue; var password = form.password.$modelValue;
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;
$timeout(function() { if (backupFile) {
if (backupFile) { reader.readAsBinaryString(backupFile);
reader.readAsBinaryString(backupFile); } else {
} else { _importBackup(backupText);
_importBackup(backupText); }
}
}, 1);
}; };
}); });

View file

@ -136,7 +136,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>
@ -85,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">
@ -47,7 +47,7 @@
<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>