Skip to content

Commit 90603b7

Browse files
committed
fix: token logo caching
1 parent 540af2e commit 90603b7

File tree

4 files changed

+11
-35
lines changed

4 files changed

+11
-35
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [1.5.4] - 2025-12-02
2+
3+
### Fixed
4+
5+
- Fixed TokenLogo caching issue when switching between DTFs
6+
17
## [1.5.3] - 2025-11-16
28

39
### Changed

demo/dtf-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export const DTF_BY_CHAIN: Record<number, DTFConfig[]> = {
2929
],
3030
[bsc.id]: [
3131
{
32-
address: '0xb1b317d781eacfeef75557c15708560e791cbd00',
33-
symbol: 'TTCT',
32+
address: '0x2f8a339b5889ffac4c5a956787cda593b3c36867',
33+
symbol: 'CMC20',
3434
},
3535
],
3636
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reserve-protocol/react-zapper",
3-
"version": "1.5.3",
3+
"version": "1.5.4",
44
"type": "module",
55
"description": "React component for DTF minting with zap functionality",
66
"main": "dist/index.cjs.js",

src/components/token-logo.tsx

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import { indexDTFIconsAtom } from '../state/atoms'
22
import { cn } from '../utils/cn'
33
import { UNIVERSAL_ASSETS } from '../utils/universal'
4-
import { atom, useAtom, useAtomValue } from 'jotai'
4+
import { useAtomValue } from 'jotai'
55
import * as React from 'react'
66
import defaultLogoSvg from './icons/svgs/defaultLogo.svg'
77
import ethSvg from './icons/svgs/eth.svg'
88
import usdcSvg from './icons/svgs/usdc.svg'
99
import wethSvg from './icons/svgs/weth.svg'
1010
import bnbSvg from './icons/svgs/bnb.svg'
1111

12-
const routeCacheAtom = atom<Record<string, string>>({})
13-
1412
type Sizes = 'sm' | 'md' | 'lg' | 'xl'
1513

1614
const sizeMap: Record<Sizes, { width: number; height: number }> = {
@@ -29,7 +27,6 @@ interface Props extends React.ImgHTMLAttributes<HTMLImageElement> {
2927

3028
const 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

Comments
 (0)