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
7f1def30
Unverified
Commit
7f1def30
authored
May 27, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: usdc prices shouldn't reload when v3 prices reload
parent
89306270
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
useUSDCPrice.ts
src/hooks/useUSDCPrice.ts
+5
-5
No files found.
src/hooks/useUSDCPrice.ts
View file @
7f1def30
...
...
@@ -2,12 +2,12 @@ import { Currency, CurrencyAmount, Price, Token } from '@uniswap/sdk-core'
import
{
useMemo
}
from
'
react
'
import
{
USDC
}
from
'
../constants/tokens
'
import
{
useV2TradeExactOut
}
from
'
./useV2Trade
'
import
{
useBestV3TradeExactOut
,
V3TradeState
}
from
'
./useBestV3Trade
'
import
{
useBestV3TradeExactOut
}
from
'
./useBestV3Trade
'
import
{
useActiveWeb3React
}
from
'
./web3
'
// USDC amount used when calculating spot price for a given currency.
// The amount is large enough to filter low liquidity pairs.
const
usdcCurrencyAmount
=
CurrencyAmount
.
fromRawAmount
(
USDC
,
100
_000e6
)
const
USDC_CURRENCY_AMOUNT_OUT
=
CurrencyAmount
.
fromRawAmount
(
USDC
,
100
_000e6
)
/**
* Returns the price in USDC of the input currency
...
...
@@ -16,10 +16,10 @@ const usdcCurrencyAmount = CurrencyAmount.fromRawAmount(USDC, 100_000e6)
export
default
function
useUSDCPrice
(
currency
?:
Currency
):
Price
<
Currency
,
Token
>
|
undefined
{
const
{
chainId
}
=
useActiveWeb3React
()
const
v2USDCTrade
=
useV2TradeExactOut
(
currency
,
chainId
===
1
?
usdcCurrencyAmount
:
undefined
,
{
const
v2USDCTrade
=
useV2TradeExactOut
(
currency
,
chainId
===
1
?
USDC_CURRENCY_AMOUNT_OUT
:
undefined
,
{
maxHops
:
2
,
})
const
v3USDCTrade
=
useBestV3TradeExactOut
(
currency
,
chainId
===
1
?
usdcCurrencyAmount
:
undefined
)
const
v3USDCTrade
=
useBestV3TradeExactOut
(
currency
,
chainId
===
1
?
USDC_CURRENCY_AMOUNT_OUT
:
undefined
)
return
useMemo
(()
=>
{
if
(
!
currency
||
!
chainId
)
{
...
...
@@ -46,7 +46,7 @@ export default function useUSDCPrice(currency?: Currency): Price<Currency, Token
if
(
v2USDCTrade
)
{
const
{
numerator
,
denominator
}
=
v2USDCTrade
.
route
.
midPrice
return
new
Price
(
currency
,
USDC
,
denominator
,
numerator
)
}
else
if
(
v3USDCTrade
.
state
===
V3TradeState
.
VALID
&&
v3USDCTrade
.
trade
)
{
}
else
if
(
v3USDCTrade
.
trade
)
{
const
{
numerator
,
denominator
}
=
v3USDCTrade
.
trade
.
route
.
midPrice
return
new
Price
(
currency
,
USDC
,
denominator
,
numerator
)
}
...
...
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