Skip to content

Commit 84f968c

Browse files
authored
Merge pull request #6064 from leather-io/dev
Release: SRC-20 Image Fix
2 parents 679de0c + 42ae048 commit 84f968c

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { useState } from 'react';
2+
3+
import { css } from 'leather-styles/css';
4+
5+
import { Src20AvatarIcon } from '@leather.io/ui';
6+
7+
interface Src20ImageProps {
8+
alt?: string;
9+
src: string;
10+
}
11+
export function Src20Image(props: Src20ImageProps) {
12+
const { alt, src } = props;
13+
const [isError, setIsError] = useState(false);
14+
const [isLoading, setIsLoading] = useState(true);
15+
const [width, setWidth] = useState(0);
16+
17+
if (isError) return <Src20AvatarIcon />;
18+
19+
return (
20+
<img
21+
alt={alt}
22+
onError={() => setIsError(true)}
23+
loading="lazy"
24+
onLoad={event => {
25+
const target = event.target as HTMLImageElement;
26+
setWidth(target.naturalWidth);
27+
setIsLoading(false);
28+
}}
29+
src={src}
30+
className={css({
31+
width: 'xl',
32+
borderRadius: '100%',
33+
objectFit: 'cover',
34+
// display: 'none' breaks onLoad event firing
35+
opacity: isLoading ? '0' : '1',
36+
imageRendering: width <= 40 ? 'pixelated' : 'auto',
37+
})}
38+
/>
39+
);
40+
}

src/app/features/asset-list/bitcoin/src20-token-asset-list/src20-token-asset-list.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { Src20AvatarIcon } from '@leather.io/ui';
44
import { getAssetDisplayName } from '@leather.io/utils';
55

66
import { useManageTokens } from '@app/common/hooks/use-manage-tokens';
7-
import { CollectibleImage } from '@app/components/collectibles/collectible-image';
87
import { CryptoAssetItem } from '@app/components/crypto-asset-item/crypto-asset-item';
98
import type { Src20TokenAssetDetails } from '@app/components/loaders/src20-tokens-loader';
9+
import { Src20Image } from '@app/components/src20/src20-image';
1010
import { useIsPrivateMode } from '@app/store/settings/settings.selectors';
1111

1212
import type { AssetRightElementVariant } from '../../asset-list';
@@ -36,13 +36,7 @@ export function Src20TokenAssetList({
3636
const key = `${token.info.id}${i}`;
3737
const captionLeft = getAssetDisplayName(token.info).toUpperCase();
3838
const icon = token.info.deploy_img ? (
39-
<CollectibleImage
40-
alt={token.info.symbol}
41-
icon={<Src20AvatarIcon size="lg" />}
42-
src={token.info.deploy_img}
43-
title={`# ${token.info.id}`}
44-
subtitle={`# ${token.info.symbol}`}
45-
/>
39+
<Src20Image src={token.info.deploy_img} />
4640
) : (
4741
<Src20AvatarIcon />
4842
);

0 commit comments

Comments
 (0)