-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4596 from blockscout/vb-token-icon-bridged-with-m…
…ainnet Display token icon for tokens from TrustWallet assets repository
- Loading branch information
Showing
27 changed files
with
651 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
function getTokenIconUrl (chainID, addressHash) { | ||
var 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 null | ||
} | ||
} | ||
|
||
function appendTokenIcon ($tokenIconContainer, chainID, addressHash, foreignChainID, foreignAddressHash, displayTokenIcons, size) { | ||
const iconSize = size || 20 | ||
var tokenIconURL = null | ||
if (foreignChainID) { | ||
tokenIconURL = getTokenIconUrl(foreignChainID.toString(), foreignAddressHash) | ||
} else if (chainID) { | ||
tokenIconURL = getTokenIconUrl(chainID.toString(), addressHash) | ||
} | ||
if (displayTokenIcons) { | ||
checkLink(tokenIconURL) | ||
.then(checkTokenIconLink => { | ||
if (checkTokenIconLink) { | ||
if ($tokenIconContainer) { | ||
var img = new Image(iconSize, iconSize) | ||
img.src = tokenIconURL | ||
$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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import $ from 'jquery' | ||
import { appendTokenIcon } from '../../lib/token_icon' | ||
|
||
if ($('[data-page="token-details"]').length) { | ||
const $tokenIconContainer = $('#token-icon') | ||
const chainID = $tokenIconContainer.data('chain-id') | ||
const addressHash = $tokenIconContainer.data('address-hash') | ||
const foreignChainID = $tokenIconContainer.data('foreign-chain-id') | ||
const foreignAddressHash = $tokenIconContainer.data('foreign-address-hash') | ||
const displayTokenIcons = $tokenIconContainer.data('display-token-icons') | ||
|
||
appendTokenIcon($tokenIconContainer, chainID, addressHash, foreignChainID, foreignAddressHash, displayTokenIcons) | ||
} |
Oops, something went wrong.