Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
64e8c3ce
Unverified
Commit
64e8c3ce
authored
Mar 21, 2022
by
Zach Pomerantz
Committed by
GitHub
Mar 21, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: token img jank (#3562)
parent
46e6c229
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
TokenImg.tsx
src/lib/components/TokenImg.tsx
+18
-14
No files found.
src/lib/components/TokenImg.tsx
View file @
64e8c3ce
...
...
@@ -3,7 +3,7 @@ import { useToken } from 'lib/hooks/useCurrency'
import
useCurrencyLogoURIs
from
'
lib/hooks/useCurrencyLogoURIs
'
import
{
MissingToken
}
from
'
lib/icons
'
import
styled
from
'
lib/theme
'
import
{
useCallback
,
use
Effect
,
useState
}
from
'
react
'
import
{
useCallback
,
use
Memo
,
useState
}
from
'
react
'
const
badSrcs
=
new
Set
<
string
>
()
...
...
@@ -19,19 +19,23 @@ function TokenImg({ token, ...rest }: TokenImgProps) {
// TODO(zzmp): TokenImg takes a frame to switch.
const
srcs
=
useCurrencyLogoURIs
(
tokenInfo
)
const
[
src
,
setSrc
]
=
useState
<
string
|
undefined
>
()
useEffect
(()
=>
{
setSrc
(
srcs
.
find
((
src
)
=>
!
badSrcs
.
has
(
src
)))
},
[
srcs
])
const
onError
=
useCallback
(()
=>
{
if
(
src
)
badSrcs
.
add
(
src
)
setSrc
(
srcs
.
find
((
src
)
=>
!
badSrcs
.
has
(
src
)))
},
[
src
,
srcs
])
if
(
src
)
{
return
<
img
src=
{
src
}
alt=
{
tokenInfo
.
name
||
tokenInfo
.
symbol
}
onError=
{
onError
}
{
...
rest
}
/>
}
return
<
MissingToken
color=
"secondary"
{
...
rest
}
/>
const
[
attempt
,
setAttempt
]
=
useState
(
0
)
const
onError
=
useCallback
((
e
)
=>
{
if
(
e
.
target
.
src
)
badSrcs
.
add
(
e
.
target
.
src
)
setAttempt
((
attempt
)
=>
++
attempt
)
},
[])
return
useMemo
(()
=>
{
// Trigger a re-render when an error occurs.
void
attempt
const
src
=
srcs
.
find
((
src
)
=>
!
badSrcs
.
has
(
src
))
if
(
!
src
)
return
<
MissingToken
color=
"secondary"
{
...
rest
}
/>
const
alt
=
tokenInfo
.
name
||
tokenInfo
.
symbol
return
<
img
src=
{
src
}
alt=
{
alt
}
key=
{
alt
}
onError=
{
onError
}
{
...
rest
}
/>
},
[
attempt
,
onError
,
rest
,
srcs
,
tokenInfo
.
name
,
tokenInfo
.
symbol
])
}
export
default
styled
(
TokenImg
)
<
{
size
?:
number
}
>
`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment