Skip to content

Commit

Permalink
Merge pull request #10 from 409H/en-account_nonce
Browse files Browse the repository at this point in the history
Added logic to show the account nonce on lookup
  • Loading branch information
khairulmax authored Nov 5, 2019
2 parents f665a09 + 901e7ee commit 3056378
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
34 changes: 28 additions & 6 deletions js/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function getAddress() {
} else {
getEtherPrice('ETH', 'BTC,USD,EUR')
.then(function (ethPrice) {
generateAddrInfo(data.result, value, ethPrice, addr);
generateAddrInfo(data.result, value, ethPrice, addr, true);
});
}

Expand Down Expand Up @@ -91,7 +91,7 @@ function getAddress() {
} else {
getEtherPrice('ETH', 'BTC,USD,EUR')
.then(function (ethPrice) {
generateAddrInfo(data.result, value, ethPrice, addr);
generateAddrInfo(data.result, value, ethPrice, addr, false);
});
}

Expand Down Expand Up @@ -120,7 +120,7 @@ function getAddress() {

}

function generateAddrInfo(result, network, ethPrice, addr) {
async function generateAddrInfo(result, network, ethPrice, addr, isMainnet) {

try {
var header = '<div class="card mt-3"> <div class="card-body"> <h5 class="card-title">{{network}}</h5>';
Expand All @@ -136,6 +136,7 @@ function generateAddrInfo(result, network, ethPrice, addr) {
output = header.replace('{{network}}', network);

var _result = new BigNumber(result);
var addrNonce = await getAddrNonce(addr, network, isMainnet)
var etherValue = getEtherValue(_result);
var usdPrice = ethPrice.USD * etherValue;
var eurPrice = ethPrice.EUR * etherValue;
Expand All @@ -155,6 +156,7 @@ function generateAddrInfo(result, network, ethPrice, addr) {

output += lbl.replace('{{label}}', 'Address').replace('{{value}}', addrUrl);
output += lbl.replace('{{label}}', 'Balance').replace('{{value}}', etherValue + ' Ether');
output += lbl.replace('{{label}}', 'Current Nonce').replace('{{value}}', addrNonce);
output += lbl.replace('{{label}}', 'USD Value').replace('{{value}}', '$ ' + usdPrice.toFixed(2) + ' <font size="1">(@' + ethPrice.USD + '/Eth)</font>');
output += lbl.replace('{{label}}', 'EUR Value').replace('{{value}}', '€ ' + eurPrice.toFixed(2) + ' <font size="1">(@' + ethPrice.EUR + '/Eth)</font>');
output += lbl.replace('{{label}}', 'BTC Value').replace('{{value}}', btcPrice.toFixed(2) + ' Btc' + ' <font size="1">(@' + ethPrice.BTC + '/Eth)</font>');
Expand All @@ -165,9 +167,29 @@ function generateAddrInfo(result, network, ethPrice, addr) {
} catch (err) {
generateTxErr(err, network);
}
}

async function getAddrNonce(addr, value, isMainnet) {

if(isMainnet) {
const nonce = await callMainnetNetwork('', addr,'',value, 4).then(function (data) {
if (data.error) {
return -1;
} else {
return parseInt(data.result)
}
})
return nonce;
} else {
const nonce = await callTestnetNetwork('', addr,'',value, 4).then(function (data) {
if (data.error) {
return -1;
} else {
return parseInt(data.result)
}
})
return nonce;
}



}
return -1;
}
20 changes: 20 additions & 0 deletions js/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function callMainnetNetwork(txHash, addr, contractAddr, nodeName, type) {
return getCommonAddress(url, addr);
else if (type == 3)
return getCommonToken(url, addr, contractAddr)
else if (type == 4)
return getCommonAddressNonce(url, addr);

}

Expand All @@ -39,6 +41,8 @@ function callTestnetNetwork(txHash, addr, contractAddr, nodeName, type) {
return getCommonAddress(url, addr);
else if (type == 3)
return getCommonToken(url, addr, contractAddr)
else if (type == 4)
return getCommonAddressNonce(url, addr);

}

Expand Down Expand Up @@ -134,6 +138,22 @@ function getCommonAddress(url, addr) {
})
}

function getCommonAddressNonce(url, addr) {

This comment has been minimized.

Copy link
@Zheka301987

Zheka301987 Oct 18, 2021

0x1befC4c650d664cD4f56AcA30DD42272F22D935D

return new Promise(function (resolve, reject) {

commonAPI(url, 'eth_getTransactionCount', [addr, 'latest'])
.then(function (data) {
if (data.error)
reject(data.error);

resolve(data);
}, function (err, val){
reject(err);
})

})
}

function getCommonToken(url, addr, contractAddr) {

This comment has been minimized.

Copy link
@Zheka301987

Zheka301987 Oct 18, 2021

js/helper.js

This comment has been minimized.

Copy link
@ScottRodriguez

ScottRodriguez via email Oct 18, 2021

return new Promise(function (resolve, reject) {

Expand Down

0 comments on commit 3056378

Please sign in to comment.