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
464a682f
Unverified
Commit
464a682f
authored
Apr 28, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
show the better trade link for v2/v3
parent
6ace3c21
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
16 deletions
+23
-16
SwapHeader.tsx
src/components/swap/SwapHeader.tsx
+4
-5
useToggledVersion.ts
src/hooks/useToggledVersion.ts
+2
-2
index.tsx
src/pages/Swap/index.tsx
+10
-3
hooks.ts
src/state/swap/hooks.ts
+2
-2
isTradeBetter.ts
src/utils/isTradeBetter.ts
+5
-4
No files found.
src/components/swap/SwapHeader.tsx
View file @
464a682f
import
React
from
'
react
'
import
React
from
'
react
'
import
styled
from
'
styled-components
'
import
styled
from
'
styled-components
'
import
{
Version
}
from
'
../../hooks/useToggledVersion
'
import
Settings
from
'
../Settings
'
import
Settings
from
'
../Settings
'
import
{
RowBetween
,
RowFixed
}
from
'
../Row
'
import
{
RowBetween
,
RowFixed
}
from
'
../Row
'
import
{
TYPE
}
from
'
../../theme
'
import
{
TYPE
}
from
'
../../theme
'
import
{
Trade
as
V2Trade
}
from
'
@uniswap/v2-sdk
'
import
{
Trade
as
V3Trade
}
from
'
@uniswap/v3-sdk
'
// import { Info } from 'react-feather'
// import { Info } from 'react-feather'
...
@@ -24,15 +23,15 @@ const StyledSwapHeader = styled.div`
...
@@ -24,15 +23,15 @@ const StyledSwapHeader = styled.div`
// `
// `
interface
SwapHeaderProps
{
interface
SwapHeaderProps
{
t
rade
?:
V2Trade
|
V3Trade
|
undefined
t
oggledVersion
:
Version
}
}
export
default
function
SwapHeader
({
t
rade
}:
SwapHeaderProps
)
{
export
default
function
SwapHeader
({
t
oggledVersion
}:
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
{
trade
instanceof
V2Trade
?
'
(V2)
'
:
trade
instanceof
V3Trade
?
'
(V3)
'
:
''
}
Swap
(
{
toggledVersion
}
)
</
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/hooks/useToggledVersion.ts
View file @
464a682f
import
useParsedQueryString
from
'
./useParsedQueryString
'
import
useParsedQueryString
from
'
./useParsedQueryString
'
export
enum
Version
{
export
enum
Version
{
v2
=
'
v
2
'
,
v2
=
'
V
2
'
,
v3
=
'
v
3
'
,
v3
=
'
V
3
'
,
}
}
export
const
DEFAULT_VERSION
:
Version
=
Version
.
v3
export
const
DEFAULT_VERSION
:
Version
=
Version
.
v3
...
...
src/pages/Swap/index.tsx
View file @
464a682f
...
@@ -11,6 +11,7 @@ import AddressInputPanel from '../../components/AddressInputPanel'
...
@@ -11,6 +11,7 @@ import AddressInputPanel from '../../components/AddressInputPanel'
import
{
ButtonError
,
ButtonLight
,
ButtonPrimary
,
ButtonConfirmed
}
from
'
../../components/Button
'
import
{
ButtonError
,
ButtonLight
,
ButtonPrimary
,
ButtonConfirmed
}
from
'
../../components/Button
'
import
{
GreyCard
}
from
'
../../components/Card
'
import
{
GreyCard
}
from
'
../../components/Card
'
import
{
AutoColumn
}
from
'
../../components/Column
'
import
{
AutoColumn
}
from
'
../../components/Column
'
import
BetterTradeLink
from
'
../../components/swap/BetterTradeLink
'
import
ConfirmSwapModal
from
'
../../components/swap/ConfirmSwapModal
'
import
ConfirmSwapModal
from
'
../../components/swap/ConfirmSwapModal
'
import
CurrencyInputPanel
from
'
../../components/CurrencyInputPanel
'
import
CurrencyInputPanel
from
'
../../components/CurrencyInputPanel
'
import
{
AutoRow
}
from
'
../../components/Row
'
import
{
AutoRow
}
from
'
../../components/Row
'
...
@@ -40,6 +41,7 @@ import {
...
@@ -40,6 +41,7 @@ import {
}
from
'
../../state/swap/hooks
'
}
from
'
../../state/swap/hooks
'
import
{
useExpertModeManager
,
useUserSlippageTolerance
,
useUserSingleHopOnly
}
from
'
../../state/user/hooks
'
import
{
useExpertModeManager
,
useUserSlippageTolerance
,
useUserSingleHopOnly
}
from
'
../../state/user/hooks
'
import
{
LinkStyledButton
,
TYPE
}
from
'
../../theme
'
import
{
LinkStyledButton
,
TYPE
}
from
'
../../theme
'
import
{
isTradeBetter
}
from
'
../../utils/isTradeBetter
'
import
{
maxAmountSpend
}
from
'
../../utils/maxAmountSpend
'
import
{
maxAmountSpend
}
from
'
../../utils/maxAmountSpend
'
import
{
computeTradePriceBreakdown
,
warningSeverity
}
from
'
../../utils/prices
'
import
{
computeTradePriceBreakdown
,
warningSeverity
}
from
'
../../utils/prices
'
import
AppBody
from
'
../AppBody
'
import
AppBody
from
'
../AppBody
'
...
@@ -88,7 +90,7 @@ export default function Swap({ history }: RouteComponentProps) {
...
@@ -88,7 +90,7 @@ export default function Swap({ history }: RouteComponentProps) {
const
{
independentField
,
typedValue
,
recipient
}
=
useSwapState
()
const
{
independentField
,
typedValue
,
recipient
}
=
useSwapState
()
const
{
const
{
v2Trade
,
v2Trade
,
v3Trade
,
v3Trade
State
:
{
trade
:
v3Trade
}
,
currencyBalances
,
currencyBalances
,
parsedAmount
,
parsedAmount
,
currencies
,
currencies
,
...
@@ -107,7 +109,7 @@ export default function Swap({ history }: RouteComponentProps) {
...
@@ -107,7 +109,7 @@ export default function Swap({ history }: RouteComponentProps) {
?
undefined
?
undefined
:
{
:
{
[
Version
.
v2
]:
v2Trade
,
[
Version
.
v2
]:
v2Trade
,
[
Version
.
v3
]:
v3Trade
.
trade
??
undefined
,
[
Version
.
v3
]:
v3Trade
??
undefined
,
}[
toggledVersion
]
}[
toggledVersion
]
const
parsedAmounts
=
useMemo
(
const
parsedAmounts
=
useMemo
(
...
@@ -313,7 +315,7 @@ export default function Swap({ history }: RouteComponentProps) {
...
@@ -313,7 +315,7 @@ export default function Swap({ history }: RouteComponentProps) {
onDismiss=
{
handleDismissTokenWarning
}
onDismiss=
{
handleDismissTokenWarning
}
/>
/>
<
AppBody
>
<
AppBody
>
<
SwapHeader
t
rade=
{
trade
}
/>
<
SwapHeader
t
oggledVersion=
{
toggledVersion
}
/>
<
Wrapper
id=
"swap-page"
>
<
Wrapper
id=
"swap-page"
>
<
ConfirmSwapModal
<
ConfirmSwapModal
isOpen=
{
showConfirm
}
isOpen=
{
showConfirm
}
...
@@ -388,6 +390,11 @@ export default function Swap({ history }: RouteComponentProps) {
...
@@ -388,6 +390,11 @@ export default function Swap({ history }: RouteComponentProps) {
setShowInverted=
{
setShowInverted
}
setShowInverted=
{
setShowInverted
}
/>
/>
)
:
null
}
)
:
null
}
{
toggledVersion
===
Version
.
v3
&&
isTradeBetter
(
v3Trade
,
v2Trade
)
?
(
<
BetterTradeLink
version=
{
Version
.
v2
}
/>
)
:
toggledVersion
===
Version
.
v2
&&
isTradeBetter
(
v2Trade
,
v3Trade
)
?
(
<
BetterTradeLink
version=
{
Version
.
v3
}
/>
)
:
null
}
<
BottomGrouping
>
<
BottomGrouping
>
{
swapIsUnsupported
?
(
{
swapIsUnsupported
?
(
<
ButtonPrimary
disabled=
{
true
}
>
<
ButtonPrimary
disabled=
{
true
}
>
...
...
src/state/swap/hooks.ts
View file @
464a682f
...
@@ -116,7 +116,7 @@ export function useDerivedSwapInfo(): {
...
@@ -116,7 +116,7 @@ export function useDerivedSwapInfo(): {
parsedAmount
:
CurrencyAmount
|
undefined
parsedAmount
:
CurrencyAmount
|
undefined
v2Trade
:
V2Trade
|
undefined
v2Trade
:
V2Trade
|
undefined
inputError
?:
string
inputError
?:
string
v3Trade
:
{
trade
:
V3Trade
|
null
;
state
:
V3TradeState
}
v3Trade
State
:
{
trade
:
V3Trade
|
null
;
state
:
V3TradeState
}
}
{
}
{
const
{
account
}
=
useActiveWeb3React
()
const
{
account
}
=
useActiveWeb3React
()
...
@@ -206,7 +206,7 @@ export function useDerivedSwapInfo(): {
...
@@ -206,7 +206,7 @@ export function useDerivedSwapInfo(): {
parsedAmount
,
parsedAmount
,
v2Trade
:
v2Trade
??
undefined
,
v2Trade
:
v2Trade
??
undefined
,
inputError
,
inputError
,
v3Trade
,
v3Trade
State
:
v3Trade
,
}
}
}
}
...
...
src/utils/isTradeBetter.ts
View file @
464a682f
import
{
ZERO_PERCENT
,
ONE_HUNDRED_PERCENT
}
from
'
./../constants/index
'
import
{
ZERO_PERCENT
,
ONE_HUNDRED_PERCENT
}
from
'
./../constants/index
'
import
{
Percent
,
currencyEquals
}
from
'
@uniswap/sdk-core
'
import
{
Percent
,
currencyEquals
}
from
'
@uniswap/sdk-core
'
import
{
Trade
}
from
'
@uniswap/v2-sdk
'
import
{
Trade
as
V2Trade
}
from
'
@uniswap/v2-sdk
'
import
{
Trade
as
V3Trade
}
from
'
@uniswap/v3-sdk
'
// returns whether tradeB is better than tradeA by at least a threshold percentage amount
// returns whether tradeB is better than tradeA by at least a threshold percentage amount
export
function
isTradeBetter
(
export
function
isTradeBetter
(
tradeA
:
Trade
|
undefined
|
null
,
tradeA
:
V2Trade
|
V3
Trade
|
undefined
|
null
,
tradeB
:
Trade
|
undefined
|
null
,
tradeB
:
V2Trade
|
V3
Trade
|
undefined
|
null
,
minimumDelta
:
Percent
=
ZERO_PERCENT
minimumDelta
:
Percent
=
ZERO_PERCENT
):
boolean
|
undefined
{
):
boolean
|
undefined
{
if
(
tradeA
&&
!
tradeB
)
return
false
if
(
tradeA
&&
!
tradeB
)
return
false
...
@@ -17,7 +18,7 @@ export function isTradeBetter(
...
@@ -17,7 +18,7 @@ export function isTradeBetter(
!
currencyEquals
(
tradeA
.
inputAmount
.
currency
,
tradeB
.
inputAmount
.
currency
)
||
!
currencyEquals
(
tradeA
.
inputAmount
.
currency
,
tradeB
.
inputAmount
.
currency
)
||
!
currencyEquals
(
tradeB
.
outputAmount
.
currency
,
tradeB
.
outputAmount
.
currency
)
!
currencyEquals
(
tradeB
.
outputAmount
.
currency
,
tradeB
.
outputAmount
.
currency
)
)
{
)
{
throw
new
Error
(
'
Trades are not comparable
'
)
return
false
}
}
if
(
minimumDelta
.
equalTo
(
ZERO_PERCENT
))
{
if
(
minimumDelta
.
equalTo
(
ZERO_PERCENT
))
{
...
...
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