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
549d4e38
Unverified
Commit
549d4e38
authored
May 03, 2021
by
Noah Zinsmeister
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'refs/remotes/origin/main'
parents
3af67818
fbccb83e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
30 deletions
+48
-30
index.tsx
src/components/CurrencyInputPanel/index.tsx
+5
-16
SwapRoute.tsx
src/components/swap/SwapRoute.tsx
+22
-4
useUSDCPrice.ts
src/hooks/useUSDCPrice.ts
+10
-1
index.tsx
src/pages/Swap/index.tsx
+11
-7
hooks.ts
src/state/lists/hooks.ts
+0
-2
No files found.
src/components/CurrencyInputPanel/index.tsx
View file @
549d4e38
import
{
Pair
}
from
'
@uniswap/v2-sdk
'
import
{
Currency
,
CurrencyAmount
}
from
'
@uniswap/sdk-core
'
import
React
,
{
useState
,
useCallback
,
useMemo
}
from
'
react
'
import
React
,
{
useState
,
useCallback
}
from
'
react
'
import
styled
from
'
styled-components
'
import
{
darken
}
from
'
polished
'
import
useUSDCPrice
from
'
../../hooks/useUSDCPrice
'
import
{
tryParseAmount
}
from
'
../../state/swap/hooks
'
import
{
useCurrencyBalance
}
from
'
../../state/wallet/hooks
'
import
CurrencySearchModal
from
'
../SearchModal/CurrencySearchModal
'
import
CurrencyLogo
from
'
../CurrencyLogo
'
...
...
@@ -159,7 +157,7 @@ interface CurrencyInputPanelProps {
pair
?:
Pair
|
null
hideInput
?:
boolean
otherCurrency
?:
Currency
|
null
showFiatValue
?:
boolean
fiatValue
?:
CurrencyAmount
id
:
string
showCommonBases
?:
boolean
customBalanceText
?:
string
...
...
@@ -177,7 +175,7 @@ export default function CurrencyInputPanel({
id
,
showCommonBases
,
customBalanceText
,
showFiatValue
=
fals
e
,
fiatValu
e
,
hideBalance
=
false
,
pair
=
null
,
// used for double token logo
hideInput
=
false
,
...
...
@@ -195,14 +193,6 @@ export default function CurrencyInputPanel({
setModalOpen
(
false
)
},
[
setModalOpen
])
const
price
=
useUSDCPrice
(
showFiatValue
?
currency
??
undefined
:
undefined
)
const
fiatValueOfTypedAmount
:
CurrencyAmount
|
null
=
useMemo
(()
=>
{
if
(
!
price
)
return
null
const
amount
=
tryParseAmount
(
value
,
currency
??
undefined
)
return
amount
?
price
.
quote
(
amount
)
:
null
},
[
currency
,
price
,
value
])
return
(
<
InputPanel
id=
{
id
}
hideInput=
{
hideInput
}
{
...
rest
}
>
{
locked
&&
(
...
...
@@ -295,9 +285,8 @@ export default function CurrencyInputPanel({
</
RowFixed
>
)
}
<
TYPE
.
body
fontSize=
{
14
}
color=
{
fiatValueOfTypedAmount
?
theme
.
text2
:
theme
.
text4
}
>
{
fiatValueOfTypedAmount
?
'
~
'
:
''
}
$
{
fiatValueOfTypedAmount
?
Number
(
fiatValueOfTypedAmount
?.
toSignificant
(
6
)).
toLocaleString
(
'
en
'
)
:
'
-
'
}
<
TYPE
.
body
fontSize=
{
14
}
color=
{
fiatValue
?
theme
.
text2
:
theme
.
text4
}
>
{
fiatValue
?
'
~
'
:
''
}
$
{
fiatValue
?
Number
(
fiatValue
?.
toSignificant
(
6
)).
toLocaleString
(
'
en
'
)
:
'
-
'
}
</
TYPE
.
body
>
</
RowBetween
>
</
FiatRow
>
...
...
src/components/swap/SwapRoute.tsx
View file @
549d4e38
import
{
Percent
}
from
'
@uniswap/sdk-core
'
import
{
Trade
as
V2Trade
}
from
'
@uniswap/v2-sdk
'
import
{
Trade
as
V3Trade
}
from
'
@uniswap/v3-sdk
'
import
{
Trade
as
V3Trade
,
FeeAmount
}
from
'
@uniswap/v3-sdk
'
import
React
,
{
Fragment
,
memo
,
useContext
}
from
'
react
'
import
{
ChevronRight
}
from
'
react-feather
'
import
{
Chevron
Left
,
Chevron
Right
}
from
'
react-feather
'
import
{
Flex
}
from
'
rebass
'
import
{
ThemeContext
}
from
'
styled-components
'
import
{
TYPE
}
from
'
../../theme
'
import
{
unwrappedToken
}
from
'
utils/wrappedCurrency
'
function
LabeledArrow
({
fee
}:
{
fee
:
FeeAmount
})
{
const
theme
=
useContext
(
ThemeContext
)
// todo: improve the rendering of this labeled arrow
return
(
<>
<
ChevronLeft
size=
{
12
}
color=
{
theme
.
text2
}
/>
<
span
style=
{
{
fontSize
:
12
,
marginTop
:
2
}
}
>
{
new
Percent
(
fee
,
1
_000_000
).
toSignificant
()
}
%
</
span
>
<
ChevronRight
size=
{
12
}
color=
{
theme
.
text2
}
/>
</>
)
}
export
default
memo
(
function
SwapRoute
({
trade
}:
{
trade
:
V2Trade
|
V3Trade
})
{
const
tokenPath
=
trade
instanceof
V2Trade
?
trade
.
route
.
path
:
trade
.
route
.
tokenPath
const
theme
=
useContext
(
ThemeContext
)
return
(
<
Flex
flexWrap=
"wrap"
width=
"100%"
justifyContent=
"flex-
end
"
alignItems=
"center"
>
<
Flex
flexWrap=
"wrap"
width=
"100%"
justifyContent=
"flex-
start
"
alignItems=
"center"
>
{
tokenPath
.
map
((
token
,
i
,
path
)
=>
{
const
isLastItem
:
boolean
=
i
===
path
.
length
-
1
const
currency
=
unwrappedToken
(
token
)
...
...
@@ -22,7 +36,11 @@ export default memo(function SwapRoute({ trade }: { trade: V2Trade | V3Trade })
{
currency
.
symbol
}
</
TYPE
.
black
>
</
Flex
>
{
isLastItem
?
null
:
<
ChevronRight
size=
{
12
}
color=
{
theme
.
text2
}
/>
}
{
isLastItem
?
null
:
trade
instanceof
V2Trade
?
(
<
ChevronRight
size=
{
12
}
color=
{
theme
.
text2
}
/>
)
:
(
<
LabeledArrow
fee=
{
trade
.
route
.
pools
[
i
].
fee
}
/>
)
}
</
Fragment
>
)
})
}
...
...
src/hooks/useUSDCPrice.ts
View file @
549d4e38
import
{
ChainId
,
Currency
,
currencyEquals
,
Price
,
Token
,
WETH9
}
from
'
@uniswap/sdk-core
'
import
{
ChainId
,
Currency
,
CurrencyAmount
,
currencyEquals
,
Price
,
Token
,
WETH9
}
from
'
@uniswap/sdk-core
'
import
{
JSBI
}
from
'
@uniswap/v2-sdk
'
import
{
useMemo
}
from
'
react
'
import
{
USDC
}
from
'
../constants
'
...
...
@@ -75,3 +75,12 @@ export default function useUSDCPrice(currency?: Currency): Price | undefined {
return
undefined
},
[
chainId
,
currency
,
ethPair
,
ethPairState
,
usdcEthPair
,
usdcEthPairState
,
usdcPair
,
usdcPairState
,
weth
,
wrapped
])
}
export
function
useUSDCValue
(
currencyAmount
:
CurrencyAmount
|
undefined
|
null
)
{
const
price
=
useUSDCPrice
(
currencyAmount
?.
currency
)
return
useMemo
(()
=>
{
if
(
!
price
||
!
currencyAmount
)
return
null
return
price
.
quote
(
currencyAmount
)
},
[
currencyAmount
,
price
])
}
src/pages/Swap/index.tsx
View file @
549d4e38
...
...
@@ -34,6 +34,7 @@ import { useERC20PermitFromTrade, UseERC20PermitState } from '../../hooks/useERC
import
{
useIsSwapUnsupported
}
from
'
../../hooks/useIsSwapUnsupported
'
import
{
useSwapCallback
}
from
'
../../hooks/useSwapCallback
'
import
useToggledVersion
,
{
Version
}
from
'
../../hooks/useToggledVersion
'
import
{
useUSDCValue
}
from
'
../../hooks/useUSDCPrice
'
import
useWrapCallback
,
{
WrapType
}
from
'
../../hooks/useWrapCallback
'
import
{
useWalletModalToggle
}
from
'
../../state/application/hooks
'
import
{
Field
}
from
'
../../state/swap/actions
'
...
...
@@ -132,6 +133,9 @@ export default function Swap({ history }: RouteComponentProps) {
[
allowedSlippage
,
independentField
,
parsedAmount
,
showWrap
,
trade
]
)
const
fiatValueInput
=
useUSDCValue
(
parsedAmounts
[
Field
.
INPUT
])
const
fiatValueOutput
=
useUSDCValue
(
parsedAmounts
[
Field
.
OUTPUT
])
const
{
onSwitchTokens
,
onCurrencySelection
,
onUserInput
,
onChangeRecipient
}
=
useSwapActionHandlers
()
const
isValid
=
!
swapInputError
const
dependentField
:
Field
=
independentField
===
Field
.
INPUT
?
Field
.
OUTPUT
:
Field
.
INPUT
...
...
@@ -216,15 +220,15 @@ export default function Swap({ history }: RouteComponentProps) {
signatureData
)
const
{
priceImpactWithoutFee
}
=
computeTradePriceBreakdown
(
trade
)
const
{
priceImpactWithoutFee
:
priceImpact
}
=
computeTradePriceBreakdown
(
trade
)
const
[
singleHopOnly
]
=
useUserSingleHopOnly
()
const
handleSwap
=
useCallback
(()
=>
{
if
(
priceImpactWithoutFee
&&
!
confirmPriceImpactWithoutFee
(
priceImpactWithoutFee
)
)
{
if
(
!
swapCallback
)
{
return
}
if
(
!
swapCallback
)
{
if
(
priceImpact
&&
!
confirmPriceImpactWithoutFee
(
priceImpact
)
)
{
return
}
setSwapState
({
attemptingTxn
:
true
,
tradeToConfirm
,
showConfirm
,
swapErrorMessage
:
undefined
,
txHash
:
undefined
})
...
...
@@ -258,7 +262,7 @@ export default function Swap({ history }: RouteComponentProps) {
})
})
},
[
priceImpact
WithoutFee
,
priceImpact
,
swapCallback
,
tradeToConfirm
,
showConfirm
,
...
...
@@ -273,7 +277,7 @@ export default function Swap({ history }: RouteComponentProps) {
const
[
showInverted
,
setShowInverted
]
=
useState
<
boolean
>
(
false
)
// warnings on price impact
const
priceImpactSeverity
=
warningSeverity
(
priceImpact
WithoutFee
)
const
priceImpactSeverity
=
warningSeverity
(
priceImpact
)
// show approve flow when: no error on inputs, not approved or pending, or approved in current session
// never show if price impact is above threshold in non expert mode
...
...
@@ -350,7 +354,7 @@ export default function Swap({ history }: RouteComponentProps) {
currency=
{
currencies
[
Field
.
INPUT
]
}
onUserInput=
{
handleTypeInput
}
onMax=
{
handleMaxInput
}
showFiatValue
fiatValue=
{
fiatValueInput
??
undefined
}
onCurrencySelect=
{
handleInputSelect
}
otherCurrency=
{
currencies
[
Field
.
OUTPUT
]
}
showCommonBases=
{
true
}
...
...
@@ -372,7 +376,7 @@ export default function Swap({ history }: RouteComponentProps) {
label=
{
independentField
===
Field
.
INPUT
&&
!
showWrap
?
'
To (at least)
'
:
'
To
'
}
showMaxButton=
{
false
}
hideBalance=
{
false
}
showFiatValue
fiatValue=
{
fiatValueOutput
??
undefined
}
currency=
{
currencies
[
Field
.
OUTPUT
]
}
onCurrencySelect=
{
handleOutputSelect
}
otherCurrency=
{
currencies
[
Field
.
INPUT
]
}
...
...
src/state/lists/hooks.ts
View file @
549d4e38
...
...
@@ -108,10 +108,8 @@ function combineMaps(map1: TokenAddressMap, map2: TokenAddressMap): TokenAddress
// merge tokens contained within lists from urls
function
useCombinedTokenMapFromUrls
(
urls
:
string
[]
|
undefined
):
TokenAddressMap
{
const
lists
=
useAllLists
()
return
useMemo
(()
=>
{
if
(
!
urls
)
return
EMPTY_LIST
return
(
urls
.
slice
()
...
...
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