Created
January 5, 2023 11:46
-
-
Save zh/b9329725e7be6b5b679bbb4d9fad7de5 to your computer and use it in GitHub Desktop.
slp-token-data usage
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
let iconFound = false; | |
let tokenUrl = null; | |
if ( | |
token.url.startsWith('ipfs://') || | |
token.url.startsWith('psf://') || | |
token.url.startsWith('nouns:') || | |
token.url.startsWith('pouns:') | |
) | |
tokenUrl = token.url; | |
if (token.url.startsWith('Qm') || token.url.startsWith('bafyb')) | |
tokenUrl = `ipfs://${token.url}`; | |
// optional | |
if (token.ticker.toLowerCase() === 'waifu') tokenUrl = 'juungle://'; | |
if (tokenUrl) { | |
const data = await getMedia(tokenUrl, { | |
token, | |
wallet, | |
size: iconSize, | |
}); | |
if (data && data.icon) { | |
const newIcon = | |
data.download === true ? ( | |
<Image | |
src={data.icon} | |
style={{ width: iconSize, marginTop: 16 }} | |
preview={false} | |
/> | |
) : ( | |
<div | |
style={{ | |
display: 'grid', | |
gridTemplateColumns: '1fr', | |
marginTop: 16, | |
}} | |
> | |
<div dangerouslySetInnerHTML={{ __html: data.icon }}></div> | |
</div> | |
); | |
setIcon(newIcon); | |
iconFound = true; | |
} | |
} | |
if (!iconFound) { | |
const data = await getMedia('legacy://', { token }); | |
if (data && data.icon) { | |
const newIcon = ( | |
<Image | |
src={data.icon} | |
style={{ width: iconSize, marginTop: 16 }} | |
preview={false} | |
/> | |
); | |
setIcon(newIcon); | |
iconFound = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment