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}}
-| Hash | -Solved at | +Height | +Timestamp | +Transactions | +Size | +Confirmations |
|---|---|---|---|---|---|---|
| {{block.hash}} | -{{block.time * 1000 | date:'medium'}} | +|||||
| Waiting for blocks... | ||||||
| + {{b.height}} + | +{{b.time * 1000 | date:'medium'}} | +{{b.tx.length}} | +{{b.size}} | +{{b.confirmations}} | ||