Blockchain explorer for Ethereum based network and a tool for inspecting and analyzing EVM based blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
blockscout/apps/block_scout_web/assets/js/lib/token_icon.js

55 lines
1.3 KiB

function getTokenIconUrl (chainID, addressHash) {
let chainName = null
switch (chainID) {
case '1':
chainName = 'ethereum'
break
case '99':
chainName = 'poa'
break
case '100':
chainName = 'xdai'
break
default:
chainName = null
break
}
if (chainName) {
return `https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/${chainName}/assets/${addressHash}/logo.png`
} else {
return '/images/icons/token_icon_default.svg'
}
}
function appendTokenIcon ($tokenIconContainer, chainID, addressHash, displayTokenIcons, size) {
const iconSize = size || 20
const tokenIconURL = getTokenIconUrl(chainID.toString(), addressHash)
if (displayTokenIcons) {
checkLink(tokenIconURL)
.then(checkTokenIconLink => {
if (checkTokenIconLink) {
if ($tokenIconContainer) {
const img = new Image(iconSize, iconSize)
img.src = tokenIconURL
img.className = 'mr-1'
$tokenIconContainer.append(img)
}
}
})
}
}
async function checkLink (url) {
if (url) {
try {
const res = await fetch(url)
return res.ok
} catch (_error) {
return false
}
} else {
return false
}
}
export { appendTokenIcon, checkLink, getTokenIconUrl }