copay/js/controllers/signin.js

80 lines
2.1 KiB
JavaScript
Raw Normal View History

'use strict';
angular.module('copay.signin').controller('SigninController',
2014-04-16 13:50:10 -07:00
function($scope, $rootScope, $location, walletFactory) {
2014-04-01 14:22:07 -07:00
2014-04-15 08:17:28 -07:00
// var peerData = Storage.get($rootScope.walletId, 'peerData');
// $rootScope.peerId = peerData ? peerData.peerId : null;
$scope.loading = false;
2014-04-15 11:25:55 -07:00
$scope.selectedWalletId = false;
$scope.listWalletIds = function() {
2014-04-16 13:50:10 -07:00
return walletFactory.getWalletIds();
};
2014-04-16 13:50:10 -07:00
var _setupUxHandlers = function(w) {
2014-04-16 15:18:19 -07:00
w.on('created', function(){
2014-04-01 14:22:07 -07:00
$location.path('peer');
2014-04-16 13:50:10 -07:00
$rootScope.wallet = w;
2014-04-08 14:35:43 -07:00
$rootScope.$digest();
});
2014-04-16 13:50:10 -07:00
w.on('openError', function(){
$scope.loading = false;
$rootScope.flashMessage = {type:'error', message: 'Wallet not found'};
$location.path('signin');
});
};
2014-04-16 13:50:10 -07:00
$scope.create = function() {
console.log('[signin.js.42:create:]'); //TODO
$scope.loading = true;
2014-04-15 11:25:55 -07:00
2014-04-16 13:50:10 -07:00
var w = walletFactory.create();
_setupUxHandlers(w);
w.netStart();
};
2014-04-15 11:25:55 -07:00
2014-04-16 13:50:10 -07:00
$scope.open = function(walletId) {
$scope.loading = true;
var w = walletFactory.open(walletId);
_setupUxHandlers(w);
w.netStart();
};
$scope.join = function(cid) {
2014-04-16 13:50:10 -07:00
console.log('[signin.js.42:join:]'); //TODO
$scope.loading = true;
2014-04-16 16:58:57 -07:00
walletFactory.connectTo(cid, function(w) {
console.log('[signin.js.50]'); //TODO
_setupUxHandlers(w);
w.netStart();
});
};
2014-04-16 15:14:58 -07:00
//
// if (cid) {
// var w = walletFactory.(walletId);
//TODO
// Network.init(null, function() {
// Network.connect(cid,
// function() {
// $location.path('peer');
// $rootScope.$digest();
// }, function() {
// $rootScope.flashMessage = { message: 'Connection refussed', type: 'error'};
// $location.path('home');
// $rootScope.$digest();
// });
// });
// }
2014-04-01 14:22:07 -07:00
2014-04-15 08:17:28 -07:00
// if (peerData && peerData.peerId && peerData.connectedPeers.length > 0) {
// $rootScope.peerId = peerData.peerId;
// $scope.join(peerData.connectedPeers);
// }
});
2014-04-01 14:22:07 -07:00