forked from Smart-Trade-Networks/stn-block-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f29c86a
commit 33a11b4
Showing
3 changed files
with
559 additions
and
504 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,88 @@ | ||
angular.module('ethExplorer') | ||
.controller('transactionInfosCtrl', function ($rootScope, $scope, $location, $routeParams, $q) { | ||
angular | ||
.module("ethExplorer") | ||
.controller( | ||
"transactionInfosCtrl", | ||
function ($rootScope, $scope, $location, $routeParams, $q) { | ||
|
||
function hex_to_ascii(str1) { | ||
var hex = str1.toString(); | ||
var str = ""; | ||
for (var n = 0; n < hex.length; n += 2) { | ||
str += String.fromCharCode(parseInt(hex.substr(n, 2), 16)); | ||
} | ||
return str; | ||
} | ||
|
||
$scope.init = function () { | ||
$scope.init = function () { | ||
$scope.txId = $routeParams.transactionId; | ||
|
||
$scope.txId = $routeParams.transactionId; | ||
if (!!$scope.txId) { | ||
// 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... | ||
|
||
if (!(!$scope.txId)) { // 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... | ||
getTransactionInfos().then(function (result) { | ||
//TODO Refactor this logic, asynchron calls + services.... | ||
var number = web3.eth.blockNumber; | ||
|
||
getTransactionInfos() | ||
.then(function (result) { | ||
//TODO Refactor this logic, asynchron calls + services.... | ||
var number = web3.eth.blockNumber; | ||
$scope.result = result; | ||
|
||
$scope.result = result; | ||
if (!!result.blockHash) { | ||
$scope.blockHash = result.blockHash; | ||
} else { | ||
$scope.blockHash = "pending"; | ||
} | ||
if (!!result.blockNumber) { | ||
$scope.blockNumber = result.blockNumber; | ||
} else { | ||
$scope.blockNumber = "pending"; | ||
} | ||
$scope.from = result.from; | ||
$scope.gas = result.gas; | ||
//$scope.gasPrice = result.gasPrice.c[0] + " WEI"; | ||
$scope.gasPrice = | ||
web3.fromWei(result.gasPrice, "ether").toFormat(10) + " ETH"; | ||
$scope.hash = result.hash; | ||
$scope.nonce = result.nonce; | ||
|
||
$scope.input = result.input; // that's a string | ||
$scope.utf8Input = hex_to_ascii(result.input); | ||
|
||
if (!(!result.blockHash)) { | ||
$scope.blockHash = result.blockHash; | ||
} | ||
else { | ||
$scope.blockHash = 'pending'; | ||
} | ||
if (!(!result.blockNumber)) { | ||
$scope.blockNumber = result.blockNumber; | ||
} | ||
else { | ||
$scope.blockNumber = 'pending'; | ||
} | ||
$scope.from = result.from; | ||
$scope.gas = result.gas; | ||
//$scope.gasPrice = result.gasPrice.c[0] + " WEI"; | ||
$scope.gasPrice = web3.fromWei(result.gasPrice, "ether").toFormat(10) + " ETH"; | ||
$scope.hash = result.hash; | ||
$scope.input = result.input; // that's a string | ||
$scope.nonce = result.nonce; | ||
$scope.to = result.to; | ||
$scope.transactionIndex = result.transactionIndex; | ||
//$scope.ethValue = web3.fromWei(result.value[0], "ether"); Newer method but has "" | ||
$scope.ethValue = result.value.c[0] / 10000; | ||
$scope.txprice = web3.fromWei(result.gas * result.gasPrice, "ether") + " ETH"; | ||
if (!(!$scope.blockNumber)) { | ||
$scope.conf = number - $scope.blockNumber; | ||
if ($scope.conf === 0) { | ||
$scope.conf = 'unconfirmed'; //TODO change color button when unconfirmed... ng-if or ng-class | ||
} | ||
} | ||
//TODO Refactor this logic, asynchron calls + services.... | ||
if (!(!$scope.blockNumber)) { | ||
var info = web3.eth.getBlock($scope.blockNumber); | ||
if (!(!info)) { | ||
$scope.time = info.timestamp; | ||
} | ||
} | ||
}); | ||
$scope.to = result.to; | ||
$scope.transactionIndex = result.transactionIndex; | ||
//$scope.ethValue = web3.fromWei(result.value[0], "ether"); Newer method but has "" | ||
$scope.ethValue = result.value.c[0] / 10000; | ||
$scope.txprice = | ||
web3.fromWei(result.gas * result.gasPrice, "ether") + " ETH"; | ||
if (!!$scope.blockNumber) { | ||
$scope.conf = number - $scope.blockNumber; | ||
if ($scope.conf === 0) { | ||
$scope.conf = "unconfirmed"; //TODO change color button when unconfirmed... ng-if or ng-class | ||
} | ||
} | ||
else { | ||
$location.path("/"); // add a trigger to display an error message so user knows he messed up with the TX number | ||
//TODO Refactor this logic, asynchron calls + services.... | ||
if (!!$scope.blockNumber) { | ||
var info = web3.eth.getBlock($scope.blockNumber); | ||
if (!!info) { | ||
$scope.time = info.timestamp; | ||
} | ||
} | ||
}); | ||
} else { | ||
$location.path("/"); // add a trigger to display an error message so user knows he messed up with the TX number | ||
} | ||
|
||
function getTransactionInfos() { | ||
var deferred = $q.defer(); | ||
function getTransactionInfos() { | ||
var deferred = $q.defer(); | ||
|
||
web3.eth.getTransaction($scope.txId, function (error, result) { | ||
if (!error) { | ||
deferred.resolve(result); | ||
} | ||
else { | ||
deferred.reject(error); | ||
} | ||
}); | ||
return deferred.promise; | ||
web3.eth.getTransaction($scope.txId, function (error, result) { | ||
if (!error) { | ||
deferred.resolve(result); | ||
} else { | ||
deferred.reject(error); | ||
} | ||
}; | ||
$scope.init(); | ||
}); | ||
}); | ||
return deferred.promise; | ||
} | ||
}; | ||
$scope.init(); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.