Skip to content

Commit

Permalink
address issue on sthnaqvi#15
Browse files Browse the repository at this point in the history
  • Loading branch information
jbagaresgaray committed Apr 1, 2021
1 parent f29c86a commit 33a11b4
Show file tree
Hide file tree
Showing 3 changed files with 559 additions and 504 deletions.
141 changes: 77 additions & 64 deletions app/scripts/controllers/transactionInfosController.js
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();
}
);
6 changes: 5 additions & 1 deletion app/views/transactionInfos.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,13 @@ <h1><i class="fa fa-exchange"></i> Transaction
<td>{{txprice}}</td>
</tr>
<tr>
<td>Data</td>
<td>Data (Hex)</td>
<td><textarea class="input-data-textarea" readonly>{{input}}</textarea></td>
</tr>
<tr>
<td>Data (UTF8)</td>
<td><textarea class="input-data-textarea" readonly>{{utf8Input}}</textarea></td>
</tr>


</tbody>
Expand Down
Loading

0 comments on commit 33a11b4

Please sign in to comment.