Skip to content

Commit

Permalink
Frontend changes to account for backend api changes (#28)
Browse files Browse the repository at this point in the history
* Changed verified page to use the /featured api endpoint

* Added sorting for featured. Added functionality for backend api on multicoin /address pages

* Change href on api req success

* Shift from local endpoint

* Fixed api issue with search.ejs

* Added toLowerCase to make coin pages work
  • Loading branch information
blurpesec authored and MrLuit committed Nov 8, 2018
1 parent e0a1fcd commit 5c3c1d0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
7 changes: 5 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ export const serve = async (): Promise<void> => {
json: true
})).result.map(scam => {
scam.hostname = url.parse(scam.url).hostname;
if (scam.coin) {
scam.coin = scam.coin.toLowerCase();
}
return scam;
});
const fullAddresses = (await request('https://api.cryptoscamdb.org/v1/addresses', {
Expand Down Expand Up @@ -377,9 +380,9 @@ export const serve = async (): Promise<void> => {
/* Verified pages */
app.get('/verified/', async (req, res) =>
res.render('verified', {
featured: (await request('https://api.cryptoscamdb.org/v1/verified', {
featured: (await request('https://api.cryptoscamdb.org/v1/featured', {
json: true
})).result.filter(entry => entry.featured)
})).result.sort((a, b) => a.name.localeCompare(b.name))
})
);

Expand Down
2 changes: 1 addition & 1 deletion src/views/pages/address.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<i>(none)</i>
<% } %>
<br>
<a target="_blank" href="https://etherscan.io/address/<%= address %>"><i class="external icon"></i> View address on etherscan</a><BR>
<a target="_blank" id="explorer" href="https://etherscan.io/address/<%= address %>"><i class="external icon"></i> View address information</a><BR>
<br>
<hr>
<br>
Expand Down
6 changes: 3 additions & 3 deletions src/views/partials/search.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<i class="checkmark icon"></i>
<div class="content message-grid">
<div class="header message-label">
VERIFIED
Verified
</div>
<p id='verifiedmessage' class="message-content">This domain is a verified domain. You can trust the contents.</p>
</div>
Expand All @@ -21,7 +21,7 @@
<i class="warning sign icon"></i>
<div class="content message-grid">
<div class="header message-label">
BLOCKED
Blocked
</div>
<p id='blacklistmessage' class="message-content">This domain was put on the blacklist.</p>
</div>
Expand All @@ -30,7 +30,7 @@
<i class="info circle icon"></i>
<div class="content message-grid">
<div class="message-label header">
NEUTRAL
Neutral
</div>
<p id='neutralmessage' class="message-content">This domain wasn't recognized as a malicious domain, nor as verified. Be careful!</p>
</div>
Expand Down
9 changes: 5 additions & 4 deletions src/views/static/js/address.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
window.addEventListener("load", function() {
$.getJSON("https://api.etherscan.io/api?module=account&action=balance&tag=latest&address=" + $("h1").html(), function(data) {
$("#balance").html((Math.round(data.result / (10e17) * 100000) / 100000) + ' ETH');
$.getJSON("https://api.coinmarketcap.com/v1/ticker/ethereum/?convert=USD", function(val) {
$("#value").html((Math.round((data.result / (10e17)) * val[0].price_usd * 100) / 100).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "$ (" + Math.round(val[0].price_usd * 100) / 100 + " USD/ETH)");
$.getJSON("https://api.cryptoscamdb.org/v1/check/" + $("h1").html(), function(data) {
$.getJSON("https://api.cryptoscamdb.org/v1/balance/" + data.coin + "/" + $("h1").html(), function(val) {
$("#balance").html(val.balance.toFixed(2) + " " + data.coin.toUpperCase());
$("#value").html("$"+ val.usdvalue.toFixed(2) + " ($" + (val.usdvalue / val.balance).toFixed(2) + " USD/" + data.coin.toUpperCase() + ")");
$("#explorer").attr("href", val.blockexplorer);
});
});
});
22 changes: 11 additions & 11 deletions src/views/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ window.addEventListener("load", function() {
$('.search-btn').click(function() {
console.log('button click recorded')
$.getJSON("https://api.cryptoscamdb.org/v1/check/" + encodeURIComponent($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]), function(result) {
if (result.result === 'verified') {
if (result.result.status === 'verified') {
hideEverything();
var strLinkVerified = '';
$("#verifiedmessage").html('<b>' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + '</b> is a verified domain. You can trust the contents.');
strLinkVerified = '<a id="details" href="/domain/' + encodeURI($("input").val()) + '">Details on this domain <i class="chevron right small icon"></i></a>';
$("#verifiedmessage").html($("#verifiedmessage").html() + ' ' + strLinkVerified);
$("#verified").css('display', 'flex');
} else if (result.result === 'neutral') {
} else if (result.result.status === 'neutral') {
hideEverything();
var strLinkNeutral = '';
if(result.type === 'address'){
if(result.result.type === 'address'){
$("#neutralmessage").html('<b>' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + '</b> wasn\'t a recognized ETH address.');
strLinkNeutral = '<a id="details" href="https://etherscan.io/address/' + encodeURI($("input").val()) + '">View this address on Etherscan <i class="chevron right small icon"></i></a>';
$("#neutralmessage").html($("#neutralmessage").html() + ' ' + strLinkNeutral);
Expand All @@ -32,25 +32,25 @@ window.addEventListener("load", function() {
$("#neutralmessage").html($("#neutralmessage").html() + ' ' + strLinkNeutral);
$("#neutral").css('display', 'flex');
}
} else if (result.result === 'whitelisted') {
} else if (result.result.status === 'whitelisted') {
hideEverything();
var strLinkWhitelisted = '';
$("#verifiedmessage").html('<b>' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + '</b> is a whitelisted address. You can trust it.');
strLinkWhitelisted = '<a id="details" href="/address/' + encodeURI($("input").val()) + '">Details on this address <i class="chevron right small icon"></i></a>';
$("#verifiedmessage").html($("#verifiedmessage").html() + ' ' + strLinkWhitelisted);
$("#verified").css('display', 'flex');
} else if (result.result === 'blocked') {
} else if (result.result.status === 'blocked') {
hideEverything();
blocked = true;
var strLinkBlocked = '';
if (result.type === 'domain' && 'category' in result.entries[0]) {
$("#blacklistmessage").html('<b>' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + '</b> was put on the blacklist for ' + result.entries[0].category.toLowerCase() + '.');
if (result.result.type === 'domain' && 'category' in result.result.entries[0]) {
$("#blacklistmessage").html('<b>' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + '</b> was put on the blacklist for ' + result.result.entries[0].category.toLowerCase() + '.');
strLinkBlocked = '<a id="details" href="/domain/' + encodeURI($("input").val()) + '">Details on this domain <i class="chevron right small icon"></i></a>';
} else if(result.type === 'address') {
$("#blacklistmessage").html('<b>' + encodeURI($("input").val().toLowerCase()) + ' was put on the blacklist and is associated with '+ result.entries.length +' blocked domain(s).');
} else if(result.result.type === 'address') {
$("#blacklistmessage").html('<b>' + encodeURI($("input").val().toLowerCase()) + ' was put on the blacklist and is associated with '+ result.result.entries.length +' blocked domain(s).');
strLinkBlocked = '<a id="details" href="/address/' + encodeURI($("input").val()) + '">Details on this address <i class="chevron right small icon"></i></a>';
} else if(result.type === 'ip') {
$("#blacklistmessage").html('<b>' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + '</b> was put on the blacklist and is associated with '+ result.entries.length +' blocked domain(s)');
} else if(result.result.type === 'ip') {
$("#blacklistmessage").html('<b>' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + '</b> was put on the blacklist and is associated with '+ result.result.entries.length +' blocked domain(s)');
strLink = '<a id="details" href="/ip/' + encodeURI($("input").val()) + '">Details on this domain <i class="chevron right small icon"></i></a>';
}
$("#blacklistmessage").html($("#blacklistmessage").html() + ' ' + strLinkBlocked);
Expand Down

0 comments on commit 5c3c1d0

Please sign in to comment.