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
efdfdc90
Unverified
Commit
efdfdc90
authored
Nov 29, 2021
by
Zach Pomerantz
Committed by
GitHub
Nov 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: use ref for jazzicon (#2874)
parent
709f0299
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
index.tsx
src/components/Identicon/index.tsx
+13
-12
No files found.
src/components/Identicon/index.tsx
View file @
efdfdc90
import
jazzicon
from
'
@metamask/jazzicon
'
import
useENSAvatar
from
'
hooks/useENSAvatar
'
import
{
use
Callback
,
useState
}
from
'
react
'
import
{
use
LayoutEffect
,
useMemo
,
useRef
,
useState
}
from
'
react
'
import
styled
from
'
styled-components/macro
'
import
{
useActiveWeb3React
}
from
'
../../hooks/web3
'
...
...
@@ -24,24 +24,25 @@ export default function Identicon() {
const
{
avatar
}
=
useENSAvatar
(
account
??
undefined
)
const
[
fetchable
,
setFetchable
]
=
useState
(
true
)
const
setJazzicon
=
useCallback
(
(
ref
:
HTMLSpanElement
|
null
)
=>
{
if
(
account
)
{
ref
?.
appendChild
(
jazzicon
(
16
,
parseInt
(
account
?.
slice
(
2
,
10
),
16
)))
const
icon
=
useMemo
(()
=>
account
&&
jazzicon
(
16
,
parseInt
(
account
.
slice
(
2
,
10
),
16
)),
[
account
])
const
iconRef
=
useRef
<
HTMLDivElement
>
(
null
)
useLayoutEffect
(()
=>
{
const
current
=
iconRef
.
current
if
(
icon
)
{
current
?.
appendChild
(
icon
)
return
()
=>
{
current
?.
removeChild
(
icon
)
}
}
,
[
account
]
)
}
return
},
[
icon
,
iconRef
]
)
return
(
<
StyledIdenticon
>
{
avatar
&&
fetchable
?
(
<
StyledAvatar
alt=
"avatar"
src=
{
avatar
}
onError=
{
()
=>
setFetchable
(
false
)
}
></
StyledAvatar
>
)
:
(
<
span
ref=
{
setJazzicon
}
key=
{
account
}
// forces re-render when account changes so that React controls jazzicon cleanup
/>
<
span
ref=
{
iconRef
}
/>
)
}
</
StyledIdenticon
>
)
...
...
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