From db462b13c228c368a8390a932c6ba0cf5b2edb12 Mon Sep 17 00:00:00 2001 From: cubedro Date: Mon, 1 Jun 2015 23:02:32 +0300 Subject: [PATCH] added block method for socket --- src/js/controllers.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/js/controllers.js b/src/js/controllers.js index b4ec7b8..2daa24b 100644 --- a/src/js/controllers.js +++ b/src/js/controllers.js @@ -181,6 +181,32 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr) break; + case "block": + var index = findIndex({id: data.id}); + + if( index >= 0 && !_.isUndefined($scope.nodes[index]) && !_.isUndefined($scope.nodes[index].stats) ) + { + if( $scope.nodes[index].stats.block.number < data.block.number ) + { + var best = _.max($scope.nodes, function (node) { + return parseInt(node.stats.block.number); + }).stats.block; + + if (data.block.number > best.number) { + data.block.arrived = _.now(); + } else { + data.block.arrived = best.arrived; + } + + $scope.nodes[index].history = data.history; + } + + $scope.nodes[index].stats.block = data.block; + $scope.nodes[index].stats.propagationAvg = data.propagationAvg; + } + + break; + case "pending": var index = findIndex({id: data.id});