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
3af67818
Unverified
Commit
3af67818
authored
May 03, 2021
by
Noah Zinsmeister
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add % breakdown for assets in range
closes #64
parent
4c2cb5b0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
1 deletion
+36
-1
PositionPage.tsx
src/pages/Pool/PositionPage.tsx
+36
-1
No files found.
src/pages/Pool/PositionPage.tsx
View file @
3af67818
...
@@ -23,7 +23,7 @@ import { currencyId } from 'utils/currencyId'
...
@@ -23,7 +23,7 @@ import { currencyId } from 'utils/currencyId'
import
{
formatTokenAmount
}
from
'
utils/formatTokenAmount
'
import
{
formatTokenAmount
}
from
'
utils/formatTokenAmount
'
import
{
useV3PositionFees
}
from
'
hooks/useV3PositionFees
'
import
{
useV3PositionFees
}
from
'
hooks/useV3PositionFees
'
import
{
BigNumber
}
from
'
@ethersproject/bignumber
'
import
{
BigNumber
}
from
'
@ethersproject/bignumber
'
import
{
WETH9
,
Currency
,
CurrencyAmount
,
Percent
,
Fraction
}
from
'
@uniswap/sdk-core
'
import
{
WETH9
,
Currency
,
CurrencyAmount
,
Percent
,
Fraction
,
Price
}
from
'
@uniswap/sdk-core
'
import
{
useActiveWeb3React
}
from
'
hooks
'
import
{
useActiveWeb3React
}
from
'
hooks
'
import
{
useV3NFTPositionManagerContract
}
from
'
hooks/useContract
'
import
{
useV3NFTPositionManagerContract
}
from
'
hooks/useContract
'
import
{
useIsTransactionPending
,
useTransactionAdder
}
from
'
state/transactions/hooks
'
import
{
useIsTransactionPending
,
useTransactionAdder
}
from
'
state/transactions/hooks
'
...
@@ -104,11 +104,13 @@ function CurrentPriceCard({
...
@@ -104,11 +104,13 @@ function CurrentPriceCard({
pool
,
pool
,
currencyQuote
,
currencyQuote
,
currencyBase
,
currencyBase
,
ratio
,
}:
{
}:
{
inverted
?:
boolean
inverted
?:
boolean
pool
?:
Pool
|
null
pool
?:
Pool
|
null
currencyQuote
?:
Currency
currencyQuote
?:
Currency
currencyBase
?:
Currency
currencyBase
?:
Currency
ratio
?:
number
})
{
})
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
if
(
!
pool
||
!
currencyQuote
||
!
currencyBase
)
{
if
(
!
pool
||
!
currencyQuote
||
!
currencyBase
)
{
...
@@ -122,11 +124,34 @@ function CurrentPriceCard({
...
@@ -122,11 +124,34 @@ function CurrentPriceCard({
<
TYPE
.
label
textAlign=
"center"
>
<
TYPE
.
label
textAlign=
"center"
>
{
(
inverted
?
pool
.
token1Price
:
pool
.
token0Price
).
toSignificant
(
4
)
}
{
currencyQuote
?.
symbol
}
{
(
inverted
?
pool
.
token1Price
:
pool
.
token0Price
).
toSignificant
(
4
)
}
{
currencyQuote
?.
symbol
}
</
TYPE
.
label
>
</
TYPE
.
label
>
{
typeof
ratio
===
'
number
'
&&
(
<
TYPE
.
label
textAlign=
"center"
>
Your position is
<
CurrencyLogo
currency=
{
currencyBase
}
size=
"12px"
/>
{
ratio
}
%
{
currencyBase
?.
symbol
}
and
{
'
'
}
<
CurrencyLogo
currency=
{
currencyQuote
}
size=
"12px"
/>
{
100
-
ratio
}
%
{
currencyQuote
?.
symbol
}
</
TYPE
.
label
>
)
}
</
AutoColumn
>
</
AutoColumn
>
</
LightCard
>
</
LightCard
>
)
)
}
}
function
getRatio
(
lower
:
Price
,
current
:
Price
,
upper
:
Price
)
{
try
{
const
a
=
Number
.
parseFloat
(
lower
.
toSignificant
(
15
))
const
b
=
Number
.
parseFloat
(
upper
.
toSignificant
(
15
))
const
c
=
Number
.
parseFloat
(
current
.
toSignificant
(
15
))
const
ratio
=
Math
.
floor
(((
Math
.
sqrt
(
a
*
b
)
-
Math
.
sqrt
(
b
*
c
))
/
(
c
-
Math
.
sqrt
(
b
*
c
)))
*
100
)
if
(
ratio
<
0
||
ratio
>
100
)
{
throw
Error
(
'
Precision error
'
)
}
return
ratio
}
catch
{
return
undefined
}
}
export
function
PositionPage
({
export
function
PositionPage
({
match
:
{
match
:
{
params
:
{
tokenId
:
tokenIdFromUrl
},
params
:
{
tokenId
:
tokenIdFromUrl
},
...
@@ -179,6 +204,15 @@ export function PositionPage({
...
@@ -179,6 +204,15 @@ export function PositionPage({
// const below = pool && typeof tickLower === 'number' ? pool.tickCurrent < tickLower : false
// const below = pool && typeof tickLower === 'number' ? pool.tickCurrent < tickLower : false
// const above = pool && typeof tickUpper === 'number' ? pool.tickCurrent >= tickUpper : false
// const above = pool && typeof tickUpper === 'number' ? pool.tickCurrent >= tickUpper : false
const
ratio
=
priceLower
&&
pool
&&
priceUpper
?
getRatio
(
inverted
?
priceUpper
.
invert
()
:
priceLower
,
pool
.
token0Price
,
inverted
?
priceLower
.
invert
()
:
priceUpper
)
:
undefined
// fees
// fees
const
[
feeValue0
,
feeValue1
]
=
useV3PositionFees
(
pool
??
undefined
,
positionDetails
)
const
[
feeValue0
,
feeValue1
]
=
useV3PositionFees
(
pool
??
undefined
,
positionDetails
)
...
@@ -513,6 +547,7 @@ export function PositionPage({
...
@@ -513,6 +547,7 @@ export function PositionPage({
pool=
{
pool
}
pool=
{
pool
}
currencyQuote=
{
currencyQuote
}
currencyQuote=
{
currencyQuote
}
currencyBase=
{
currencyBase
}
currencyBase=
{
currencyBase
}
ratio=
{
typeof
ratio
===
'
number
'
&&
inRange
?
(
inverted
?
100
-
ratio
:
ratio
)
:
undefined
}
/>
/>
</
AutoColumn
>
</
AutoColumn
>
</
DarkCard
>
</
DarkCard
>
...
...
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