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
bc251230
Unverified
Commit
bc251230
authored
Mar 14, 2023
by
Tina
Committed by
GitHub
Mar 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Remove block number check for quotes (#6148)
* remove block number check * add refetchOnMountOrArgChange
parent
b0aea5f6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
38 deletions
+11
-38
useIsValidBlock.ts
src/lib/hooks/useIsValidBlock.ts
+0
-31
useRoutingAPITrade.ts
src/state/routing/useRoutingAPITrade.ts
+11
-7
No files found.
src/lib/hooks/useIsValidBlock.ts
deleted
100644 → 0
View file @
b0aea5f6
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
atomWithImmer
}
from
'
jotai/immer
'
import
{
useAtomValue
}
from
'
jotai/utils
'
import
{
useCallback
}
from
'
react
'
import
useBlockNumber
from
'
./useBlockNumber
'
// The oldest block (per chain) to be considered valid.
const
oldestBlockMapAtom
=
atomWithImmer
<
{
[
chainId
:
number
]:
number
}
>
({})
const
DEFAULT_MAX_BLOCK_AGE
=
10
function
useGetIsValidBlock
(
maxBlockAge
=
DEFAULT_MAX_BLOCK_AGE
):
(
block
:
number
)
=>
boolean
{
const
{
chainId
}
=
useWeb3React
()
const
currentBlock
=
useBlockNumber
()
const
oldestBlockMap
=
useAtomValue
(
oldestBlockMapAtom
)
const
oldestBlock
=
chainId
?
oldestBlockMap
[
chainId
]
:
0
return
useCallback
(
(
block
:
number
)
=>
{
if
(
!
currentBlock
)
return
false
if
(
currentBlock
-
block
>
maxBlockAge
)
return
false
if
(
currentBlock
<
oldestBlock
)
return
false
return
true
},
[
currentBlock
,
maxBlockAge
,
oldestBlock
]
)
}
export
default
function
useIsValidBlock
(
block
:
number
):
boolean
{
return
useGetIsValidBlock
()(
block
)
}
src/state/routing/useRoutingAPITrade.ts
View file @
bc251230
...
@@ -5,12 +5,11 @@ import { sendTiming } from 'components/analytics'
...
@@ -5,12 +5,11 @@ import { sendTiming } from 'components/analytics'
import
{
AVERAGE_L1_BLOCK_TIME
}
from
'
constants/chainInfo
'
import
{
AVERAGE_L1_BLOCK_TIME
}
from
'
constants/chainInfo
'
import
{
useStablecoinAmountFromFiatValue
}
from
'
hooks/useStablecoinPrice
'
import
{
useStablecoinAmountFromFiatValue
}
from
'
hooks/useStablecoinPrice
'
import
{
useRoutingAPIArguments
}
from
'
lib/hooks/routing/useRoutingAPIArguments
'
import
{
useRoutingAPIArguments
}
from
'
lib/hooks/routing/useRoutingAPIArguments
'
import
useIsValidBlock
from
'
lib/hooks/useIsValidBlock
'
import
ms
from
'
ms.macro
'
import
ms
from
'
ms.macro
'
import
{
useMemo
}
from
'
react
'
import
{
useMemo
}
from
'
react
'
import
{
RouterPreference
,
useGetQuoteQuery
}
from
'
state/routing/slice
'
import
{
RouterPreference
,
useGetQuoteQuery
}
from
'
state/routing/slice
'
import
{
GetQuoteResult
,
InterfaceTrade
,
TradeState
}
from
'
./types
'
import
{
InterfaceTrade
,
TradeState
}
from
'
./types
'
import
{
computeRoutes
,
transformRoutesToTrade
}
from
'
./utils
'
import
{
computeRoutes
,
transformRoutesToTrade
}
from
'
./utils
'
/**
/**
...
@@ -44,13 +43,18 @@ export function useRoutingAPITrade<TTradeType extends TradeType>(
...
@@ -44,13 +43,18 @@ export function useRoutingAPITrade<TTradeType extends TradeType>(
routerPreference
,
routerPreference
,
})
})
const
{
isLoading
,
isError
,
data
,
currentData
}
=
useGetQuoteQuery
(
queryArgs
??
skipToken
,
{
const
{
isLoading
,
isError
,
data
:
quoteResult
,
currentData
,
}
=
useGetQuoteQuery
(
queryArgs
??
skipToken
,
{
// Price-fetching is informational and costly, so it's done less frequently.
// Price-fetching is informational and costly, so it's done less frequently.
pollingInterval
:
routerPreference
===
RouterPreference
.
PRICE
?
ms
`2m`
:
AVERAGE_L1_BLOCK_TIME
,
pollingInterval
:
routerPreference
===
RouterPreference
.
PRICE
?
ms
`1m`
:
AVERAGE_L1_BLOCK_TIME
,
// If latest quote from cache was fetched > 2m ago, instantly repoll for another instead of waiting for next poll period
refetchOnMountOrArgChange
:
2
*
60
,
})
})
const
quoteResult
:
GetQuoteResult
|
undefined
=
useIsValidBlock
(
Number
(
data
?.
blockNumber
)
||
0
)
?
data
:
undefined
const
route
=
useMemo
(
const
route
=
useMemo
(
()
=>
computeRoutes
(
currencyIn
,
currencyOut
,
tradeType
,
quoteResult
),
()
=>
computeRoutes
(
currencyIn
,
currencyOut
,
tradeType
,
quoteResult
),
[
currencyIn
,
currencyOut
,
quoteResult
,
tradeType
]
[
currencyIn
,
currencyOut
,
quoteResult
,
tradeType
]
...
@@ -59,7 +63,7 @@ export function useRoutingAPITrade<TTradeType extends TradeType>(
...
@@ -59,7 +63,7 @@ export function useRoutingAPITrade<TTradeType extends TradeType>(
// get USD gas cost of trade in active chains stablecoin amount
// get USD gas cost of trade in active chains stablecoin amount
const
gasUseEstimateUSD
=
useStablecoinAmountFromFiatValue
(
quoteResult
?.
gasUseEstimateUSD
)
??
null
const
gasUseEstimateUSD
=
useStablecoinAmountFromFiatValue
(
quoteResult
?.
gasUseEstimateUSD
)
??
null
const
isSyncing
=
currentData
!==
data
const
isSyncing
=
currentData
!==
quoteResult
return
useMemo
(()
=>
{
return
useMemo
(()
=>
{
if
(
!
currencyIn
||
!
currencyOut
||
currencyIn
.
equals
(
currencyOut
))
{
if
(
!
currencyIn
||
!
currencyOut
||
currencyIn
.
equals
(
currencyOut
))
{
...
...
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