File tree Expand file tree Collapse file tree 2 files changed +42
-8
lines changed
features/asset-list/bitcoin/src20-token-asset-list Expand file tree Collapse file tree 2 files changed +42
-8
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ import { Src20AvatarIcon } from '@leather.io/ui';
44import { getAssetDisplayName } from '@leather.io/utils' ;
55
66import { useManageTokens } from '@app/common/hooks/use-manage-tokens' ;
7- import { CollectibleImage } from '@app/components/collectibles/collectible-image' ;
87import { CryptoAssetItem } from '@app/components/crypto-asset-item/crypto-asset-item' ;
98import type { Src20TokenAssetDetails } from '@app/components/loaders/src20-tokens-loader' ;
9+ import { Src20Image } from '@app/components/src20/src20-image' ;
1010import { useIsPrivateMode } from '@app/store/settings/settings.selectors' ;
1111
1212import 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 ) ;
You can’t perform that action at this time.
0 commit comments