FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
uniswap-interface/src/hooks/usePositionTokenURI.ts at main · codeaudit/uniswap-interface · GitHub
codeaudit
/
uniswap-interface
Public
forked from
Uniswap/interface
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
uniswap-interface
/
src
/
hooks
/
usePositionTokenURI.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
79 lines (72 loc) · 1.79 KB
Breadcrumbs
uniswap-interface
/
src
/
hooks
/
usePositionTokenURI.ts
Copy path
File metadata and controls
79 lines (72 loc) · 1.79 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import
{
BigNumber
}
from
'ethers'
import
JSBI
from
'jsbi'
import
{
useMemo
}
from
'react'
import
{
NEVER_RELOAD
,
useSingleCallResult
}
from
'../state/multicall/hooks'
import
{
useV3NFTPositionManagerContract
}
from
'./useContract'
type
TokenId
=
number
|
JSBI
|
BigNumber
const
STARTS_WITH
=
'data:application/json;base64,'
type
UsePositionTokenURIResult
=
|
{
valid
:
true
loading
:
false
result
:
{
name
:
string
description
:
string
image
:
string
}
}
|
{
valid
:
false
loading
:
false
}
|
{
valid
:
true
loading
:
true
}
export
function
usePositionTokenURI
(
tokenId
:
TokenId
|
undefined
)
:
UsePositionTokenURIResult
{
const
contract
=
useV3NFTPositionManagerContract
(
)
const
inputs
=
useMemo
(
(
)
=>
[
tokenId
instanceof
BigNumber
?
tokenId
.
toHexString
(
)
:
tokenId
?.
toString
(
16
)
]
,
[
tokenId
]
)
const
{
result
,
error
,
loading
,
valid
}
=
useSingleCallResult
(
contract
,
'tokenURI'
,
inputs
,
{
...
NEVER_RELOAD
,
gasRequired
:
3_000_000
,
}
)
return
useMemo
(
(
)
=>
{
if
(
error
||
!
valid
||
!
tokenId
)
{
return
{
valid
:
false
,
loading
:
false
,
}
}
if
(
loading
)
{
return
{
valid
:
true
,
loading
:
true
,
}
}
if
(
!
result
)
{
return
{
valid
:
false
,
loading
:
false
,
}
}
const
[
tokenURI
]
=
result
as
[
string
]
if
(
!
tokenURI
||
!
tokenURI
.
startsWith
(
STARTS_WITH
)
)
return
{
valid
:
false
,
loading
:
false
,
}
try
{
const
json
=
JSON
.
parse
(
atob
(
tokenURI
.
slice
(
STARTS_WITH
.
length
)
)
)
return
{
valid
:
true
,
loading
:
false
,
result
:
json
,
}
}
catch
(
error
)
{
return
{
valid
:
false
,
loading
:
false
}
}
}
,
[
error
,
loading
,
result
,
tokenId
,
valid
]
)
}
Back
|
FazBrowse Home
|
New Git URL