11import { indexDTFIconsAtom } from '../state/atoms'
22import { cn } from '../utils/cn'
33import { UNIVERSAL_ASSETS } from '../utils/universal'
4- import { atom , useAtom , useAtomValue } from 'jotai'
4+ import { useAtomValue } from 'jotai'
55import * as React from 'react'
66import defaultLogoSvg from './icons/svgs/defaultLogo.svg'
77import ethSvg from './icons/svgs/eth.svg'
88import usdcSvg from './icons/svgs/usdc.svg'
99import wethSvg from './icons/svgs/weth.svg'
1010import bnbSvg from './icons/svgs/bnb.svg'
1111
12- const routeCacheAtom = atom < Record < string , string > > ( { } )
13-
1412type Sizes = 'sm' | 'md' | 'lg' | 'xl'
1513
1614const sizeMap : Record < Sizes , { width : number ; height : number } > = {
@@ -29,7 +27,6 @@ interface Props extends React.ImgHTMLAttributes<HTMLImageElement> {
2927
3028const TokenLogo = React . forwardRef < HTMLImageElement , Props > ( ( props , ref ) => {
3129 const indexDTFIcons = useAtomValue ( indexDTFIconsAtom )
32- const [ routeCache , setRouteCache ] = useAtom ( routeCacheAtom )
3330 const {
3431 symbol,
3532 size = 'md' ,
@@ -68,43 +65,21 @@ const TokenLogo = React.forwardRef<HTMLImageElement, Props>((props, ref) => {
6865 } )
6966 }
7067
71- const cacheUrl = React . useCallback ( ( url : string ) => {
72- if ( address && chain ) {
73- setRouteCache ( ( prev ) => ( {
74- ...prev ,
75- [ `${ address . toLowerCase ( ) } -${ chain } ` ] : url ,
76- } ) )
77- }
78- } , [ address , chain , setRouteCache ] )
79-
8068 const loadImage = React . useCallback ( async ( ) => {
8169 try {
82- // check cache first
83- if ( address && chain ) {
84- const cacheKey = `${ address . toLowerCase ( ) } -${ chain } `
85- if ( routeCache [ cacheKey ] ) {
86- setCurrentSrc ( routeCache [ cacheKey ] )
87- return
88- }
89- }
90-
91- // If we have a direct src, try to use it first
9270 if ( propsSrc ) {
9371 const url = await tryLoadImage ( propsSrc )
94- cacheUrl ( url )
9572 setCurrentSrc ( url )
9673 return
9774 }
9875
99- // If we have a symbol, try to load the logo according to convention
10076 if ( symbol ) {
10177 const symbolWithoutVault = symbol . endsWith ( '-VAULT' )
10278 ? symbol . replace ( '-VAULT' , '' )
10379 : symbol
10480
10581 const imgSrc = getKnownTokenLogo ( symbolWithoutVault )
10682 if ( imgSrc ) {
107- cacheUrl ( imgSrc )
10883 setCurrentSrc ( imgSrc )
10984 return
11085 }
@@ -114,7 +89,6 @@ const TokenLogo = React.forwardRef<HTMLImageElement, Props>((props, ref) => {
11489 address && chain && indexDTFIcons [ chain ] ?. [ address . toLowerCase ( ) ]
11590 if ( foundIndexDTFIcon ) {
11691 const imgUrl = await tryLoadImage ( foundIndexDTFIcon )
117- cacheUrl ( imgUrl )
11892 setCurrentSrc ( imgUrl )
11993 return
12094 }
@@ -125,7 +99,6 @@ const TokenLogo = React.forwardRef<HTMLImageElement, Props>((props, ref) => {
12599 . toUpperCase ( )
126100 . substring ( 1 ) } .svg`
127101 const url = await tryLoadImage ( universalUrl )
128- // cacheUrl(url) // don't cache universal logos because of the wrapper... solve later
129102 setCurrentSrc ( url )
130103 setIsWrapped ( true )
131104 return
@@ -134,12 +107,10 @@ const TokenLogo = React.forwardRef<HTMLImageElement, Props>((props, ref) => {
134107 }
135108 }
136109
137- // If we have address and chain, try external APIs
138110 if ( address && chain ) {
139111 try {
140112 const dexscreenerUrl = `https://dd.dexscreener.com/ds-data/tokens/base/${ address ?. toLowerCase ( ) } .png?size=lg`
141113 const url = await tryLoadImage ( dexscreenerUrl )
142- cacheUrl ( url )
143114 setCurrentSrc ( url )
144115 return
145116 } catch {
@@ -149,7 +120,6 @@ const TokenLogo = React.forwardRef<HTMLImageElement, Props>((props, ref) => {
149120 try {
150121 const llamaUrl = `https://token-icons.llamao.fi/icons/tokens/${ chain } /${ address ?. toLowerCase ( ) } ?h=${ h } &w=${ w } `
151122 const url = await tryLoadImage ( llamaUrl )
152- cacheUrl ( url )
153123 setCurrentSrc ( url )
154124 return
155125 } catch {
@@ -162,7 +132,7 @@ const TokenLogo = React.forwardRef<HTMLImageElement, Props>((props, ref) => {
162132 console . debug ( 'Failed to load token logo:' , error )
163133 setCurrentSrc ( defaultLogoSvg )
164134 }
165- } , [ propsSrc , symbol , address , chain , h , w , indexDTFIcons , routeCache , cacheUrl ] )
135+ } , [ propsSrc , symbol , address , chain , h , w , indexDTFIcons ] )
166136
167137 React . useEffect ( ( ) => {
168138 setCurrentSrc ( '' )
0 commit comments