2014-07-23 13:10:02 -07:00
|
|
|
'use strict';
|
|
|
|
|
2014-08-14 15:46:42 -07:00
|
|
|
angular.module('copayApp.controllers').controller('OpenController', function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase, notification) {
|
|
|
|
controllerUtils.redirIfLogged();
|
2014-08-04 07:27:46 -07:00
|
|
|
|
2014-08-13 11:10:37 -07:00
|
|
|
if ($rootScope.pendingPayment) {
|
|
|
|
notification.info('Login Required', 'Please open wallet to complete payment');
|
|
|
|
}
|
|
|
|
|
2014-08-14 15:46:42 -07:00
|
|
|
var cmp = function(o1, o2) {
|
|
|
|
var v1 = o1.show.toLowerCase(),
|
|
|
|
v2 = o2.show.toLowerCase();
|
|
|
|
return v1 > v2 ? 1 : (v1 < v2) ? -1 : 0;
|
|
|
|
};
|
|
|
|
$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.openPassword = '';
|
|
|
|
$scope.isMobile = !!window.cordova;
|
2014-07-23 13:10:02 -07:00
|
|
|
|
2014-08-15 07:41:34 -07:00
|
|
|
if (!$scope.wallets.length){
|
|
|
|
$location.path('/');
|
|
|
|
}
|
|
|
|
|
2014-08-14 15:46:42 -07:00
|
|
|
$scope.open = function(form) {
|
|
|
|
if (form && form.$invalid) {
|
|
|
|
notification.error('Error', 'Please enter the required fields');
|
|
|
|
return;
|
|
|
|
}
|
2014-07-23 13:10:02 -07:00
|
|
|
|
2014-08-14 15:46:42 -07:00
|
|
|
$scope.loading = true;
|
|
|
|
var password = form.openPassword.$modelValue;
|
2014-07-23 13:10:02 -07:00
|
|
|
|
2014-08-14 15:46:42 -07:00
|
|
|
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;
|
|
|
|
}
|
2014-08-19 12:37:37 -07:00
|
|
|
$rootScope.updatingBalance = true;
|
2014-08-14 15:46:42 -07:00
|
|
|
controllerUtils.startNetwork(w, $scope);
|
|
|
|
});
|
|
|
|
};
|
2014-07-23 13:10:02 -07:00
|
|
|
|
2014-08-14 15:46:42 -07:00
|
|
|
});
|