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
3c3be3c6
Unverified
Commit
3c3be3c6
authored
Apr 28, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some unit tests
parent
7660943e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
17 deletions
+36
-17
SwapHeader.tsx
src/components/swap/SwapHeader.tsx
+2
-2
index.tsx
src/pages/Swap/index.tsx
+6
-10
prices.test.ts
src/utils/prices.test.ts
+21
-3
prices.ts
src/utils/prices.ts
+7
-2
No files found.
src/components/swap/SwapHeader.tsx
View file @
3c3be3c6
...
@@ -27,12 +27,12 @@ interface SwapHeaderProps {
...
@@ -27,12 +27,12 @@ interface SwapHeaderProps {
trade
?:
V2Trade
|
V3Trade
|
undefined
trade
?:
V2Trade
|
V3Trade
|
undefined
}
}
export
default
function
SwapHeader
({}:
SwapHeaderProps
)
{
export
default
function
SwapHeader
({
trade
}:
SwapHeaderProps
)
{
return
(
return
(
<
StyledSwapHeader
>
<
StyledSwapHeader
>
<
RowBetween
>
<
RowBetween
>
<
TYPE
.
black
fontWeight=
{
500
}
fontSize=
{
16
}
style=
{
{
opacity
:
'
0.6
'
}
}
>
<
TYPE
.
black
fontWeight=
{
500
}
fontSize=
{
16
}
style=
{
{
opacity
:
'
0.6
'
}
}
>
Swap
Swap
{
trade
instanceof
V2Trade
?
'
(V2)
'
:
trade
instanceof
V3Trade
?
'
(V3)
'
:
''
}
</
TYPE
.
black
>
</
TYPE
.
black
>
<
RowFixed
>
<
RowFixed
>
{
/* Send icon appears here when expert mode is toggled on */
}
{
/* Send icon appears here when expert mode is toggled on */
}
...
...
src/pages/Swap/index.tsx
View file @
3c3be3c6
...
@@ -305,6 +305,8 @@ export default function Swap({ history }: RouteComponentProps) {
...
@@ -305,6 +305,8 @@ export default function Swap({ history }: RouteComponentProps) {
const
[
showDetails
,
setShowDetails
]
=
useState
<
boolean
>
(
true
)
const
[
showDetails
,
setShowDetails
]
=
useState
<
boolean
>
(
true
)
const
priceImpactTooHigh
=
priceImpactSeverity
>
3
&&
!
isExpertMode
return
(
return
(
<>
<>
<
TokenWarningModal
<
TokenWarningModal
...
@@ -468,17 +470,11 @@ export default function Swap({ history }: RouteComponentProps) {
...
@@ -468,17 +470,11 @@ export default function Swap({ history }: RouteComponentProps) {
}
}
}
}
width=
"100%"
width=
"100%"
id=
"swap-button"
id=
"swap-button"
disabled=
{
disabled=
{
!
isValid
||
approvalState
!==
ApprovalState
.
APPROVED
||
priceImpactTooHigh
}
!
isValid
||
approvalState
!==
ApprovalState
.
APPROVED
||
(
priceImpactSeverity
>
3
&&
!
isExpertMode
)
}
error=
{
isValid
&&
priceImpactSeverity
>
2
}
error=
{
isValid
&&
priceImpactSeverity
>
2
}
>
>
<
Text
fontSize=
{
16
}
fontWeight=
{
500
}
>
<
Text
fontSize=
{
16
}
fontWeight=
{
500
}
>
{
priceImpactSeverity
>
3
&&
!
isExpertMode
{
priceImpactTooHigh
?
`Price Impact High`
:
`Swap${priceImpactSeverity > 2 ? ' Anyway' : ''}`
}
?
`Price Impact High`
:
`Swap${priceImpactSeverity > 2 ? ' Anyway' : ''}`
}
</
Text
>
</
Text
>
</
ButtonError
>
</
ButtonError
>
</
AutoColumn
>
</
AutoColumn
>
...
@@ -500,13 +496,13 @@ export default function Swap({ history }: RouteComponentProps) {
...
@@ -500,13 +496,13 @@ export default function Swap({ history }: RouteComponentProps) {
}
}
}
}
}
}
id=
"swap-button"
id=
"swap-button"
disabled=
{
!
isValid
||
(
priceImpactSeverity
>
3
&&
!
isExpertMode
)
||
!!
swapCallbackError
}
disabled=
{
!
isValid
||
priceImpactTooHigh
||
!!
swapCallbackError
}
error=
{
isValid
&&
priceImpactSeverity
>
2
&&
!
swapCallbackError
}
error=
{
isValid
&&
priceImpactSeverity
>
2
&&
!
swapCallbackError
}
>
>
<
Text
fontSize=
{
20
}
fontWeight=
{
500
}
>
<
Text
fontSize=
{
20
}
fontWeight=
{
500
}
>
{
swapInputError
{
swapInputError
?
swapInputError
?
swapInputError
:
priceImpact
Severity
>
3
&&
!
isExpertMode
:
priceImpact
TooHigh
?
`Price Impact Too High`
?
`Price Impact Too High`
:
`Swap${priceImpactSeverity > 2 ? ' Anyway' : ''}`
}
:
`Swap${priceImpactSeverity > 2 ? ' Anyway' : ''}`
}
</
Text
>
</
Text
>
...
...
src/utils/prices.test.ts
View file @
3c3be3c6
import
{
ChainId
,
Token
,
TokenAmount
,
TradeType
}
from
'
@uniswap/sdk-core
'
import
{
ChainId
,
Percent
,
Token
,
TokenAmount
,
TradeType
}
from
'
@uniswap/sdk-core
'
import
{
JSBI
,
Trade
,
Pair
,
Route
}
from
'
@uniswap/v2-sdk
'
import
{
JSBI
,
Trade
,
Pair
,
Route
}
from
'
@uniswap/v2-sdk
'
import
{
computeTradePriceBreakdown
}
from
'
./prices
'
import
{
computeTradePriceBreakdown
,
warningSeverity
}
from
'
./prices
'
describe
(
'
prices
'
,
()
=>
{
describe
(
'
prices
'
,
()
=>
{
const
token1
=
new
Token
(
ChainId
.
MAINNET
,
'
0x0000000000000000000000000000000000000001
'
,
18
)
const
token1
=
new
Token
(
ChainId
.
MAINNET
,
'
0x0000000000000000000000000000000000000001
'
,
18
)
...
@@ -10,7 +10,7 @@ describe('prices', () => {
...
@@ -10,7 +10,7 @@ describe('prices', () => {
const
pair12
=
new
Pair
(
new
TokenAmount
(
token1
,
JSBI
.
BigInt
(
10000
)),
new
TokenAmount
(
token2
,
JSBI
.
BigInt
(
20000
)))
const
pair12
=
new
Pair
(
new
TokenAmount
(
token1
,
JSBI
.
BigInt
(
10000
)),
new
TokenAmount
(
token2
,
JSBI
.
BigInt
(
20000
)))
const
pair23
=
new
Pair
(
new
TokenAmount
(
token2
,
JSBI
.
BigInt
(
20000
)),
new
TokenAmount
(
token3
,
JSBI
.
BigInt
(
30000
)))
const
pair23
=
new
Pair
(
new
TokenAmount
(
token2
,
JSBI
.
BigInt
(
20000
)),
new
TokenAmount
(
token3
,
JSBI
.
BigInt
(
30000
)))
describe
(
'
computeTradePriceBreakdown
'
,
()
=>
{
describe
(
'
#
computeTradePriceBreakdown
'
,
()
=>
{
it
(
'
returns undefined for undefined
'
,
()
=>
{
it
(
'
returns undefined for undefined
'
,
()
=>
{
expect
(
computeTradePriceBreakdown
(
undefined
)).
toEqual
({
expect
(
computeTradePriceBreakdown
(
undefined
)).
toEqual
({
priceImpactWithoutFee
:
undefined
,
priceImpactWithoutFee
:
undefined
,
...
@@ -38,4 +38,22 @@ describe('prices', () => {
...
@@ -38,4 +38,22 @@ describe('prices', () => {
).
toEqual
(
new
TokenAmount
(
token1
,
JSBI
.
BigInt
(
5
)))
).
toEqual
(
new
TokenAmount
(
token1
,
JSBI
.
BigInt
(
5
)))
})
})
})
})
describe
(
'
#warningSeverity
'
,
()
=>
{
it
(
'
max for undefined
'
,
()
=>
{
expect
(
warningSeverity
(
undefined
)).
toEqual
(
4
)
})
it
(
'
correct for 0
'
,
()
=>
{
expect
(
warningSeverity
(
new
Percent
(
0
))).
toEqual
(
0
)
})
it
(
'
correct for 0.5
'
,
()
=>
{
expect
(
warningSeverity
(
new
Percent
(
5
,
1000
))).
toEqual
(
0
)
})
it
(
'
correct for 5
'
,
()
=>
{
expect
(
warningSeverity
(
new
Percent
(
5
,
100
))).
toEqual
(
2
)
})
it
(
'
correct for 50
'
,
()
=>
{
expect
(
warningSeverity
(
new
Percent
(
5
,
10
))).
toEqual
(
4
)
})
})
})
})
src/utils/prices.ts
View file @
3c3be3c6
...
@@ -45,7 +45,7 @@ export function computeTradePriceBreakdown(
...
@@ -45,7 +45,7 @@ export function computeTradePriceBreakdown(
:
CurrencyAmount
.
ether
(
realizedLPFee
.
multiply
(
trade
.
inputAmount
.
raw
).
quotient
))
:
CurrencyAmount
.
ether
(
realizedLPFee
.
multiply
(
trade
.
inputAmount
.
raw
).
quotient
))
return
{
priceImpactWithoutFee
:
priceImpactWithoutFeePercent
,
realizedLPFee
:
realizedLPFeeAmount
}
return
{
priceImpactWithoutFee
:
priceImpactWithoutFeePercent
,
realizedLPFee
:
realizedLPFeeAmount
}
}
else
{
}
else
if
(
trade
instanceof
V3Trade
)
{
const
realizedLPFee
=
!
trade
const
realizedLPFee
=
!
trade
?
undefined
?
undefined
:
ONE_HUNDRED_PERCENT
.
subtract
(
:
ONE_HUNDRED_PERCENT
.
subtract
(
...
@@ -67,6 +67,11 @@ export function computeTradePriceBreakdown(
...
@@ -67,6 +67,11 @@ export function computeTradePriceBreakdown(
priceImpactWithoutFee
:
new
Percent
(
0
),
priceImpactWithoutFee
:
new
Percent
(
0
),
realizedLPFee
:
realizedLPFeeAmount
,
realizedLPFee
:
realizedLPFeeAmount
,
}
}
}
else
{
return
{
priceImpactWithoutFee
:
undefined
,
realizedLPFee
:
undefined
,
}
}
}
}
}
...
@@ -93,7 +98,7 @@ export function warningSeverity(priceImpact: Percent | undefined): 0 | 1 | 2 | 3
...
@@ -93,7 +98,7 @@ export function warningSeverity(priceImpact: Percent | undefined): 0 | 1 | 2 | 3
if
(
!
priceImpact
)
return
4
if
(
!
priceImpact
)
return
4
let
impact
=
IMPACT_TIERS
.
length
let
impact
=
IMPACT_TIERS
.
length
for
(
const
impactLevel
of
IMPACT_TIERS
)
{
for
(
const
impactLevel
of
IMPACT_TIERS
)
{
if
(
priceImpact
.
lessThan
(
impactLevel
))
return
impact
as
0
|
1
|
2
|
3
|
4
if
(
impactLevel
.
lessThan
(
priceImpact
))
return
impact
as
0
|
1
|
2
|
3
|
4
impact
--
impact
--
}
}
return
0
return
0
...
...
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