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
709f0299
Unverified
Commit
709f0299
authored
Nov 29, 2021
by
Zach Pomerantz
Committed by
GitHub
Nov 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: remove orphaned node (#2863)
* fix: remove orphaned node * fix: react cleanup
parent
6b57ffe3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
+15
-14
index.tsx
src/components/Identicon/index.tsx
+15
-14
No files found.
src/components/Identicon/index.tsx
View file @
709f0299
import
jazzicon
from
'
@metamask/jazzicon
'
import
jazzicon
from
'
@metamask/jazzicon
'
import
useENSAvatar
from
'
hooks/useENSAvatar
'
import
useENSAvatar
from
'
hooks/useENSAvatar
'
import
{
use
Effect
,
useRef
,
useState
}
from
'
react
'
import
{
use
Callback
,
useState
}
from
'
react
'
import
styled
from
'
styled-components/macro
'
import
styled
from
'
styled-components/macro
'
import
{
useActiveWeb3React
}
from
'
../../hooks/web3
'
import
{
useActiveWeb3React
}
from
'
../../hooks/web3
'
...
@@ -20,27 +20,28 @@ const StyledAvatar = styled.img`
...
@@ -20,27 +20,28 @@ const StyledAvatar = styled.img`
`
`
export
default
function
Identicon
()
{
export
default
function
Identicon
()
{
const
ref
=
useRef
<
HTMLDivElement
>
(
null
)
const
{
account
}
=
useActiveWeb3React
()
const
{
account
}
=
useActiveWeb3React
()
const
{
avatar
}
=
useENSAvatar
(
account
??
undefined
)
const
{
avatar
}
=
useENSAvatar
(
account
??
undefined
)
const
[
fetchable
,
setFetchable
]
=
useState
(
true
)
const
[
fetchable
,
setFetchable
]
=
useState
(
true
)
useEffect
(()
=>
{
const
setJazzicon
=
useCallback
(
if
((
!
avatar
||
!
fetchable
)
&&
account
)
{
(
ref
:
HTMLSpanElement
|
null
)
=>
{
const
icon
=
jazzicon
(
16
,
parseInt
(
account
?.
slice
(
2
,
10
),
16
))
if
(
account
)
{
const
current
=
ref
.
current
ref
?.
appendChild
(
jazzicon
(
16
,
parseInt
(
account
?.
slice
(
2
,
10
),
16
)))
current
?.
appendChild
(
icon
)
return
()
=>
{
current
?.
removeChild
(
icon
)
}
}
}
}
,
return
[
account
]
},
[
account
,
avatar
,
fetchable
]
)
)
return
(
return
(
<
StyledIdenticon
ref=
{
ref
}
>
<
StyledIdenticon
>
{
avatar
&&
fetchable
&&
(
{
avatar
&&
fetchable
?
(
<
StyledAvatar
alt=
"avatar"
src=
{
avatar
}
onError=
{
()
=>
setFetchable
(
false
)
}
></
StyledAvatar
>
<
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
/>
)
}
)
}
</
StyledIdenticon
>
</
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