integrate new name and header. Signin/signout flow
This commit is contained in:
parent
28247a87c6
commit
4cd48b7bb2
12 changed files with 130 additions and 74 deletions
|
|
@ -11,7 +11,7 @@ angular.module('copay',[
|
|||
'copay.backup',
|
||||
'copay.network',
|
||||
'copay.signin',
|
||||
'copay.join'
|
||||
'copay.peer'
|
||||
]);
|
||||
|
||||
angular.module('copay.header', []);
|
||||
|
|
@ -21,5 +21,5 @@ angular.module('copay.send', []);
|
|||
angular.module('copay.backup', []);
|
||||
angular.module('copay.network', []);
|
||||
angular.module('copay.signin', []);
|
||||
angular.module('copay.join', []);
|
||||
angular.module('copay.peer', []);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ angular
|
|||
.when('/join/:id', {
|
||||
templateUrl: 'join.html'
|
||||
})
|
||||
.when('/peer', {
|
||||
templateUrl: 'peer.html'
|
||||
})
|
||||
.when('/transactions', {
|
||||
templateUrl: 'transactions.html'
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.header').controller('HeaderController',
|
||||
function($scope, $rootScope, $location) {
|
||||
function($scope, $rootScope, $location, Network) {
|
||||
$scope.menu = [{
|
||||
'title': 'Home',
|
||||
'link': '#/'
|
||||
'link': '#/home'
|
||||
}, {
|
||||
'title': 'Transactions',
|
||||
'link': '#/transactions'
|
||||
|
|
@ -16,6 +16,10 @@ angular.module('copay.header').controller('HeaderController',
|
|||
'link': '#/backup'
|
||||
}];
|
||||
|
||||
if (!$rootScope.peerId) {
|
||||
$location.path('signin');
|
||||
}
|
||||
|
||||
$scope.isActive = function(item) {
|
||||
if (item.link.replace('#','') == $location.path()) {
|
||||
return true;
|
||||
|
|
@ -29,7 +33,7 @@ angular.module('copay.header').controller('HeaderController',
|
|||
|
||||
$scope.signout = function() {
|
||||
$rootScope.isLogged = false;
|
||||
|
||||
Network.disconnect();
|
||||
$location.path('signin');
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ angular.module('copay.home').controller('HomeController',
|
|||
|
||||
$scope.oneAtATime = true;
|
||||
|
||||
if (!$rootScope.peerId) {
|
||||
$location.path('signin');
|
||||
}
|
||||
|
||||
$scope.addrs = [
|
||||
{ addrStr: 'n3zUqNR7Bbbc4zJhPVj1vG2Lx66K3Xhzvb'},
|
||||
{ addrStr: 'my9wnLwwUrwpNfEgSrWY62ymEGf1edKf4J'}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.join').controller('JoinController',
|
||||
function($scope, $rootScope, $routeParams, Network) {
|
||||
|
||||
$scope.connectionId = $routeParams.id;
|
||||
$scope.copayers = [];
|
||||
|
||||
$scope.init = function() {
|
||||
console.log('-------- init --------');
|
||||
console.log($rootScope.peerId);
|
||||
$scope.copayers.push($rootScope.peerId);
|
||||
|
||||
Network.connect($scope.connectionId, function(copayer) {
|
||||
console.log('----- join connect --------');
|
||||
console.log(copayer);
|
||||
$scope.copayers.push(copayer);
|
||||
$scope.$digest();
|
||||
});
|
||||
};
|
||||
});
|
||||
13
js/controllers/peer.js
Normal file
13
js/controllers/peer.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.peer').controller('PeerController',
|
||||
function($scope, $rootScope, $location, $routeParams, Network) {
|
||||
|
||||
$scope.init = function() {
|
||||
Network.connect($rootScope.connectionId, function(copayer) {
|
||||
console.log(copayer);
|
||||
console.log($rootScope.copayers);
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
|
|
@ -3,4 +3,9 @@
|
|||
angular.module('copay.send').controller('SendController',
|
||||
function($scope, $rootScope, $location) {
|
||||
$scope.title = 'Send';
|
||||
|
||||
if (!$rootScope.peerId) {
|
||||
$location.path('signin');
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,23 +2,36 @@
|
|||
|
||||
angular.module('copay.signin').controller('SigninController',
|
||||
function($scope, $rootScope, $location, Network) {
|
||||
$scope.loading = false;
|
||||
$rootScope.peerId = null;
|
||||
$scope.peerReady = false;
|
||||
|
||||
// Init peer
|
||||
Network.init(function(pid) {
|
||||
$rootScope.peerId = pid;
|
||||
$rootScope.$digest();
|
||||
|
||||
$scope.peerReady = true;
|
||||
$scope.$digest();
|
||||
});
|
||||
$rootScope.copayers = [];
|
||||
|
||||
$scope.create = function() {
|
||||
$scope.loading = true;
|
||||
Network.init(function(pid) {
|
||||
$rootScope.copayers.push(pid);
|
||||
$location.path('peer');
|
||||
});
|
||||
};
|
||||
|
||||
$scope.join = function(cid) {
|
||||
console.log('------- join --------');
|
||||
console.log(cid);
|
||||
$scope.loading = true;
|
||||
$rootScope.connectionId = cid;
|
||||
Network.init(function(pid) {
|
||||
|
||||
console.log('------- join --------');
|
||||
console.log(pid);
|
||||
|
||||
$rootScope.copayers.push(pid);
|
||||
|
||||
Network.connect(cid, function(copayer) {
|
||||
console.log('----- join master --------');
|
||||
console.log(copayer);
|
||||
$rootScope.copayers.push(copayer);
|
||||
|
||||
$location.path('peer');
|
||||
});
|
||||
});
|
||||
|
||||
var pid = cid || $rootScope.peerId;
|
||||
$location.path('join/' + pid);
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ angular.module('copay.transactions').controller('TransactionsController',
|
|||
|
||||
$scope.oneAtATime = true;
|
||||
|
||||
if (!$rootScope.peerId) {
|
||||
$location.path('signin');
|
||||
}
|
||||
|
||||
$scope.txsinput = [
|
||||
{
|
||||
fromAddr: "n3zUqNR7Bbbc4zJhPVj1vG2Lx66K3Xhzvb",
|
||||
|
|
|
|||
|
|
@ -6,14 +6,15 @@ angular.module('copay.network')
|
|||
return 2;
|
||||
};
|
||||
})
|
||||
.factory('Network', function() {
|
||||
.factory('Network', function($rootScope) {
|
||||
var peer;
|
||||
var connectedPeers = {};
|
||||
|
||||
var _onConnect = function(c, cb) {
|
||||
if (c.label === 'wallet') {
|
||||
var a = peer.connections[c.peer][0];
|
||||
console.log(peer.connections[c.peer]);
|
||||
console.log(peer.connections[c.peer][0]);
|
||||
console.log(a);
|
||||
a.send('------ origin recived -------');
|
||||
|
||||
c.on('data', function(data) {
|
||||
|
|
@ -43,7 +44,12 @@ angular.module('copay.network')
|
|||
debug: 3
|
||||
});
|
||||
|
||||
peer.on('open', cb);
|
||||
peer.on('open', function() {
|
||||
$rootScope.peerId = peer.id;
|
||||
$rootScope.peerReady = true;
|
||||
cb(peer.id);
|
||||
$rootScope.$digest();
|
||||
});
|
||||
};
|
||||
|
||||
var _connect = function(pid, cb) {
|
||||
|
|
@ -59,17 +65,18 @@ angular.module('copay.network')
|
|||
});
|
||||
|
||||
c.on('open', function() {
|
||||
c.send('-------oopen-------');
|
||||
c.send('-------open-------');
|
||||
});
|
||||
|
||||
c.on('data', function(data) {
|
||||
if (data)
|
||||
console.log(data);
|
||||
console.log('Data:' + data);
|
||||
});
|
||||
|
||||
c.on('error', function(err) {
|
||||
console.error(err);
|
||||
});
|
||||
cb(c.peer);
|
||||
};
|
||||
|
||||
var _sendTo = function(pid, data) {
|
||||
|
|
@ -81,10 +88,17 @@ angular.module('copay.network')
|
|||
console.log(data);
|
||||
};
|
||||
|
||||
var _disconnect = function() {
|
||||
peer.disconnect();
|
||||
peer.destroy();
|
||||
console.log('Disconnected and destroyed connection');
|
||||
}
|
||||
|
||||
return {
|
||||
init: _init,
|
||||
connect: _connect,
|
||||
sendTo: _sendTo
|
||||
sendTo: _sendTo,
|
||||
disconnect: _disconnect
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue