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
b2528792
Unverified
Commit
b2528792
authored
Apr 28, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return fake price data for non mainnet and fill it into the currency input panel
parent
65c51ea4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
31 deletions
+51
-31
index.tsx
src/components/CurrencyInputPanel/index.tsx
+25
-16
index.tsx
src/components/NumericalInput/index.tsx
+0
-1
useUSDCPrice.ts
src/hooks/useUSDCPrice.ts
+24
-14
index.tsx
src/pages/Swap/index.tsx
+2
-0
No files found.
src/components/CurrencyInputPanel/index.tsx
View file @
b2528792
import
{
Pair
}
from
'
@uniswap/v2-sdk
'
import
{
Currency
}
from
'
@uniswap/sdk-core
'
import
React
,
{
useState
,
useCallback
}
from
'
react
'
import
{
Currency
,
CurrencyAmount
}
from
'
@uniswap/sdk-core
'
import
React
,
{
useState
,
useCallback
,
useMemo
}
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
'
...
...
@@ -152,6 +154,7 @@ interface CurrencyInputPanelProps {
pair
?:
Pair
|
null
hideInput
?:
boolean
otherCurrency
?:
Currency
|
null
showFiatValue
?:
boolean
id
:
string
showCommonBases
?:
boolean
customBalanceText
?:
string
...
...
@@ -170,6 +173,7 @@ export default function CurrencyInputPanel({
id
,
showCommonBases
,
customBalanceText
,
showFiatValue
=
false
,
hideBalance
=
false
,
pair
=
null
,
// used for double token logo
hideInput
=
false
,
...
...
@@ -187,7 +191,13 @@ export default function CurrencyInputPanel({
setModalOpen
(
false
)
},
[
setModalOpen
])
const
disableCurrencySelect
=
typeof
onCurrencySelect
!==
'
function
'
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
}
>
...
...
@@ -206,16 +216,17 @@ export default function CurrencyInputPanel({
<
TYPE
.
body
color=
{
theme
.
text3
}
fontWeight=
{
500
}
fontSize=
{
14
}
>
{
label
}
</
TYPE
.
body
>
{
fiatValueOfTypedAmount
?
<
TYPE
.
label
>
$
{
fiatValueOfTypedAmount
?.
toFixed
(
2
)
}
</
TYPE
.
label
>
:
null
}
</
RowBetween
>
</
LabelRow
>
)
}
<
InputRow
style=
{
hideInput
?
{
padding
:
'
0
'
,
borderRadius
:
'
8px
'
}
:
{}
}
selected=
{
disable
CurrencySelect
}
>
<
InputRow
style=
{
hideInput
?
{
padding
:
'
0
'
,
borderRadius
:
'
8px
'
}
:
{}
}
selected=
{
!
on
CurrencySelect
}
>
<
CurrencySelect
selected=
{
!!
currency
}
hideInput=
{
hideInput
}
className=
"open-currency-select-button"
onClick=
{
()
=>
{
if
(
!
disable
CurrencySelect
)
{
if
(
on
CurrencySelect
)
{
setModalOpen
(
true
)
}
}
}
...
...
@@ -243,19 +254,17 @@ export default function CurrencyInputPanel({
</
StyledTokenName
>
)
}
</
RowFixed
>
{
!
disable
CurrencySelect
&&
<
StyledDropDown
selected=
{
!!
currency
}
/>
}
{
on
CurrencySelect
&&
<
StyledDropDown
selected=
{
!!
currency
}
/>
}
</
Aligner
>
</
CurrencySelect
>
{
!
hideInput
&&
(
<>
<
NumericalInput
className=
"token-amount-input"
value=
{
value
}
onUserInput=
{
(
val
)
=>
{
onUserInput
(
val
)
}
}
/>
</>
<
NumericalInput
className=
"token-amount-input"
value=
{
value
}
onUserInput=
{
(
val
)
=>
{
onUserInput
(
val
)
}
}
/>
)
}
</
InputRow
>
{
!
hideInput
&&
!
hideBalance
&&
(
...
...
@@ -288,7 +297,7 @@ export default function CurrencyInputPanel({
</
LabelRow
>
)
}
</
Container
>
{
!
disableCurrencySelect
&&
onCurrencySelect
&&
(
{
onCurrencySelect
&&
(
<
CurrencySearchModal
isOpen=
{
modalOpen
}
onDismiss=
{
handleDismissSearch
}
...
...
src/components/NumericalInput/index.tsx
View file @
b2528792
...
...
@@ -81,7 +81,6 @@ export const Input = React.memo(function InnerInput({
}
}
// universal input options
inputMode=
"decimal"
title=
"Token Amount"
autoComplete=
"off"
autoCorrect=
"off"
// text-specific options
...
...
src/hooks/useUSDCPrice.ts
View file @
b2528792
import
{
ChainId
,
Currency
,
currencyEquals
,
Price
,
WETH9
}
from
'
@uniswap/sdk-core
'
import
{
ChainId
,
Currency
,
currencyEquals
,
Price
,
Token
,
WETH9
}
from
'
@uniswap/sdk-core
'
import
{
JSBI
}
from
'
@uniswap/v2-sdk
'
import
{
useMemo
}
from
'
react
'
import
{
USDC
}
from
'
../constants
'
...
...
@@ -13,16 +13,15 @@ import { wrappedCurrency } from '../utils/wrappedCurrency'
export
default
function
useUSDCPrice
(
currency
?:
Currency
):
Price
|
undefined
{
const
{
chainId
}
=
useActiveWeb3React
()
const
wrapped
=
wrappedCurrency
(
currency
,
chainId
)
const
weth
=
WETH9
[
chainId
as
ChainId
]
const
tokenPairs
:
[
Currency
|
undefined
,
Currency
|
undefined
][]
=
useMemo
(
()
=>
[
[
chainId
&&
wrapped
&&
currencyEquals
(
WETH9
[
chainId
],
wrapped
)
?
undefined
:
currency
,
chainId
?
WETH9
[
chainId
]
:
undefined
,
],
[
chainId
&&
wrapped
&&
currencyEquals
(
weth
,
wrapped
)
?
undefined
:
currency
,
chainId
?
weth
:
undefined
],
[
wrapped
?.
equals
(
USDC
)
?
undefined
:
wrapped
,
chainId
===
ChainId
.
MAINNET
?
USDC
:
undefined
],
[
chainId
?
WETH9
[
chainId
]
:
undefined
,
chainId
===
ChainId
.
MAINNET
?
USDC
:
undefined
],
[
chainId
?
weth
:
undefined
,
chainId
===
ChainId
.
MAINNET
?
USDC
:
undefined
],
],
[
chainId
,
currency
,
wrapped
]
[
chainId
,
currency
,
w
eth
,
w
rapped
]
)
const
[[
ethPairState
,
ethPair
],
[
usdcPairState
,
usdcPair
],
[
usdcEthPairState
,
usdcEthPair
]]
=
useV2Pairs
(
tokenPairs
)
...
...
@@ -30,10 +29,21 @@ export default function useUSDCPrice(currency?: Currency): Price | undefined {
if
(
!
currency
||
!
wrapped
||
!
chainId
)
{
return
undefined
}
// return some fake price data for non-mainnet
if
(
chainId
!==
ChainId
.
MAINNET
)
{
const
fakeUSDC
=
new
Token
(
chainId
,
'
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
'
,
6
,
'
fUSDC
'
,
'
Fake USDC
'
)
return
new
Price
(
currency
,
fakeUSDC
,
10
**
Math
.
max
(
0
,
currency
.
decimals
-
6
),
15
*
10
**
Math
.
max
(
6
-
currency
.
decimals
,
0
)
)
}
// handle weth/eth
if
(
wrapped
.
equals
(
WETH9
[
chainId
]
))
{
if
(
wrapped
.
equals
(
weth
))
{
if
(
usdcPair
)
{
const
price
=
usdcPair
.
priceOf
(
WETH9
[
chainId
]
)
const
price
=
usdcPair
.
priceOf
(
weth
)
return
new
Price
(
currency
,
USDC
,
price
.
denominator
,
price
.
numerator
)
}
else
{
return
undefined
...
...
@@ -44,9 +54,9 @@ export default function useUSDCPrice(currency?: Currency): Price | undefined {
return
new
Price
(
USDC
,
USDC
,
'
1
'
,
'
1
'
)
}
const
ethPairETHAmount
=
ethPair
?.
reserveOf
(
WETH9
[
chainId
]
)
const
ethPairETHAmount
=
ethPair
?.
reserveOf
(
weth
)
const
ethPairETHUSDCValue
:
JSBI
=
ethPairETHAmount
&&
usdcEthPair
?
usdcEthPair
.
priceOf
(
WETH9
[
chainId
]
).
quote
(
ethPairETHAmount
).
raw
:
JSBI
.
BigInt
(
0
)
ethPairETHAmount
&&
usdcEthPair
?
usdcEthPair
.
priceOf
(
weth
).
quote
(
ethPairETHAmount
).
raw
:
JSBI
.
BigInt
(
0
)
// all other tokens
// first try the usdc pair
...
...
@@ -55,13 +65,13 @@ export default function useUSDCPrice(currency?: Currency): Price | undefined {
return
new
Price
(
currency
,
USDC
,
price
.
denominator
,
price
.
numerator
)
}
if
(
ethPairState
===
PairState
.
EXISTS
&&
ethPair
&&
usdcEthPairState
===
PairState
.
EXISTS
&&
usdcEthPair
)
{
if
(
usdcEthPair
.
reserveOf
(
USDC
).
greaterThan
(
'
0
'
)
&&
ethPair
.
reserveOf
(
WETH9
[
chainId
]
).
greaterThan
(
'
0
'
))
{
if
(
usdcEthPair
.
reserveOf
(
USDC
).
greaterThan
(
'
0
'
)
&&
ethPair
.
reserveOf
(
weth
).
greaterThan
(
'
0
'
))
{
const
ethUsdcPrice
=
usdcEthPair
.
priceOf
(
USDC
)
const
currencyEthPrice
=
ethPair
.
priceOf
(
WETH9
[
chainId
]
)
const
currencyEthPrice
=
ethPair
.
priceOf
(
weth
)
const
usdcPrice
=
ethUsdcPrice
.
multiply
(
currencyEthPrice
).
invert
()
return
new
Price
(
currency
,
USDC
,
usdcPrice
.
denominator
,
usdcPrice
.
numerator
)
}
}
return
undefined
},
[
chainId
,
currency
,
ethPair
,
ethPairState
,
usdcEthPair
,
usdcEthPairState
,
usdcPair
,
usdcPairState
,
wrapped
])
},
[
chainId
,
currency
,
ethPair
,
ethPairState
,
usdcEthPair
,
usdcEthPairState
,
usdcPair
,
usdcPairState
,
w
eth
,
w
rapped
])
}
src/pages/Swap/index.tsx
View file @
b2528792
...
...
@@ -341,6 +341,7 @@ export default function Swap({ history }: RouteComponentProps) {
currency=
{
currencies
[
Field
.
INPUT
]
}
onUserInput=
{
handleTypeInput
}
onMax=
{
handleMaxInput
}
showFiatValue
onCurrencySelect=
{
handleInputSelect
}
otherCurrency=
{
currencies
[
Field
.
OUTPUT
]
}
showCommonBases=
{
true
}
...
...
@@ -363,6 +364,7 @@ export default function Swap({ history }: RouteComponentProps) {
label=
{
independentField
===
Field
.
INPUT
&&
!
showWrap
&&
trade
?
'
To (minimum)
'
:
'
To
'
}
showMaxButton=
{
false
}
hideBalance=
{
true
}
showFiatValue
currency=
{
currencies
[
Field
.
OUTPUT
]
}
onCurrencySelect=
{
handleOutputSelect
}
otherCurrency=
{
currencies
[
Field
.
INPUT
]
}
...
...
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