From 5c3c1d0b3bc011ebc40b6af2232c2c2be812b373 Mon Sep 17 00:00:00 2001 From: Michael - Blurpesec Date: Thu, 8 Nov 2018 12:20:45 -0500 Subject: [PATCH] Frontend changes to account for backend api changes (#28) * 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 --- src/app.ts | 7 +++++-- src/views/pages/address.ejs | 2 +- src/views/partials/search.ejs | 6 +++--- src/views/static/js/address.js | 9 +++++---- src/views/static/js/search.js | 22 +++++++++++----------- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/app.ts b/src/app.ts index 2d9844e..4c456ba 100644 --- a/src/app.ts +++ b/src/app.ts @@ -217,6 +217,9 @@ export const serve = async (): Promise => { 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', { @@ -377,9 +380,9 @@ export const serve = async (): Promise => { /* 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)) }) ); diff --git a/src/views/pages/address.ejs b/src/views/pages/address.ejs index debdc1d..52304bd 100644 --- a/src/views/pages/address.ejs +++ b/src/views/pages/address.ejs @@ -34,7 +34,7 @@ (none) <% } %>
- View address on etherscan
+ View address information



diff --git a/src/views/partials/search.ejs b/src/views/partials/search.ejs index 6061d17..444aef7 100644 --- a/src/views/partials/search.ejs +++ b/src/views/partials/search.ejs @@ -12,7 +12,7 @@
- VERIFIED + Verified

This domain is a verified domain. You can trust the contents.

@@ -21,7 +21,7 @@
- BLOCKED + Blocked

This domain was put on the blacklist.

@@ -30,7 +30,7 @@
- NEUTRAL + Neutral

This domain wasn't recognized as a malicious domain, nor as verified. Be careful!

diff --git a/src/views/static/js/address.js b/src/views/static/js/address.js index 2f604f1..b65e2c4 100644 --- a/src/views/static/js/address.js +++ b/src/views/static/js/address.js @@ -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); }); }); }); \ No newline at end of file diff --git a/src/views/static/js/search.js b/src/views/static/js/search.js index c23afbc..2ab4f6f 100644 --- a/src/views/static/js/search.js +++ b/src/views/static/js/search.js @@ -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('' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + ' is a verified domain. You can trust the contents.'); strLinkVerified = 'Details on this domain '; $("#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('' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + ' wasn\'t a recognized ETH address.'); strLinkNeutral = 'View this address on Etherscan '; $("#neutralmessage").html($("#neutralmessage").html() + ' ' + strLinkNeutral); @@ -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('' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + ' is a whitelisted address. You can trust it.'); strLinkWhitelisted = 'Details on this address '; $("#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('' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + ' was put on the blacklist for ' + result.entries[0].category.toLowerCase() + '.'); + if (result.result.type === 'domain' && 'category' in result.result.entries[0]) { + $("#blacklistmessage").html('' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + ' was put on the blacklist for ' + result.result.entries[0].category.toLowerCase() + '.'); strLinkBlocked = 'Details on this domain '; - } else if(result.type === 'address') { - $("#blacklistmessage").html('' + 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('' + encodeURI($("input").val().toLowerCase()) + ' was put on the blacklist and is associated with '+ result.result.entries.length +' blocked domain(s).'); strLinkBlocked = 'Details on this address '; - } else if(result.type === 'ip') { - $("#blacklistmessage").html('' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + ' was put on the blacklist and is associated with '+ result.entries.length +' blocked domain(s)'); + } else if(result.result.type === 'ip') { + $("#blacklistmessage").html('' + encodeURI($("input").val().toLowerCase().replace('http://','').replace('https://','').replace('www.','').split(/[/?#]/)[0]) + ' was put on the blacklist and is associated with '+ result.result.entries.length +' blocked domain(s)'); strLink = 'Details on this domain '; } $("#blacklistmessage").html($("#blacklistmessage").html() + ' ' + strLinkBlocked);