2014-03-27 16:31:42 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2014-03-28 14:08:14 -04:00
|
|
|
angular.module('copay.signin').controller('SigninController',
|
2014-04-17 11:46:49 -03:00
|
|
|
function($scope, $rootScope, $location, walletFactory, controllerUtils) {
|
2014-03-31 12:48:35 -03:00
|
|
|
$scope.loading = false;
|
2014-04-24 16:35:52 -03:00
|
|
|
$scope.wallets = walletFactory.getWallets();
|
|
|
|
|
$scope.selectedWalletId = $scope.wallets.length ? $scope.wallets[0].id : null;
|
2014-04-09 02:20:28 -03:00
|
|
|
|
2014-04-30 16:11:55 -03:00
|
|
|
$scope.create = function(walletName) {
|
2014-04-24 22:43:19 -03:00
|
|
|
$scope.loading = true;
|
2014-04-30 16:11:55 -03:00
|
|
|
$rootScope.walletName = walletName;
|
2014-04-16 19:45:22 -03:00
|
|
|
$location.path('setup');
|
2014-04-16 17:50:10 -03:00
|
|
|
};
|
2014-04-15 15:25:55 -03:00
|
|
|
|
2014-04-18 18:25:51 -03:00
|
|
|
$scope.open = function(walletId, opts) {
|
2014-04-16 17:50:10 -03:00
|
|
|
$scope.loading = true;
|
2014-04-18 18:25:51 -03:00
|
|
|
var w = walletFactory.open(walletId, opts);
|
2014-04-24 23:13:55 -03:00
|
|
|
controllerUtils.startNetwork(w);
|
2014-04-09 02:20:28 -03:00
|
|
|
};
|
|
|
|
|
|
2014-04-20 12:41:28 -03:00
|
|
|
$scope.join = function(secret) {
|
2014-04-24 16:35:52 -03:00
|
|
|
if (!secret || secret.length !==66 || !secret.match(/^[0-9a-f]*$/) ) {
|
|
|
|
|
$rootScope.flashMessage = { message: 'Bad secret secret string', type: 'error'};
|
2014-04-21 12:10:34 -03:00
|
|
|
return;
|
|
|
|
|
}
|
2014-03-31 12:48:35 -03:00
|
|
|
$scope.loading = true;
|
2014-04-20 12:41:28 -03:00
|
|
|
|
|
|
|
|
walletFactory.network.on('joinError', function() {
|
|
|
|
|
controllerUtils.onErrorDigest($scope);
|
2014-04-17 16:27:15 -03:00
|
|
|
});
|
2014-04-20 12:41:28 -03:00
|
|
|
|
|
|
|
|
walletFactory.joinCreateSession(secret, function(w) {
|
2014-04-24 23:13:55 -03:00
|
|
|
if (w) {
|
|
|
|
|
controllerUtils.startNetwork(w);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$scope.loading = false;
|
|
|
|
|
controllerUtils.onErrorDigest();
|
|
|
|
|
}
|
2014-04-16 20:58:57 -03:00
|
|
|
});
|
|
|
|
|
};
|
2014-03-27 16:31:42 -03:00
|
|
|
});
|