diff --git a/public/js/controllers/header.js b/public/js/controllers/header.js index 8b3b4f7e..ec3e878d 100755 --- a/public/js/controllers/header.js +++ b/public/js/controllers/header.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('insight.system').controller('HeaderController', - function ($scope, Global) { + function ($scope, get_socket, Global, Block) { $scope.global = Global; $scope.menu = [ @@ -15,5 +15,23 @@ angular.module('insight.system').controller('HeaderController', } ]; + var socket = get_socket($scope); + socket.emit('subscribe', 'inv'); + + var getBlock = function(hash) { + Block.get({ + blockHash: hash + }, function(res) { + $scope.totalBlocks = res.height; + }); + }; + + socket.on('block', function(block) { + var blockHash = block.hash.toString(); + console.log('Update Height'); + getBlock(blockHash); + }); + + $scope.isCollapsed = false; }); diff --git a/public/js/controllers/index.js b/public/js/controllers/index.js index bd1cdcdb..7621cbff 100755 --- a/public/js/controllers/index.js +++ b/public/js/controllers/index.js @@ -3,9 +3,25 @@ var TRANSACTION_DISPLAYED = 5; var BLOCKS_DISPLAYED = 5; angular.module('insight.system').controller('IndexController', - function($scope, $rootScope, Global, get_socket, Blocks, Transactions) { + function($scope, $rootScope, Global, get_socket, Blocks, Block, Transactions, Transaction) { $scope.global = Global; + var getTransaction = function(txid) { + Transaction.get({ + txId: txid + }, function(res) { + $scope.txs.unshift(res); + }); + }; + + var getBlock = function(hash) { + Block.get({ + blockHash: hash + }, function(res) { + $scope.blocks.unshift(res); + }); + }; + var socket = get_socket($scope); socket.emit('subscribe', 'inv'); @@ -13,19 +29,21 @@ angular.module('insight.system').controller('IndexController', $scope.flashMessage = $rootScope.flashMessage || null; socket.on('tx', function(tx) { + var txStr = tx.txid.toString(); console.log('Transaction received! ' + JSON.stringify(tx)); if ($scope.txs.length === TRANSACTION_DISPLAYED) { $scope.txs.pop(); } - $scope.txs.unshift(tx); + getTransaction(txStr); }); socket.on('block', function(block) { + var blockHash = block.hash.toString(); console.log('Block received! ' + JSON.stringify(block)); - if ($scope.blocks.length === BLOCKS_DISPLAYED) { - $scope.blocks.pop(); - } - $scope.blocks.unshift(block); + if ($scope.blocks.length === BLOCKS_DISPLAYED) { + $scope.blocks.pop(); + } + getBlock(blockHash); }); $scope.human_since = function(time) { @@ -38,6 +56,7 @@ angular.module('insight.system').controller('IndexController', limit: BLOCKS_DISPLAYED }, function(res) { $scope.blocks = res.blocks; + $scope.blocksLength = res.lenght; }); Transactions.get({ diff --git a/public/views/blocks/list.html b/public/views/blocks/list.html index abdcf856..40b90fc7 100644 --- a/public/views/blocks/list.html +++ b/public/views/blocks/list.html @@ -11,33 +11,47 @@

{{pagination.current}}

- ← {{pagination.prev}} + ← {{pagination.prev}} {{pagination.next}} →
-
+
- +
- - + + + + + - - - + + + + + + +
HashSolved atHeightTimestampTransactionsSizeConfirmations
{{block.hash}}{{block.time * 1000 | date:'medium'}}
Waiting for blocks...
+ {{b.height}} + {{b.time * 1000 | date:'medium'}}{{b.tx.length}}{{b.size}}{{b.confirmations}}
+

No blocks yet.

diff --git a/public/views/header.html b/public/views/header.html index baf6f772..b9f2a51c 100755 --- a/public/views/header.html +++ b/public/views/header.html @@ -35,7 +35,7 @@ Conn: {{info.connections}} - Height: {{info.blocks}} + Height: {{totalBlocks || info.blocks}} diff --git a/public/views/index.html b/public/views/index.html index 7ae3dda1..6a3fdf13 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -17,7 +17,7 @@ - Loading... + Waiting for blocks... {{b.height}} @@ -29,7 +29,6 @@ -
@@ -45,7 +44,7 @@ - Loading... + Waiting for transactions... {{tx.txid}}