insight-ui-zcash/public/js/controllers/index.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2014-01-06 12:34:25 -08:00
'use strict';
2014-01-14 14:42:38 -08:00
var TRANSACTION_DISPLAYED = 5;
var BLOCKS_DISPLAYED = 5;
2014-01-15 08:07:07 -08:00
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', 'socket', 'Blocks', 'Transactions', function($scope, Global, socket, Blocks, Transactions) {
2014-01-06 13:01:23 -08:00
$scope.global = Global;
2014-01-15 07:44:17 -08:00
socket.on('tx', function(tx) {
2014-01-15 04:38:27 -08:00
console.log('Transaction received! ' + JSON.stringify(tx));
2014-01-14 14:42:38 -08:00
if ($scope.txs.length === TRANSACTION_DISPLAYED) {
$scope.txs.pop();
}
$scope.txs.unshift(tx);
});
2014-01-15 07:44:17 -08:00
socket.on('block', function(block) {
2014-01-15 04:38:27 -08:00
console.log('Block received! ' + JSON.stringify(block));
2014-01-14 14:42:38 -08:00
if ($scope.blocks.length === BLOCKS_DISPLAYED) {
$scope.blocks.pop();
}
$scope.blocks.unshift(block);
2014-01-13 13:13:41 -08:00
});
2014-01-15 07:44:17 -08:00
$scope.index = function() {
Blocks.get({
limit: BLOCKS_DISPLAYED
}, function(res) {
$scope.blocks = res.blocks;
});
Transactions.query({
limit: TRANSACTION_DISPLAYED
}, function(txs) {
$scope.txs = txs;
});
};
$scope.txs = [];
2014-01-14 14:42:38 -08:00
$scope.blocks = [];
}]);
2014-01-13 13:13:41 -08:00