This commit is contained in:
Matias Pando 2014-09-22 12:13:51 -03:00
parent 12adaa64d2
commit ce976a1b42
1 changed files with 33 additions and 19 deletions

View File

@ -14,15 +14,32 @@ angular.module('copayApp.controllers').controller('OpenController', function($sc
};
$rootScope.fromSetup = false;
$scope.loading = false;
$scope.wallets = walletFactory.getWallets().sort(cmp);
$scope.selectedWalletId = walletFactory.storage.getLastOpened() || ($scope.wallets[0] && $scope.wallets[0].id);
$scope.retreiving = true;
walletFactory.getWallets(function(err, wallets) {
if (err || !wallets || !wallets.length) {
$location.path('/');
} else {
$scope.retreiving = false;
$scope.wallets = wallets.sort(cmp);
walletFactory.storage.getLastOpened(function(ret) {
if (ret && _.indexOf(_.pluck($scope.wallets, 'id')) == -1)
ret = null;
$scope.selectedWalletId = ret || ($scope.wallets[0] && $scope.wallets[0].id);
setTimeout(function() {
$rootScope.$digest();
}, 0);
});
}
});
$scope.openPassword = '';
$scope.isMobile = !!window.cordova;
if (!$scope.wallets.length) {
$location.path('/');
}
$scope.open = function(form) {
if (form && form.$invalid) {
notification.error('Error', 'Please enter the required fields');
@ -34,19 +51,16 @@ angular.module('copayApp.controllers').controller('OpenController', function($sc
Passphrase.getBase64Async(password, function(passphrase) {
var w, errMsg;
try {
w = walletFactory.open($scope.selectedWalletId, passphrase);
} catch (e) {
errMsg = e.message;
};
if (!w) {
$scope.loading = false;
notification.error('Error', errMsg || 'Wrong password');
$rootScope.$digest();
return;
}
$rootScope.updatingBalance = true;
controllerUtils.startNetwork(w, $scope);
walletFactory.open($scope.selectedWalletId, passphrase, function(err, w) {
if (!w) {
$scope.loading = false;
notification.error('Error', err.errMsg || 'Wrong password');
$rootScope.$digest();
} else {
$rootScope.updatingBalance = true;
controllerUtils.startNetwork(w, $scope);
}
});
});
};