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
fd1ee61d
Unverified
Commit
fd1ee61d
authored
Jan 11, 2023
by
Mike Grabowski
Committed by
GitHub
Jan 11, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: crash when invalid ENS avatar (#5810)
* chore: fix invalid ens * chore: unwanted
parent
de71f07b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
12 deletions
+16
-12
useENSAvatar.ts
src/hooks/useENSAvatar.ts
+16
-12
No files found.
src/hooks/useENSAvatar.ts
View file @
fd1ee61d
...
...
@@ -77,8 +77,8 @@ function useAvatarFromNFT(nftUri = '', enforceOwnership: boolean): { avatar?: st
const
[
contractAddress
,
id
]
=
parts
[
2
]?.
split
(
'
/
'
)
??
[]
const
isERC721
=
protocol
===
'
eip155
'
&&
erc
===
'
erc721
'
const
isERC1155
=
protocol
===
'
eip155
'
&&
erc
===
'
erc1155
'
const
erc721
=
useERC721Uri
(
isERC721
?
contractAddress
:
undefined
,
id
,
enforceOwnership
)
const
erc1155
=
useERC1155Uri
(
isERC1155
?
contractAddress
:
undefined
,
id
,
enforceOwnership
)
const
erc721
=
useERC721Uri
(
isERC721
?
contractAddress
:
undefined
,
i
sERC721
?
id
:
undefine
d
,
enforceOwnership
)
const
erc1155
=
useERC1155Uri
(
isERC1155
?
contractAddress
:
undefined
,
i
sERC1155
?
id
:
undefine
d
,
enforceOwnership
)
const
uri
=
erc721
.
uri
||
erc1155
.
uri
const
http
=
uri
&&
uriToHttp
(
uri
)[
0
]
...
...
@@ -136,14 +136,18 @@ function useERC1155Uri(
const
contract
=
useERC1155Contract
(
contractAddress
)
const
balance
=
useSingleCallResult
(
contract
,
'
balanceOf
'
,
accountArgument
)
const
uri
=
useSingleCallResult
(
contract
,
'
uri
'
,
idArgument
)
return
useMemo
(()
=>
{
try
{
// ERC-1155 allows a generic {id} in the URL, so prepare to replace if relevant,
// in lowercase hexadecimal (with no 0x prefix) and leading zero padded to 64 hex characters.
const
idHex
=
id
?
hexZeroPad
(
BigNumber
.
from
(
id
).
toHexString
(),
32
).
substring
(
2
)
:
id
return
useMemo
(
()
=>
({
return
{
uri
:
!
enforceOwnership
||
balance
.
result
?.[
0
]
>
0
?
uri
.
result
?.[
0
]?.
replaceAll
(
'
{id}
'
,
idHex
)
:
undefined
,
loading
:
balance
.
loading
||
uri
.
loading
,
}),
[
balance
.
loading
,
balance
.
result
,
enforceOwnership
,
uri
.
loading
,
uri
.
result
,
idHex
]
)
}
}
catch
(
error
)
{
console
.
error
(
'
Invalid token id
'
,
error
)
return
{
loading
:
false
}
}
},
[
balance
.
loading
,
balance
.
result
,
enforceOwnership
,
uri
.
loading
,
uri
.
result
,
id
])
}
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