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
e39e5908
Unverified
Commit
e39e5908
authored
Apr 29, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drop the card in the position page
parent
c5424d2d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
46 deletions
+131
-46
usePositionTokenURI.ts
src/hooks/usePositionTokenURI.ts
+75
-0
PositionPage.tsx
src/pages/Pool/PositionPage.tsx
+56
-46
No files found.
src/hooks/usePositionTokenURI.ts
0 → 100644
View file @
e39e5908
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
,
1
_600_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
])
}
src/pages/Pool/PositionPage.tsx
View file @
e39e5908
...
@@ -5,10 +5,11 @@ import { useToken } from 'hooks/Tokens'
...
@@ -5,10 +5,11 @@ import { useToken } from 'hooks/Tokens'
import
{
useV3PositionFromTokenId
}
from
'
hooks/useV3Positions
'
import
{
useV3PositionFromTokenId
}
from
'
hooks/useV3Positions
'
import
{
Link
,
RouteComponentProps
}
from
'
react-router-dom
'
import
{
Link
,
RouteComponentProps
}
from
'
react-router-dom
'
import
{
unwrappedToken
}
from
'
utils/wrappedCurrency
'
import
{
unwrappedToken
}
from
'
utils/wrappedCurrency
'
import
{
usePositionTokenURI
}
from
'
../../hooks/usePositionTokenURI
'
import
{
LoadingRows
}
from
'
./styleds
'
import
{
LoadingRows
}
from
'
./styleds
'
import
styled
from
'
styled-components
'
import
styled
from
'
styled-components
'
import
{
AutoColumn
}
from
'
components/Column
'
import
{
AutoColumn
}
from
'
components/Column
'
import
{
RowBetween
,
RowFixed
}
from
'
components/Row
'
import
Row
,
{
RowBetween
,
RowFixed
}
from
'
components/Row
'
import
DoubleCurrencyLogo
from
'
components/DoubleLogo
'
import
DoubleCurrencyLogo
from
'
components/DoubleLogo
'
import
{
ButtonText
,
TYPE
}
from
'
theme
'
import
{
ButtonText
,
TYPE
}
from
'
theme
'
import
Badge
,
{
BadgeVariant
}
from
'
components/Badge
'
import
Badge
,
{
BadgeVariant
}
from
'
components/Badge
'
...
@@ -140,6 +141,8 @@ export function PositionPage({
...
@@ -140,6 +141,8 @@ export function PositionPage({
const
token0
=
useToken
(
token0Address
)
const
token0
=
useToken
(
token0Address
)
const
token1
=
useToken
(
token1Address
)
const
token1
=
useToken
(
token1Address
)
const
metadata
=
usePositionTokenURI
(
parsedTokenId
)
const
currency0
=
token0
?
unwrappedToken
(
token0
)
:
undefined
const
currency0
=
token0
?
unwrappedToken
(
token0
)
:
undefined
const
currency1
=
token1
?
unwrappedToken
(
token1
)
:
undefined
const
currency1
=
token1
?
unwrappedToken
(
token1
)
:
undefined
...
@@ -312,52 +315,59 @@ export function PositionPage({
...
@@ -312,52 +315,59 @@ export function PositionPage({
</
BadgeWrapper
>
</
BadgeWrapper
>
</
RowBetween
>
</
RowBetween
>
</
AutoColumn
>
</
AutoColumn
>
<
DarkCard
>
<
Row
align=
"stretch"
>
<
AutoColumn
gap=
"lg"
>
{
'
result
'
in
metadata
?
(
<
ResponsiveGrid
>
<
div
style=
{
{
marginRight
:
12
}
}
>
<
Label
>
Tokens
</
Label
>
<
img
src=
{
metadata
.
result
.
image
}
/>
<
Label
end=
{
true
}
>
Liquidity
</
Label
>
</
div
>
<
Label
end=
{
true
}
>
Fees
</
Label
>
)
:
null
}
</
ResponsiveGrid
>
<
DarkCard
>
<
ResponsiveGrid
>
<
AutoColumn
gap=
"lg"
>
<
RowFixed
>
<
ResponsiveGrid
>
<
CurrencyLogo
currency=
{
currencyQuote
}
/>
<
Label
>
Tokens
</
Label
>
<
TYPE
.
label
ml=
"10px"
>
{
currencyQuote
?.
symbol
}
</
TYPE
.
label
>
<
Label
end=
{
true
}
>
Liquidity
</
Label
>
</
RowFixed
>
<
Label
end=
{
true
}
>
Fees
</
Label
>
<
Label
end=
{
true
}
>
</
ResponsiveGrid
>
{
inverted
?
position
?.
amount0
.
toSignificant
(
4
)
:
position
?.
amount1
.
toSignificant
(
4
)
}
<
ResponsiveGrid
>
</
Label
>
<
RowFixed
>
<
Label
end=
{
true
}
>
<
CurrencyLogo
currency=
{
currencyQuote
}
/>
{
inverted
<
TYPE
.
label
ml=
"10px"
>
{
currencyQuote
?.
symbol
}
</
TYPE
.
label
>
?
feeValue0
</
RowFixed
>
?
formatTokenAmount
(
feeValue0
,
4
)
<
Label
end=
{
true
}
>
:
'
-
'
{
inverted
?
position
?.
amount0
.
toSignificant
(
4
)
:
position
?.
amount1
.
toSignificant
(
4
)
}
:
feeValue1
</
Label
>
?
formatTokenAmount
(
feeValue1
,
4
)
<
Label
end=
{
true
}
>
:
'
-
'
}
{
inverted
</
Label
>
?
feeValue0
</
ResponsiveGrid
>
?
formatTokenAmount
(
feeValue0
,
4
)
<
ResponsiveGrid
>
:
'
-
'
<
RowFixed
>
:
feeValue1
<
CurrencyLogo
currency=
{
currencyBase
}
/>
<
TYPE
.
label
ml=
"10px"
>
{
currencyBase
?.
symbol
}
</
TYPE
.
label
>
</
RowFixed
>
<
Label
end=
{
true
}
>
{
inverted
?
position
?.
amount1
.
toSignificant
(
4
)
:
position
?.
amount0
.
toSignificant
(
4
)
}
</
Label
>
<
Label
end=
{
true
}
>
{
inverted
?
feeValue1
?
formatTokenAmount
(
feeValue1
,
4
)
?
formatTokenAmount
(
feeValue1
,
4
)
:
'
-
'
:
'
-
'
}
:
feeValue0
</
Label
>
?
formatTokenAmount
(
feeValue0
,
4
)
</
ResponsiveGrid
>
:
'
-
'
}
<
ResponsiveGrid
>
</
Label
>
<
RowFixed
>
</
ResponsiveGrid
>
<
CurrencyLogo
currency=
{
currencyBase
}
/>
</
AutoColumn
>
<
TYPE
.
label
ml=
"10px"
>
{
currencyBase
?.
symbol
}
</
TYPE
.
label
>
</
DarkCard
>
</
RowFixed
>
<
Label
end=
{
true
}
>
{
inverted
?
position
?.
amount1
.
toSignificant
(
4
)
:
position
?.
amount0
.
toSignificant
(
4
)
}
</
Label
>
<
Label
end=
{
true
}
>
{
inverted
?
feeValue1
?
formatTokenAmount
(
feeValue1
,
4
)
:
'
-
'
:
feeValue0
?
formatTokenAmount
(
feeValue0
,
4
)
:
'
-
'
}
</
Label
>
</
ResponsiveGrid
>
</
AutoColumn
>
</
DarkCard
>
</
Row
>
<
DarkCard
>
<
DarkCard
>
<
AutoColumn
gap=
"lg"
>
<
AutoColumn
gap=
"lg"
>
<
TYPE
.
label
display=
"flex"
>
<
TYPE
.
label
display=
"flex"
>
...
...
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