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
9b5261aa
Unverified
Commit
9b5261aa
authored
Jul 17, 2023
by
Jack Short
Committed by
GitHub
Jul 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: v2 liquidity divide by zero (#6921)
parent
0efb7f51
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
6 deletions
+42
-6
PoolPriceBar.test.tsx
src/pages/AddLiquidityV2/PoolPriceBar.test.tsx
+31
-0
PoolPriceBar.tsx
src/pages/AddLiquidityV2/PoolPriceBar.tsx
+11
-6
No files found.
src/pages/AddLiquidityV2/PoolPriceBar.test.tsx
0 → 100644
View file @
9b5261aa
import
{
Price
,
WETH9
}
from
'
@uniswap/sdk-core
'
import
{
USDC_MAINNET
}
from
'
constants/tokens
'
import
{
Field
}
from
'
state/mint/actions
'
import
{
render
,
screen
}
from
'
test-utils/render
'
import
{
PoolPriceBar
}
from
'
./PoolPriceBar
'
const
currencies
=
{
[
Field
.
CURRENCY_A
]:
WETH9
[
1
],
[
Field
.
CURRENCY_B
]:
USDC_MAINNET
,
}
const
price
=
new
Price
(
currencies
[
Field
.
CURRENCY_A
],
currencies
[
Field
.
CURRENCY_B
],
1234
,
1
)
describe
(
'
pool price bar
'
,
()
=>
{
it
(
'
correctly renders the correct pool prices
'
,
()
=>
{
render
(<
PoolPriceBar
currencies=
{
currencies
}
price=
{
price
}
noLiquidity=
{
false
}
poolTokenPercentage=
{
undefined
}
/>)
expect
(
screen
.
getByTestId
(
'
currency-b-price
'
).
textContent
).
toBe
(
'
810373000
'
)
expect
(
screen
.
getByTestId
(
'
currency-a-price
'
).
textContent
).
toBe
(
'
0.000000001234
'
)
})
it
(
'
handles undefined price
'
,
()
=>
{
render
(
<
PoolPriceBar
currencies=
{
currencies
}
price=
{
undefined
}
noLiquidity=
{
false
}
poolTokenPercentage=
{
undefined
}
/>
)
expect
(
screen
.
getByTestId
(
'
currency-b-price
'
).
textContent
).
toBe
(
'
-
'
)
expect
(
screen
.
getByTestId
(
'
currency-a-price
'
).
textContent
).
toBe
(
'
-
'
)
})
})
src/pages/AddLiquidityV2/PoolPriceBar.tsx
View file @
9b5261aa
...
@@ -21,16 +21,21 @@ export function PoolPriceBar({
...
@@ -21,16 +21,21 @@ export function PoolPriceBar({
price
?:
Price
<
Currency
,
Currency
>
price
?:
Price
<
Currency
,
Currency
>
})
{
})
{
const
theme
=
useTheme
()
const
theme
=
useTheme
()
const
canInvertPrice
=
Boolean
(
price
&&
price
.
baseCurrency
&&
price
.
quoteCurrency
&&
!
price
.
baseCurrency
.
equals
(
price
.
quoteCurrency
)
let
invertedPrice
:
string
|
undefined
)
try
{
const
invertedPrice
=
canInvertPrice
?
price
?.
invert
()?.
toSignificant
(
6
)
:
undefined
invertedPrice
=
price
?.
invert
()?.
toSignificant
(
6
)
}
catch
(
error
)
{
invertedPrice
=
undefined
}
return
(
return
(
<
AutoColumn
gap=
"md"
>
<
AutoColumn
gap=
"md"
>
<
AutoRow
justify=
"space-around"
gap=
"4px"
>
<
AutoRow
justify=
"space-around"
gap=
"4px"
>
<
AutoColumn
justify=
"center"
>
<
AutoColumn
justify=
"center"
>
<
ThemedText
.
DeprecatedBlack
>
{
price
?.
toSignificant
(
6
)
??
'
-
'
}
</
ThemedText
.
DeprecatedBlack
>
<
ThemedText
.
DeprecatedBlack
data
-
testid=
"currency-b-price"
>
{
price
?.
toSignificant
(
6
)
??
'
-
'
}
</
ThemedText
.
DeprecatedBlack
>
<
Text
fontWeight=
{
500
}
fontSize=
{
14
}
color=
{
theme
.
textSecondary
}
pt=
{
1
}
>
<
Text
fontWeight=
{
500
}
fontSize=
{
14
}
color=
{
theme
.
textSecondary
}
pt=
{
1
}
>
<
Trans
>
<
Trans
>
{
currencies
[
Field
.
CURRENCY_B
]?.
symbol
}
per
{
currencies
[
Field
.
CURRENCY_A
]?.
symbol
}
{
currencies
[
Field
.
CURRENCY_B
]?.
symbol
}
per
{
currencies
[
Field
.
CURRENCY_A
]?.
symbol
}
...
@@ -38,7 +43,7 @@ export function PoolPriceBar({
...
@@ -38,7 +43,7 @@ export function PoolPriceBar({
</
Text
>
</
Text
>
</
AutoColumn
>
</
AutoColumn
>
<
AutoColumn
justify=
"center"
>
<
AutoColumn
justify=
"center"
>
<
ThemedText
.
DeprecatedBlack
>
{
invertedPrice
??
'
-
'
}
</
ThemedText
.
DeprecatedBlack
>
<
ThemedText
.
DeprecatedBlack
data
-
testid=
"currency-a-price"
>
{
invertedPrice
??
'
-
'
}
</
ThemedText
.
DeprecatedBlack
>
<
Text
fontWeight=
{
500
}
fontSize=
{
14
}
color=
{
theme
.
textSecondary
}
pt=
{
1
}
>
<
Text
fontWeight=
{
500
}
fontSize=
{
14
}
color=
{
theme
.
textSecondary
}
pt=
{
1
}
>
<
Trans
>
<
Trans
>
{
currencies
[
Field
.
CURRENCY_A
]?.
symbol
}
per
{
currencies
[
Field
.
CURRENCY_B
]?.
symbol
}
{
currencies
[
Field
.
CURRENCY_A
]?.
symbol
}
per
{
currencies
[
Field
.
CURRENCY_B
]?.
symbol
}
...
...
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