2014-07-23 13:10:02 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('OpenController',
|
2014-08-04 07:27:46 -07:00
|
|
|
function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase, notification) {
|
2014-08-06 14:41:37 -07:00
|
|
|
controllerUtils.redirIfLogged();
|
2014-08-04 07:27:46 -07:00
|
|
|
|
2014-07-23 13:10:02 -07:00
|
|
|
var cmp = function(o1, o2) {
|
|
|
|
var v1 = o1.show.toLowerCase(),
|
|
|
|
v2 = o2.show.toLowerCase();
|
|
|
|
return v1 > v2 ? 1 : (v1 < v2) ? -1 : 0;
|
|
|
|
};
|
2014-08-06 14:21:14 -07:00
|
|
|
$rootScope.fromSetup = false;
|
2014-07-23 13:10:02 -07:00
|
|
|
$scope.loading = false;
|
|
|
|
$scope.wallets = walletFactory.getWallets().sort(cmp);
|
2014-08-04 11:10:01 -07:00
|
|
|
$scope.selectedWalletId = walletFactory.storage.getLastOpened() || ($scope.wallets[0] && $scope.wallets[0].id);
|
2014-07-23 13:10:02 -07:00
|
|
|
$scope.openPassword = '';
|
2014-08-15 11:47:13 -07:00
|
|
|
$scope.isMobile = !!window.cordova;
|
2014-07-23 13:10:02 -07:00
|
|
|
|
|
|
|
$scope.open = function(form) {
|
|
|
|
if (form && form.$invalid) {
|
|
|
|
notification.error('Error', 'Please enter the required fields');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.loading = true;
|
|
|
|
var password = form.openPassword.$modelValue;
|
|
|
|
|
|
|
|
Passphrase.getBase64Async(password, function(passphrase) {
|
|
|
|
var w, errMsg;
|
|
|
|
try {
|
2014-08-06 14:07:01 -07:00
|
|
|
w = walletFactory.open($scope.selectedWalletId, {
|
2014-07-23 13:10:02 -07:00
|
|
|
passphrase: passphrase
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
errMsg = e.message;
|
|
|
|
};
|
|
|
|
if (!w) {
|
|
|
|
$scope.loading = false;
|
|
|
|
notification.error('Error', errMsg || 'Wrong password');
|
|
|
|
$rootScope.$digest();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
controllerUtils.startNetwork(w, $scope);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|