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
13254430
Unverified
Commit
13254430
authored
May 04, 2021
by
Noah Zinsmeister
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ratio bugs
parent
1607f891
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
27 deletions
+26
-27
PositionPage.tsx
src/pages/Pool/PositionPage.tsx
+26
-27
No files found.
src/pages/Pool/PositionPage.tsx
View file @
13254430
...
@@ -131,16 +131,12 @@ function CurrentPriceCard({
...
@@ -131,16 +131,12 @@ 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
theme
=
useTheme
()
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
if
(
!
pool
||
!
currencyQuote
||
!
currencyBase
)
{
if
(
!
pool
||
!
currencyQuote
||
!
currencyBase
)
{
return
null
return
null
...
@@ -155,26 +151,23 @@ function CurrentPriceCard({
...
@@ -155,26 +151,23 @@ function CurrentPriceCard({
</
TYPE
.
mediumHeader
>
</
TYPE
.
mediumHeader
>
<
ExtentsText
>
{
currencyQuote
?.
symbol
+
'
/
'
+
currencyBase
?.
symbol
}
</
ExtentsText
>
<
ExtentsText
>
{
currencyQuote
?.
symbol
+
'
/
'
+
currencyBase
?.
symbol
}
</
ExtentsText
>
</
AutoColumn
>
</
AutoColumn
>
{
typeof
ratio
===
'
number
'
&&
(
<
TYPE
.
small
color=
{
theme
.
text3
}
textAlign=
"center"
style=
{
{
marginTop
:
'
8px
'
}
}
>
Your position is currently
{
ratio
}
%
{
currencyBase
?.
symbol
}
and
{
100
-
ratio
}
%
{
currencyQuote
?.
symbol
}
</
TYPE
.
small
>
)
}
</
LightCard
>
</
LightCard
>
)
)
}
}
function
getRatio
(
lower
:
Price
,
current
:
Price
,
upper
:
Price
)
{
function
getRatio
(
lower
:
Price
,
current
:
Price
,
upper
:
Price
)
{
try
{
try
{
if
(
!
current
.
greaterThan
(
lower
))
{
return
100
}
else
if
(
!
current
.
lessThan
(
upper
))
{
return
0
}
const
a
=
Number
.
parseFloat
(
lower
.
toSignificant
(
15
))
const
a
=
Number
.
parseFloat
(
lower
.
toSignificant
(
15
))
const
b
=
Number
.
parseFloat
(
upper
.
toSignificant
(
15
))
const
b
=
Number
.
parseFloat
(
upper
.
toSignificant
(
15
))
const
c
=
Number
.
parseFloat
(
current
.
toSignificant
(
15
))
const
c
=
Number
.
parseFloat
(
current
.
toSignificant
(
15
))
let
ratio
=
Math
.
floor
(((
Math
.
sqrt
(
a
*
b
)
-
Math
.
sqrt
(
b
*
c
))
/
(
c
-
Math
.
sqrt
(
b
*
c
)))
*
100
)
const
ratio
=
Math
.
floor
((
1
/
((
Math
.
sqrt
(
a
*
b
)
-
Math
.
sqrt
(
b
*
c
))
/
(
c
-
Math
.
sqrt
(
b
*
c
))
+
1
))
*
100
)
if
(
ratio
>
100
)
{
ratio
-=
100
}
if
(
ratio
<
0
||
ratio
>
100
)
{
if
(
ratio
<
0
||
ratio
>
100
)
{
throw
Error
(
'
Out of range
'
)
throw
Error
(
'
Out of range
'
)
...
@@ -243,6 +236,9 @@ export function PositionPage({
...
@@ -243,6 +236,9 @@ export function PositionPage({
:
undefined
:
undefined
},
[
inverted
,
pool
,
priceLower
,
priceUpper
])
},
[
inverted
,
pool
,
priceLower
,
priceUpper
])
// really can't figure out why i have to do this, getting conditional hook call errors otherwise
const
WORKAROUND
=
typeof
ratio
===
'
number
'
?
(
inverted
?
100
-
ratio
:
ratio
)
:
undefined
// fees
// fees
const
[
feeValue0
,
feeValue1
]
=
useV3PositionFees
(
pool
??
undefined
,
positionDetails
)
const
[
feeValue0
,
feeValue1
]
=
useV3PositionFees
(
pool
??
undefined
,
positionDetails
)
...
@@ -497,12 +493,12 @@ export function PositionPage({
...
@@ -497,12 +493,12 @@ export function PositionPage({
</
RowFixed
>
</
RowFixed
>
<
RowFixed
>
<
RowFixed
>
<
TYPE
.
main
>
<
TYPE
.
main
>
{
inverted
?
position
?.
amount0
.
toSignificant
(
4
)
:
position
?.
amount1
.
toSignificant
(
4
)
}
(
{
inverted
?
position
?.
amount0
.
toSignificant
(
4
)
:
position
?.
amount1
.
toSignificant
(
4
)
}
</
TYPE
.
main
>
</
TYPE
.
main
>
{
typeof
ratio
===
'
number
'
&&
(
{
typeof
ratio
===
'
number
'
&&
(
<
DarkGreyCard
padding=
"4px 6px"
style=
{
{
width
:
'
fit-content
'
,
marginLeft
:
'
8px
'
}
}
>
<
DarkGreyCard
padding=
"4px 6px"
style=
{
{
width
:
'
fit-content
'
,
marginLeft
:
'
8px
'
}
}
>
<
TYPE
.
main
color=
{
theme
.
text2
}
fontSize=
{
11
}
>
<
TYPE
.
main
color=
{
theme
.
text2
}
fontSize=
{
11
}
>
{
100
-
ratio
}
%
{
inverted
?
ratio
:
100
-
ratio
}
%
</
TYPE
.
main
>
</
TYPE
.
main
>
</
DarkGreyCard
>
</
DarkGreyCard
>
)
}
)
}
...
@@ -515,12 +511,12 @@ export function PositionPage({
...
@@ -515,12 +511,12 @@ export function PositionPage({
</
RowFixed
>
</
RowFixed
>
<
RowFixed
>
<
RowFixed
>
<
TYPE
.
main
>
<
TYPE
.
main
>
{
inverted
?
position
?.
amount1
.
toSignificant
(
4
)
:
position
?.
amount0
.
toSignificant
(
4
)
}
(
{
inverted
?
position
?.
amount1
.
toSignificant
(
4
)
:
position
?.
amount0
.
toSignificant
(
4
)
}
</
TYPE
.
main
>
</
TYPE
.
main
>
{
typeof
ratio
===
'
number
'
&&
(
{
typeof
ratio
===
'
number
'
&&
(
<
DarkGreyCard
padding=
"4px 6px"
style=
{
{
width
:
'
fit-content
'
,
marginLeft
:
'
8px
'
}
}
>
<
DarkGreyCard
padding=
"4px 6px"
style=
{
{
width
:
'
fit-content
'
,
marginLeft
:
'
8px
'
}
}
>
<
TYPE
.
main
color=
{
theme
.
text2
}
fontSize=
{
11
}
>
<
TYPE
.
main
color=
{
theme
.
text2
}
fontSize=
{
11
}
>
{
ratio
}
%
{
WORKAROUND
}
%
</
TYPE
.
main
>
</
TYPE
.
main
>
</
DarkGreyCard
>
</
DarkGreyCard
>
)
}
)
}
...
@@ -644,10 +640,12 @@ export function PositionPage({
...
@@ -644,10 +640,12 @@ export function PositionPage({
<
ExtentsText
>
Min price
</
ExtentsText
>
<
ExtentsText
>
Min price
</
ExtentsText
>
<
TYPE
.
mediumHeader
textAlign=
"center"
>
{
priceLower
?.
toSignificant
(
4
)
}
</
TYPE
.
mediumHeader
>
<
TYPE
.
mediumHeader
textAlign=
"center"
>
{
priceLower
?.
toSignificant
(
4
)
}
</
TYPE
.
mediumHeader
>
<
ExtentsText
>
{
currencyQuote
?.
symbol
+
'
/
'
+
currencyBase
?.
symbol
}
</
ExtentsText
>
<
ExtentsText
>
{
currencyQuote
?.
symbol
+
'
/
'
+
currencyBase
?.
symbol
}
</
ExtentsText
>
{
inRange
&&
(
<
TYPE
.
small
color=
{
theme
.
text3
}
>
<
TYPE
.
small
color=
{
theme
.
text3
}
>
{
'
Your position is will be 100%
'
}
Your position will be 100%
{
currencyBase
?.
symbol
}
at this price.
{
currencyBase
?.
symbol
}
{
'
at this price.
'
}
</
TYPE
.
small
>
</
TYPE
.
small
>
)
}
</
AutoColumn
>
</
AutoColumn
>
</
LightCard
>
</
LightCard
>
...
@@ -657,10 +655,12 @@ export function PositionPage({
...
@@ -657,10 +655,12 @@ export function PositionPage({
<
ExtentsText
>
Max price
</
ExtentsText
>
<
ExtentsText
>
Max price
</
ExtentsText
>
<
TYPE
.
mediumHeader
textAlign=
"center"
>
{
priceUpper
?.
toSignificant
(
4
)
}
</
TYPE
.
mediumHeader
>
<
TYPE
.
mediumHeader
textAlign=
"center"
>
{
priceUpper
?.
toSignificant
(
4
)
}
</
TYPE
.
mediumHeader
>
<
ExtentsText
>
{
currencyQuote
?.
symbol
+
'
/
'
+
currencyBase
?.
symbol
}
</
ExtentsText
>
<
ExtentsText
>
{
currencyQuote
?.
symbol
+
'
/
'
+
currencyBase
?.
symbol
}
</
ExtentsText
>
{
inRange
&&
(
<
TYPE
.
small
color=
{
theme
.
text3
}
>
<
TYPE
.
small
color=
{
theme
.
text3
}
>
{
'
Your position is will be 100%
'
}
Your position will be 100%
{
currencyQuote
?.
symbol
}
at this price.
{
currencyQuote
?.
symbol
}
{
'
at this price.
'
}
</
TYPE
.
small
>
</
TYPE
.
small
>
)
}
</
AutoColumn
>
</
AutoColumn
>
</
LightCard
>
</
LightCard
>
</
RowBetween
>
</
RowBetween
>
...
@@ -669,7 +669,6 @@ export function PositionPage({
...
@@ -669,7 +669,6 @@ 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