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';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.backup').controller('BackupController',
|
angular.module('copay.backup').controller('BackupController',
|
||||||
function($scope, $rootScope, $location) {
|
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||||
|
|
||||||
|
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||||
if (!$rootScope.wallet.id) {
|
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
var socket = Socket($scope);
|
||||||
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
|
}
|
||||||
|
|
||||||
$scope.title = 'Backup';
|
$scope.title = 'Backup';
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.home').controller('HomeController',
|
angular.module('copay.home').controller('HomeController',
|
||||||
function($scope, $rootScope, $location) {
|
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||||
$scope.title = 'Home';
|
$scope.title = 'Home';
|
||||||
|
|
||||||
$scope.oneAtATime = true;
|
$scope.oneAtATime = true;
|
||||||
$scope.addrBalance = {};
|
$scope.addrBalance = {};
|
||||||
|
|
||||||
var _getBalance = function() {
|
var _getBalance = function() {
|
||||||
$scope.addrs.forEach(function(addr) {
|
$scope.addrs.forEach(function(addr) {
|
||||||
$rootScope.wallet.blockchain.listUnspent([addr], function(unspent) {
|
$rootScope.wallet.blockchain.listUnspent([addr], function(unspent) {
|
||||||
|
|
@ -24,6 +24,9 @@ angular.module('copay.home').controller('HomeController',
|
||||||
$scope.selectedAddr = $scope.addrs[0];
|
$scope.selectedAddr = $scope.addrs[0];
|
||||||
|
|
||||||
_getBalance();
|
_getBalance();
|
||||||
|
|
||||||
|
var socket = Socket($scope);
|
||||||
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.newAddr = function() {
|
$scope.newAddr = function() {
|
||||||
|
|
@ -31,6 +34,8 @@ angular.module('copay.home').controller('HomeController',
|
||||||
$scope.addrs.push(a);
|
$scope.addrs.push(a);
|
||||||
|
|
||||||
_getBalance();
|
_getBalance();
|
||||||
|
var socket = Socket($scope);
|
||||||
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.selectAddr = function(addr) {
|
$scope.selectAddr = function(addr) {
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,18 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.peer').controller('PeerController',
|
angular.module('copay.peer').controller('PeerController',
|
||||||
function($scope, $rootScope, $location, $routeParams, Socket) {
|
function($scope, $rootScope, $location, $routeParams, Socket, controllerUtils) {
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
//Network.connect($rootScope.masterId);
|
//Network.connect($rootScope.masterId);
|
||||||
};
|
};
|
||||||
|
|
||||||
var socket = Socket($scope);
|
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||||
socket.on('connect', function() {
|
$location.path('signin');
|
||||||
var addrs = $rootScope.wallet.getAddressesStr();
|
}
|
||||||
socket.emit('subscribe', 'inv');
|
else {
|
||||||
for(var i=0;i<addrs.length;i++) {
|
var socket = Socket($scope);
|
||||||
socket.emit('subscribe', addrs[i]);
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.send').controller('SendController',
|
angular.module('copay.send').controller('SendController',
|
||||||
function($scope, $rootScope, $location) {
|
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||||
$scope.title = 'Send';
|
$scope.title = 'Send';
|
||||||
|
|
||||||
if (!$rootScope.wallet.id) {
|
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
var socket = Socket($scope);
|
||||||
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$scope.sendTest = function() {
|
$scope.sendTest = function() {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,33 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.transactions').controller('TransactionsController',
|
angular.module('copay.transactions').controller('TransactionsController',
|
||||||
function($scope, $rootScope, $location) {
|
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||||
$scope.title = 'Transactions';
|
$scope.title = 'Transactions';
|
||||||
|
|
||||||
$scope.oneAtATime = true;
|
$scope.oneAtATime = true;
|
||||||
|
|
||||||
if (!$rootScope.wallet.id) {
|
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$scope.txsinput = [
|
||||||
|
{
|
||||||
|
fromAddr: "n3zUqNR7Bbbc4zJhPVj1vG2Lx66K3Xhzvb",
|
||||||
|
toAddr: "msvv2mDfE298s7boXwALq4Dqv77K3TWRZ1",
|
||||||
|
amount: 23.9982
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fromAddr: "my9wnLwwUrwpNfEgSrWY62ymEGf1edKf4J",
|
||||||
|
toAddr: "monCusNiDuptf68rtr58hEjKpJt6cW6zwS",
|
||||||
|
amount: 2.22
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
$scope.txsinput = [
|
$scope.txsoutput = $rootScope.wallet.getTxProposals();
|
||||||
{
|
|
||||||
fromAddr: "n3zUqNR7Bbbc4zJhPVj1vG2Lx66K3Xhzvb",
|
var socket = Socket($scope);
|
||||||
toAddr: "msvv2mDfE298s7boXwALq4Dqv77K3TWRZ1",
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
amount: 23.9982
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fromAddr: "my9wnLwwUrwpNfEgSrWY62ymEGf1edKf4J",
|
|
||||||
toAddr: "monCusNiDuptf68rtr58hEjKpJt6cW6zwS",
|
|
||||||
amount: 2.22
|
|
||||||
}
|
}
|
||||||
];
|
|
||||||
|
|
||||||
$scope.txsoutput = $rootScope.wallet.getTxProposals();
|
|
||||||
|
|
||||||
$scope.sign = function (ntxid) {
|
$scope.sign = function (ntxid) {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.controllerUtils').factory('controllerUtils', function ($rootScope, $location) {
|
angular.module('copay.controllerUtils').factory('controllerUtils', function ($rootScope, $location, Socket) {
|
||||||
var root = {};
|
var root = {};
|
||||||
root.setupUxHandlers = function(w) {
|
root.setupUxHandlers = function(w) {
|
||||||
w.on('created', function() {
|
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;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue