Cleaning controllers. Also call connect socket-ii in all pages. Everything work!
This commit is contained in:
parent
5d83d180da
commit
8ab479691d
6 changed files with 68 additions and 46 deletions
|
|
@ -1,13 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.backup').controller('BackupController',
|
||||
function($scope, $rootScope, $location) {
|
||||
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||
|
||||
|
||||
if (!$rootScope.wallet.id) {
|
||||
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||
$location.path('signin');
|
||||
}
|
||||
|
||||
else {
|
||||
var socket = Socket($scope);
|
||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||
}
|
||||
|
||||
$scope.title = 'Backup';
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.home').controller('HomeController',
|
||||
function($scope, $rootScope, $location) {
|
||||
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||
$scope.title = 'Home';
|
||||
|
||||
$scope.oneAtATime = true;
|
||||
$scope.addrBalance = {};
|
||||
|
||||
|
||||
var _getBalance = function() {
|
||||
$scope.addrs.forEach(function(addr) {
|
||||
$rootScope.wallet.blockchain.listUnspent([addr], function(unspent) {
|
||||
|
|
@ -24,6 +24,9 @@ angular.module('copay.home').controller('HomeController',
|
|||
$scope.selectedAddr = $scope.addrs[0];
|
||||
|
||||
_getBalance();
|
||||
|
||||
var socket = Socket($scope);
|
||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||
}
|
||||
|
||||
$scope.newAddr = function() {
|
||||
|
|
@ -31,6 +34,8 @@ angular.module('copay.home').controller('HomeController',
|
|||
$scope.addrs.push(a);
|
||||
|
||||
_getBalance();
|
||||
var socket = Socket($scope);
|
||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||
};
|
||||
|
||||
$scope.selectAddr = function(addr) {
|
||||
|
|
|
|||
|
|
@ -1,31 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.peer').controller('PeerController',
|
||||
function($scope, $rootScope, $location, $routeParams, Socket) {
|
||||
function($scope, $rootScope, $location, $routeParams, Socket, controllerUtils) {
|
||||
|
||||
$scope.init = function() {
|
||||
//Network.connect($rootScope.masterId);
|
||||
};
|
||||
|
||||
var socket = Socket($scope);
|
||||
socket.on('connect', function() {
|
||||
var addrs = $rootScope.wallet.getAddressesStr();
|
||||
socket.emit('subscribe', 'inv');
|
||||
for(var i=0;i<addrs.length;i++) {
|
||||
socket.emit('subscribe', addrs[i]);
|
||||
}
|
||||
addrs.forEach(function(addr) {
|
||||
socket.on(addr, function(txid) {
|
||||
console.log('Received!', txid);
|
||||
$rootScope.wallet.getBalance(function(balance) {
|
||||
$scope.$apply(function() {
|
||||
$rootScope.totalBalance = balance;
|
||||
});
|
||||
console.log('New balance:', balance);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||
$location.path('signin');
|
||||
}
|
||||
else {
|
||||
var socket = Socket($scope);
|
||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.send').controller('SendController',
|
||||
function($scope, $rootScope, $location) {
|
||||
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||
$scope.title = 'Send';
|
||||
|
||||
if (!$rootScope.wallet.id) {
|
||||
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||
$location.path('signin');
|
||||
}
|
||||
|
||||
else {
|
||||
var socket = Socket($scope);
|
||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||
|
||||
}
|
||||
|
||||
$scope.sendTest = function() {
|
||||
var w = $rootScope.wallet;
|
||||
|
|
|
|||
|
|
@ -1,29 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.transactions').controller('TransactionsController',
|
||||
function($scope, $rootScope, $location) {
|
||||
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||
$scope.title = 'Transactions';
|
||||
|
||||
$scope.oneAtATime = true;
|
||||
|
||||
if (!$rootScope.wallet.id) {
|
||||
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||
$location.path('signin');
|
||||
}
|
||||
else {
|
||||
$scope.txsinput = [
|
||||
{
|
||||
fromAddr: "n3zUqNR7Bbbc4zJhPVj1vG2Lx66K3Xhzvb",
|
||||
toAddr: "msvv2mDfE298s7boXwALq4Dqv77K3TWRZ1",
|
||||
amount: 23.9982
|
||||
},
|
||||
{
|
||||
fromAddr: "my9wnLwwUrwpNfEgSrWY62ymEGf1edKf4J",
|
||||
toAddr: "monCusNiDuptf68rtr58hEjKpJt6cW6zwS",
|
||||
amount: 2.22
|
||||
}
|
||||
];
|
||||
|
||||
$scope.txsinput = [
|
||||
{
|
||||
fromAddr: "n3zUqNR7Bbbc4zJhPVj1vG2Lx66K3Xhzvb",
|
||||
toAddr: "msvv2mDfE298s7boXwALq4Dqv77K3TWRZ1",
|
||||
amount: 23.9982
|
||||
},
|
||||
{
|
||||
fromAddr: "my9wnLwwUrwpNfEgSrWY62ymEGf1edKf4J",
|
||||
toAddr: "monCusNiDuptf68rtr58hEjKpJt6cW6zwS",
|
||||
amount: 2.22
|
||||
$scope.txsoutput = $rootScope.wallet.getTxProposals();
|
||||
|
||||
var socket = Socket($scope);
|
||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||
}
|
||||
];
|
||||
|
||||
$scope.txsoutput = $rootScope.wallet.getTxProposals();
|
||||
|
||||
$scope.sign = function (ntxid) {
|
||||
var w = $rootScope.wallet;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.controllerUtils').factory('controllerUtils', function ($rootScope, $location) {
|
||||
angular.module('copay.controllerUtils').factory('controllerUtils', function ($rootScope, $location, Socket) {
|
||||
var root = {};
|
||||
root.setupUxHandlers = function(w) {
|
||||
w.on('created', function() {
|
||||
|
|
@ -24,6 +24,26 @@ angular.module('copay.controllerUtils').factory('controllerUtils', function ($ro
|
|||
});
|
||||
};
|
||||
|
||||
root.handleTransactionByAddress = function(scope) {
|
||||
var socket = Socket(scope);
|
||||
var addrs = $rootScope.wallet.getAddressesStr();
|
||||
socket.emit('subscribe', 'inv');
|
||||
for(var i=0;i<addrs.length;i++) {
|
||||
socket.emit('subscribe', addrs[i]);
|
||||
}
|
||||
addrs.forEach(function(addr) {
|
||||
socket.on(addr, function(txid) {
|
||||
console.log('Received!', txid);
|
||||
$rootScope.wallet.getBalance(function(balance) {
|
||||
scope.$apply(function() {
|
||||
$rootScope.totalBalance = balance;
|
||||
});
|
||||
console.log('New balance:', balance);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue