Skip to content

Instantly share code, notes, and snippets.

@zh
Created January 5, 2023 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zh/b9329725e7be6b5b679bbb4d9fad7de5 to your computer and use it in GitHub Desktop.
Save zh/b9329725e7be6b5b679bbb4d9fad7de5 to your computer and use it in GitHub Desktop.
slp-token-data usage
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