From bafffe4c271a9ed1fefd98424b1507c432ce6c52 Mon Sep 17 00:00:00 2001 From: Alexandr Date: Fri, 17 Jan 2020 11:58:07 +0200 Subject: [PATCH] some changes --- config.json | 2 +- index.html | 11 +++++ scripts/controllers/addressInfoController.js | 3 +- scripts/controllers/blockInfosController.js | 48 ++++++++++++------- scripts/controllers/mainController.js | 38 ++++++++++++++- .../controllers/transactionInfosController.js | 24 +++++++--- styles/main.css | 8 ++++ 7 files changed, 105 insertions(+), 29 deletions(-) diff --git a/config.json b/config.json index d7bb82f..3aedac2 100644 --- a/config.json +++ b/config.json @@ -1,3 +1,3 @@ { - "rpcUrl": "http://78.47.64.48/api" + "rpcUrl": "https://explorer.affilcoin.net/api" } diff --git a/index.html b/index.html index ea5f88e..0d7c558 100644 --- a/index.html +++ b/index.html @@ -22,9 +22,15 @@ affilcoin + + + diff --git a/scripts/controllers/addressInfoController.js b/scripts/controllers/addressInfoController.js index 4f82376..bbc3e94 100644 --- a/scripts/controllers/addressInfoController.js +++ b/scripts/controllers/addressInfoController.js @@ -19,7 +19,8 @@ } return web3.eth.getTransactionCount($scope.addressId, function(err, transactions){ var balanceInEther; - balanceInEther = web3.fromWei(balance, 'ether'); + + balanceInEther = web3.utils.fromWei(balance, 'ether'); $rootScope.loading = false; return cb(null, { balance: balance, diff --git a/scripts/controllers/blockInfosController.js b/scripts/controllers/blockInfosController.js index bddb99e..ae6795a 100644 --- a/scripts/controllers/blockInfosController.js +++ b/scripts/controllers/blockInfosController.js @@ -2,18 +2,24 @@ angular.module('ethExplorer.block', ['ngRoute','ui.bootstrap']) .controller('blockInfosCtrl', function ($rootScope, $scope, $location, $routeParams,$q) { var web3 = $rootScope.web3; + $scope.init = function() { $rootScope.loading = true; $scope.blockId = $routeParams.blockId; - + + var number = 0; if($scope.blockId!==undefined) { - + + web3.eth.getBlockNumber().then(res => { + number = res; + }, err => console.log(err)); + getBlockInfos() - .then(function(result){ + .then( function(result){ - var number = web3.eth.blockNumber; + $rootScope.loading = false; $scope.result = result; @@ -30,24 +36,28 @@ angular.module('ethExplorer.block', ['ngRoute','ui.bootstrap']) $scope.miner ='pending'; } $scope.gasLimit = result.gasLimit; - $scope.gasUsed = result.gasUsed; - $scope.nonce = result.nonce; + $scope.gasUsed = (result.gasUsed !== null ? result.gasUsed : 0); + $scope.nonce = (result.nonce === null ? 'null' : result.nonce); $scope.difficulty = ("" + result.difficulty).replace(/['"]+/g, ''); $scope.gasLimit = result.gasLimit; // that's a string - $scope.nonce = result.nonce; $scope.number = result.number; $scope.parentHash = result.parentHash; $scope.blockNumber = result.number; $scope.timestamp = result.timestamp; - $scope.extraData = result.extraData; + $scope.extraData = (result.extraData === null ? 'null' : result.extraData); $scope.dataFromHex = hex2a(result.extraData); $scope.size = result.size; - if($scope.blockNumber!==undefined){ - $scope.conf = number - $scope.blockNumber + " Confirmations"; - if($scope.conf===0 + " Confirmations"){ - $scope.conf='Unconfirmed'; - } - } + + if(result.number!==undefined){ + $scope.conf = number - result.number + " Confirmations"; + if($scope.conf===0 + " Confirmations"){ + $scope.conf='Unconfirmed'; + } + if ( (number - result.number) <= 0) { + $scope.conf='Unconfirmed'; + } + } + if($scope.blockNumber!==undefined){ var info = web3.eth.getBlock($scope.blockNumber); if(info!==undefined){ @@ -57,8 +67,6 @@ angular.module('ethExplorer.block', ['ngRoute','ui.bootstrap']) } } - - }); } else { @@ -87,9 +95,10 @@ angular.module('ethExplorer.block', ['ngRoute','ui.bootstrap']) // parse transactions $scope.transactions = [] web3.eth.getBlockTransactionCount($scope.blockId, function(error, result){ - var txCount = result - + var txCount = result; + for (var blockIdx = 0; blockIdx < txCount; blockIdx++) { + web3.eth.getTransactionFromBlock($scope.blockId, blockIdx, function(error, result) { var transaction = { @@ -110,6 +119,9 @@ angular.module('ethExplorer.block', ['ngRoute','ui.bootstrap']) function hex2a(hexx) { + if (hexx === null) { + return 'null'; + } var hex = hexx.toString();//force conversion var str = ''; for (var i = 0; i < hex.length; i += 2) diff --git a/scripts/controllers/mainController.js b/scripts/controllers/mainController.js index 49f7255..75ce826 100644 --- a/scripts/controllers/mainController.js +++ b/scripts/controllers/mainController.js @@ -1,7 +1,36 @@ // Generated by LiveScript 1.6.0 (function(){ var slice$ = [].slice; - angular.module('ethExplorer.main', []).controller('mainCtrl', function($rootScope, $scope){ + angular.module('ethExplorer.main', []).controller('mainCtrl', function($rootScope, $scope, $location){ + + + setTimeout(function(){ + setInterval(function(){ + + if ($location.path() === '/') { + + let blockNumNew = $scope.blocks[0].number + 1; + + $rootScope.web3.eth.getBlock(blockNumNew, function(err, item){ + if (err != null) { + return console.log('getBlock err: '+err); + } + + console.log('block number: '+blockNumNew); + + $scope.blockNum = blockNumNew; + $scope.blocks.unshift(item); + $scope.blocks.splice(-1,1); + + $rootScope.safeApply(); + }); + } + + }, 60*100); + }, 60); + + + var loadBlock, init; loadBlock = function(arg$, cb){ var item, items; @@ -11,6 +40,7 @@ } console.log(item); return $rootScope.web3.eth.getBlock($scope.blockNum - item, function(err, item){ + if (err != null) { return cb(err); } @@ -39,6 +69,7 @@ } return $rootScope.safeApply(function(){ $rootScope.loading = false; + return console.log('loadingstop', err); }); }); @@ -48,8 +79,11 @@ return init(function(err){ return console.log(err); }); + + + }); - angular.module('ethExplorer.search', []).controller('searchCtrl', function($rootScope, $scope){ + angular.module('ethExplorer.search', []).controller('searchCtrl', function($rootScope, $scope, $location){ var goToBlockInfos, goToAddrInfos, goToTxInfos; goToBlockInfos = function(requestStr){ return $location.path('/block/' + requestStr); diff --git a/scripts/controllers/transactionInfosController.js b/scripts/controllers/transactionInfosController.js index 34073e6..d54cd4b 100644 --- a/scripts/controllers/transactionInfosController.js +++ b/scripts/controllers/transactionInfosController.js @@ -1,21 +1,31 @@ angular.module('ethExplorer.tx', ['ngRoute','ui.bootstrap']) .controller('transactionInfosCtrl', function ($rootScope, $scope, $location, $routeParams,$q) { - - var web3 = $rootScope.web3; - + var web3 = $rootScope.web3; + $scope.init=function() { $scope.txId=$routeParams.transactionId; + + web3.eth.getTransactionReceipt($scope.txId).then((res)=>{ + console.log('res: '+res); + }, (err) => { + console.log('err: '+err); + }); if($scope.txId!==undefined) { // add a test to check if it match tx paterns to avoid useless API call, clients are not obliged to come from the search form... $rootScope.loading = true; getTransactionInfos() - .then(function(result){ + .then(function(result){ + if (result == null) { + $rootScope.loading = false; + alert('Невозможно отобразить данные о транзакции'); + return console.log('getTransactionInfos err: '+result); + } //TODO Refactor this logic, asynchron calls + services.... var number = web3.eth.blockNumber; $rootScope.loading = false; $scope.result = result; - + if(result.blockHash!==undefined){ $scope.blockHash = result.blockHash; } @@ -52,7 +62,7 @@ angular.module('ethExplorer.tx', ['ngRoute','ui.bootstrap']) } } - }); + }, err => console.log(err)); } @@ -64,6 +74,7 @@ angular.module('ethExplorer.tx', ['ngRoute','ui.bootstrap']) function getTransactionInfos(){ + var deferred = $q.defer(); web3.eth.getTransaction($scope.txId,function(error, result) { @@ -82,6 +93,5 @@ angular.module('ethExplorer.tx', ['ngRoute','ui.bootstrap']) }; $scope.init(); - console.log($scope.result); }); diff --git a/styles/main.css b/styles/main.css index df9cfa3..59617a8 100644 --- a/styles/main.css +++ b/styles/main.css @@ -19,6 +19,14 @@ input.form-control { width: 400px !important; } +@media screen and (max-width: 990px) { + input.form-control { + width: 0 !important; + } + .collapse { + margin-bottom: 30px; + } +} .navbar-brand { padding-left: 0;