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
72936322
Unverified
Commit
72936322
authored
Jun 02, 2023
by
Jack Short
Committed by
GitHub
Jun 02, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: adding price impact modal (#6681)
parent
1bc6eb9a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
11 deletions
+104
-11
index.tsx
src/components/Button/index.tsx
+5
-0
PriceImpactModal.tsx
src/components/swap/PriceImpactModal.tsx
+74
-0
PriceImpactWarning.tsx
src/components/swap/PriceImpactWarning.tsx
+1
-1
index.tsx
src/pages/Swap/index.tsx
+24
-10
No files found.
src/components/Button/index.tsx
View file @
72936322
...
...
@@ -391,6 +391,7 @@ export enum ButtonEmphasis {
low,
warning,
destructive,
failure,
}
interface BaseThemeButtonProps {
size: ButtonSize
...
...
@@ -411,6 +412,8 @@ function pickThemeButtonBackgroundColor({ theme, emphasis }: { theme: DefaultThe
return theme.accentWarningSoft
case ButtonEmphasis.destructive:
return theme.accentCritical
case ButtonEmphasis.failure:
return theme.accentFailureSoft
case ButtonEmphasis.medium:
default:
return theme.backgroundInteractive
...
...
@@ -465,6 +468,8 @@ function pickThemeButtonTextColor({ theme, emphasis }: { theme: DefaultTheme; em
return theme.accentWarning
case ButtonEmphasis.destructive:
return theme.accentTextDarkPrimary
case ButtonEmphasis.failure:
return theme.accentFailure
case ButtonEmphasis.medium:
default:
return theme.textPrimary
...
...
src/components/swap/PriceImpactModal.tsx
0 → 100644
View file @
72936322
import
{
Trans
}
from
'
@lingui/macro
'
import
{
formatPriceImpact
}
from
'
@uniswap/conedison/format
'
import
{
Percent
}
from
'
@uniswap/sdk-core
'
import
{
ButtonEmphasis
,
ButtonSize
,
ThemeButton
}
from
'
components/Button
'
import
{
ColumnCenter
}
from
'
components/Column
'
import
Row
from
'
components/Row
'
import
{
AlertTriangle
}
from
'
react-feather
'
import
styled
from
'
styled-components/macro
'
import
{
CloseIcon
,
ThemedText
}
from
'
theme
'
import
Modal
from
'
../Modal
'
const
Wrapper
=
styled
(
ColumnCenter
)
`
padding: 16px 24px;
`
const
IconContainer
=
styled
.
div
`
padding: 32px 0px;
`
const
WarningIcon
=
styled
(
AlertTriangle
)
`
color:
${({
theme
})
=>
theme
.
accentCritical
}
;
`
const
ButtonContainer
=
styled
(
ColumnCenter
)
`
padding: 12px 0px 0px;
`
const
StyledThemeButton
=
styled
(
ThemeButton
)
`
width: 100%;
`
interface
PriceImpactModalProps
{
priceImpact
:
Percent
onDismiss
:
()
=>
void
onContinue
:
()
=>
void
}
export
default
function
PriceImpactModal
({
priceImpact
,
onDismiss
,
onContinue
}:
PriceImpactModalProps
)
{
return
(
<
Modal
isOpen
onDismiss=
{
onDismiss
}
>
<
Wrapper
gap=
"md"
>
<
Row
padding=
"8px 0px 4px"
>
<
CloseIcon
size=
{
24
}
onClick=
{
onDismiss
}
/>
</
Row
>
<
IconContainer
>
<
WarningIcon
size=
{
48
}
/>
</
IconContainer
>
<
ColumnCenter
gap=
"sm"
>
<
ThemedText
.
HeadlineSmall
fontWeight=
{
500
}
>
<
Trans
>
Warning
</
Trans
>
</
ThemedText
.
HeadlineSmall
>
<
ThemedText
.
BodyPrimary
lineHeight=
"24px"
textAlign=
"center"
>
<
Trans
>
This transaction will result in a
{
'
'
}
<
ThemedText
.
BodyPrimary
lineHeight=
"24px"
color=
"accentFailure"
display=
"inline"
>
{
formatPriceImpact
(
priceImpact
)
}
</
ThemedText
.
BodyPrimary
>
{
'
'
}
price impact on the market price of this pool. Do you wish to continue?
</
Trans
>
</
ThemedText
.
BodyPrimary
>
</
ColumnCenter
>
<
ButtonContainer
gap=
"md"
>
<
StyledThemeButton
size=
{
ButtonSize
.
large
}
emphasis=
{
ButtonEmphasis
.
failure
}
onClick=
{
onContinue
}
>
<
Trans
>
Continue
</
Trans
>
</
StyledThemeButton
>
<
StyledThemeButton
size=
{
ButtonSize
.
medium
}
emphasis=
{
ButtonEmphasis
.
low
}
onClick=
{
onDismiss
}
>
<
Trans
>
Cancel
</
Trans
>
</
StyledThemeButton
>
</
ButtonContainer
>
</
Wrapper
>
</
Modal
>
)
}
src/components/swap/PriceImpactWarning.tsx
View file @
72936322
...
...
@@ -39,7 +39,7 @@ export default function PriceImpactWarning({ priceImpact }: PriceImpactWarningPr
<
Trans
>
Price impact warning
</
Trans
>
</
ThemedText
.
DeprecatedSubHeader
>
</
RowFixed
>
<
ThemedText
.
DeprecatedLabel
textAlign=
"right"
fontSize=
{
14
}
color=
{
theme
.
accentFailure
}
>
<
ThemedText
.
DeprecatedLabel
textAlign=
"right"
fontSize=
{
14
}
color=
"accentFailure"
>
{
formatPriceImpact
(
priceImpact
)
}
</
ThemedText
.
DeprecatedLabel
>
</
RowBetween
>
...
...
src/pages/Swap/index.tsx
View file @
72936322
...
...
@@ -15,6 +15,7 @@ import { useWeb3React } from '@web3-react/core'
import
{
useToggleAccountDrawer
}
from
'
components/AccountDrawer
'
import
{
sendEvent
}
from
'
components/analytics
'
import
{
NetworkAlert
}
from
'
components/NetworkAlert/NetworkAlert
'
import
PriceImpactModal
from
'
components/swap/PriceImpactModal
'
import
PriceImpactWarning
from
'
components/swap/PriceImpactWarning
'
import
SwapDetailsDropdown
from
'
components/swap/SwapDetailsDropdown
'
import
TokenSafetyModal
from
'
components/TokenSafety/TokenSafetyModal
'
...
...
@@ -190,6 +191,8 @@ export function Swap({
},
[
prefilledInputCurrency
,
prefilledOutputCurrency
])
const
[
dismissTokenWarning
,
setDismissTokenWarning
]
=
useState
<
boolean
>
(
false
)
const
[
showPriceImpactModal
,
setShowPriceImpactModal
]
=
useState
<
boolean
>
(
false
)
const
urlLoadedTokens
:
Token
[]
=
useMemo
(
()
=>
[
loadedInputCurrency
,
loadedOutputCurrency
]?.
filter
((
c
):
c
is
Token
=>
c
?.
isToken
??
false
)
??
[],
[
loadedInputCurrency
,
loadedOutputCurrency
]
...
...
@@ -390,6 +393,15 @@ export function Swap({
allowance
.
state
===
AllowanceState
.
ALLOWED
?
allowance
.
permitSignature
:
undefined
)
const
handleContinueToReview
=
useCallback
(()
=>
{
setSwapState
({
tradeToConfirm
:
trade
,
swapError
:
undefined
,
showConfirm
:
true
,
txHash
:
undefined
,
})
},
[
trade
])
const
handleSwap
=
useCallback
(()
=>
{
if
(
!
swapCallback
)
{
return
...
...
@@ -500,7 +512,6 @@ export function Swap({
[
onCurrencyChange
,
onCurrencySelection
,
state
]
)
const
priceImpactTooHigh
=
priceImpactSeverity
>
3
const
showPriceImpactWarning
=
largerPriceImpact
&&
priceImpactSeverity
>
3
const
prevTrade
=
usePrevious
(
trade
)
...
...
@@ -545,6 +556,16 @@ export function Swap({
fiatValueOutput=
{
fiatValueTradeOutput
}
/>
)
}
{
showPriceImpactModal
&&
showPriceImpactWarning
&&
(
<
PriceImpactModal
priceImpact=
{
largerPriceImpact
}
onDismiss=
{
()
=>
setShowPriceImpactModal
(
false
)
}
onContinue=
{
()
=>
{
setShowPriceImpactModal
(
false
)
handleContinueToReview
()
}
}
/>
)
}
<
div
style=
{
{
display
:
'
relative
'
}
}
>
<
SwapSection
>
...
...
@@ -698,16 +719,11 @@ export function Swap({
>
<
ButtonError
onClick=
{
()
=>
{
setSwapState
({
tradeToConfirm
:
trade
,
swapError
:
undefined
,
showConfirm
:
true
,
txHash
:
undefined
,
})
showPriceImpactWarning
?
setShowPriceImpactModal
(
true
)
:
handleContinueToReview
()
}
}
id=
"swap-button"
data
-
testid=
"swap-button"
disabled=
{
!
isValid
||
routeIsSyncing
||
routeIsLoading
||
priceImpactTooHigh
}
disabled=
{
!
isValid
||
routeIsSyncing
||
routeIsLoading
}
error=
{
isValid
&&
priceImpactSeverity
>
2
&&
allowance
.
state
===
AllowanceState
.
ALLOWED
}
>
<
Text
fontSize=
{
20
}
fontWeight=
{
600
}
>
...
...
@@ -715,8 +731,6 @@ export function Swap({
swapInputError
)
:
routeIsSyncing
||
routeIsLoading
?
(
<
Trans
>
Swap
</
Trans
>
)
:
priceImpactTooHigh
?
(
<
Trans
>
Price Impact Too High
</
Trans
>
)
:
priceImpactSeverity
>
2
?
(
<
Trans
>
Swap Anyway
</
Trans
>
)
:
(
...
...
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