My problem : I want to show transaction details like block hash , block no and input parameters. but it was showing that metamask does not support callback. our function is not waiting till transaction got mined and it enters into else part. how to solve it?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="../script/main.css">
<script src="../node_modules/web3/dist/web3.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="../script/app.js"></script>
</head>
<body>
<div class="container">
<h1>INSTAFER</h1>
<h3>APPROVE</h3>
<p id="result"></p>
<label for="address" class="col-lg-2 control-label">Address to be approved </label>
<input id="address" type="text">
<label for="amount" class="col-lg-2 control-label"> Maximum Amount</label>
<input id="amount" type="number">
<!-- <label for="name" class="col-lg-2 control-label">Instructor Age</label>
<input id="age" type="text"> -->
<button id="approve" style="height:50px;width:200px">Approve now</button>
<input type="button" style="height:50px;width:200px" id="homebutton" value="Home" onClick="location.href='../index.html'" >
</div>
<script>
$("#approve").click(function() {
console.log($("#address").val());
console.log($("#amount").val());
INCTokenC.approve($("#address").val(),$("#amount").val(),function(error, result){
if(!error)
{
tx.then(function(res){console.log(res);});
console.log(tx);
if (tx != null) {
while(tx.blockNumber==null){
var tx = getTx(result);
}
var txResult = "TxHash : " + tx.hash +"\n TxBlockNumber : " + tx.blockNumber;
$("#result").html(txResult);
console.log(result);
}
else {
$("#result").html(' No Transaction Happen');
}
}
else
console.error(error);
});
});
</script>
</body>
</html>