diff --git a/index.html b/index.html index 4a0457bc2..3fe435694 100644 --- a/index.html +++ b/index.html @@ -211,7 +211,7 @@

Address

- {{addr}} {{balanceByAddr[addr] || 0}} BTC > + {{addr}} {{$root.balanceByAddr[addr] || 0}} BTC >
diff --git a/js/controllers/backup.js b/js/controllers/backup.js index 309da15dc..5c468fe24 100644 --- a/js/controllers/backup.js +++ b/js/controllers/backup.js @@ -1,9 +1,7 @@ 'use strict'; angular.module('copay.backup').controller('BackupController', - function($scope, $rootScope, $location, $window, $timeout, Socket, controllerUtils) { - controllerUtils.handleTransactionByAddress($scope); - + function($scope, $rootScope, $location, $window, $timeout) { $scope.title = 'Backup'; var filename = $rootScope.wallet.id + '.json.aes'; diff --git a/js/controllers/header.js b/js/controllers/header.js index 9919d11fd..36c67ebfd 100644 --- a/js/controllers/header.js +++ b/js/controllers/header.js @@ -24,6 +24,12 @@ angular.module('copay.header').controller('HeaderController', 'link': '#/backup' }]; + $rootScope.$watch('wallet', function(wallet) { + if (wallet) { + controllerUtils.setSocketHandlers(); + } + }); + $scope.isActive = function(item) { if (item.link && item.link.replace('#','') == $location.path()) { return true; diff --git a/js/controllers/home.js b/js/controllers/home.js index f103b200e..0fc8e2b3c 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copay.home').controller('HomeController', - function($scope, $rootScope, $location, Socket, controllerUtils) { + function($scope, $rootScope, controllerUtils) { $scope.title = 'Home'; $scope.oneAtATime = true; $scope.addrBalance = {}; @@ -10,18 +10,19 @@ angular.module('copay.home').controller('HomeController', var _updateBalance = function () { w.getBalance(function (balance, balanceByAddr) { - $scope.balanceByAddr = balanceByAddr; - $scope.addrs = Object.keys(balanceByAddr); - $scope.selectedAddr = $scope.addrs[0]; - $scope.$digest(); + $rootScope.$apply(function() { + $rootScope.balanceByAddr = balanceByAddr; + $scope.addrs = Object.keys(balanceByAddr); + $scope.selectedAddr = $scope.addrs[0]; + }); }); - var socket = Socket($scope); - controllerUtils.handleTransactionByAddress($scope, _updateBalance); }; $scope.newAddr = function() { - var a = w.generateAddress().toString(); + w.generateAddress().toString(); _updateBalance(); + + controllerUtils.setSocketHandlers(); }; $scope.selectAddr = function(addr) { diff --git a/js/controllers/peer.js b/js/controllers/peer.js index 5ce6125e1..5ae619020 100644 --- a/js/controllers/peer.js +++ b/js/controllers/peer.js @@ -1,7 +1,6 @@ 'use strict'; angular.module('copay.peer').controller('PeerController', - function($scope, $rootScope, $location, $routeParams, Socket, controllerUtils) { - controllerUtils.handleTransactionByAddress($scope); + function($scope, $rootScope, $location, $routeParams) { }); diff --git a/js/controllers/send.js b/js/controllers/send.js index 02cd74c37..5f1ea7267 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -1,11 +1,9 @@ 'use strict'; angular.module('copay.send').controller('SendController', - function($scope, $rootScope, $location, Socket, controllerUtils) { + function($scope, $rootScope, $location) { $scope.title = 'Send'; - controllerUtils.handleTransactionByAddress($scope); - $scope.sendTest = function() { var w = $rootScope.wallet; w.createTx( 'mimoZNLcP2rrMRgdeX5PSnR7AjCqQveZZ4', '12345',function() { diff --git a/js/controllers/setup.js b/js/controllers/setup.js index b13f96071..db18809c1 100644 --- a/js/controllers/setup.js +++ b/js/controllers/setup.js @@ -24,7 +24,7 @@ angular.module('copay.setup').controller('SetupController', $scope.$watch('totalCopayers', function(tc) { updateRCSelect(tc); - }) + }); $scope.create = function(totalCopayers, requiredCopayers) { $scope.loading = true; diff --git a/js/controllers/signin.js b/js/controllers/signin.js index 2d4e43e3d..2336c3238 100644 --- a/js/controllers/signin.js +++ b/js/controllers/signin.js @@ -2,15 +2,8 @@ angular.module('copay.signin').controller('SigninController', function($scope, $rootScope, $location, walletFactory, controllerUtils) { - -// var peerData = Storage.get($rootScope.walletId, 'peerData'); -// $rootScope.peerId = peerData ? peerData.peerId : null; -// - $scope.loading = false; - $scope.walletIds = walletFactory.getWalletIds(); - $scope.selectedWalletId = $scope.walletIds.length ? $scope.walletIds[0]:null; $scope.create = function() { @@ -25,39 +18,15 @@ angular.module('copay.signin').controller('SigninController', w.netStart(); }; - $scope.join = function(cid) { + $scope.join = function(peerId) { $scope.loading = true; walletFactory.network.on('openError', function() { controllerUtils.onError($scope); $rootScope.$digest(); }); - walletFactory.connectTo(cid, function(w) { + walletFactory.connectTo(peerId, function(w) { controllerUtils.setupUxHandlers(w); w.netStart(); }); }; - - -// -// 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(); - // }); - // }); -// } - - // if (peerData && peerData.peerId && peerData.connectedPeers.length > 0) { - // $rootScope.peerId = peerData.peerId; - // $scope.join(peerData.connectedPeers); - // } }); - diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index 639890105..44ca586d7 100644 --- a/js/controllers/transactions.js +++ b/js/controllers/transactions.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copay.transactions').controller('TransactionsController', - function($scope, $rootScope, $location, Socket, controllerUtils) { + function($scope, $rootScope, $location) { $scope.title = 'Transactions'; $scope.oneAtATime = true; @@ -35,8 +35,6 @@ angular.module('copay.transactions').controller('TransactionsController', }; _updateTxs(); - var socket = Socket($scope); - socket.on('connect', controllerUtils.handleTransactionByAddress($scope)); $scope.sign = function (ntxid) { var w = $rootScope.wallet; diff --git a/js/routes.js b/js/routes.js index 6bca7f6a1..fa17d4077 100644 --- a/js/routes.js +++ b/js/routes.js @@ -7,31 +7,40 @@ angular $routeProvider .when('/', { - templateUrl: 'signin.html' + templateUrl: 'signin.html', + validate: false }) .when('/signin', { - templateUrl: 'signin.html' + templateUrl: 'signin.html', + validate: false }) .when('/setup', { - templateUrl: 'setup.html' + templateUrl: 'setup.html', + validate: false }) .when('/home', { - templateUrl: 'home.html' + templateUrl: 'home.html', + validate: true }) .when('/join/:id', { - templateUrl: 'join.html' + templateUrl: 'join.html', + validate: true }) .when('/peer', { - templateUrl: 'peer.html' + templateUrl: 'peer.html', + validate: true }) .when('/transactions', { - templateUrl: 'transactions.html' + templateUrl: 'transactions.html', + validate: true }) .when('/send', { - templateUrl: 'send.html' + templateUrl: 'send.html', + validate: true }) .when('/backup', { - templateUrl: 'backup.html' + templateUrl: 'backup.html', + validate: true }) .otherwise({ templateUrl: '404.html' @@ -47,9 +56,8 @@ angular //.hashPrefix('!'); }) .run(function($rootScope, $location) { - $rootScope.$on('$routeChangeStart', function() { - if (!$rootScope.wallet || !$rootScope.wallet.id) { - console.log('############ no wallet'); + $rootScope.$on('$routeChangeStart', function(event, next, current) { + if ((!$rootScope.wallet || !$rootScope.wallet.id) && next.validate) { $location.path('signin'); } }); diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index c3ffd373b..b208cef7a 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -21,9 +21,7 @@ angular.module('copay.controllerUtils').factory('controllerUtils', function ($ro $rootScope.$digest(); } - root.setupUxHandlers = function(w) { - w.on('badMessage', function(peerId) { $rootScope.flashMessage = {type:'error', message: 'Received wrong message from peer id:' + peerId}; }); @@ -45,19 +43,24 @@ angular.module('copay.controllerUtils').factory('controllerUtils', function ($ro w.on('close', root.onErrorDigest); }; - root.handleTransactionByAddress = function(scope, cb) { - var socket = Socket(scope); + root.setSocketHandlers = function(cb) { + Socket.removeAllListeners(); + var addrs = $rootScope.wallet.getAddressesStr(); - for(var i=0;i