-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce queries from unfillable updater #3107
Changes from all commits
7ecbeaf
caa9573
1a731e8
6ebdbaf
b1473f1
77d6972
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,8 @@ export function UnfillableOrdersUpdater(): null { | |
[setIsOrderUnfillable, updateOrderMarketPriceCallback] | ||
) | ||
|
||
const balancesRef = useRef(balances) | ||
balancesRef.current = balances | ||
const updatePending = useCallback(() => { | ||
if (!chainId || !account || isUpdating.current || !isWindowVisible) { | ||
return | ||
|
@@ -144,7 +146,11 @@ export function UnfillableOrdersUpdater(): null { | |
console.debug(`[UnfillableOrdersUpdater] Check order`, order) | ||
|
||
const currencyAmount = CurrencyAmount.fromRawAmount(order.inputToken, order.sellAmount) | ||
const enoughBalance = hasEnoughBalanceAndAllowance({ account, amount: currencyAmount, balances }) | ||
const enoughBalance = hasEnoughBalanceAndAllowance({ | ||
account, | ||
amount: currencyAmount, | ||
balances: balancesRef.current, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now balances uses a ref to not re-render the function that often, but always use the latest version of the balances |
||
}) | ||
const verifiedQuote = verifiedQuotesEnabled && enoughBalance | ||
|
||
_getOrderPrice(chainId, order, verifiedQuote, strategy) | ||
|
@@ -185,22 +191,24 @@ export function UnfillableOrdersUpdater(): null { | |
strategy, | ||
updateIsUnfillableFlag, | ||
isWindowVisible, | ||
balances, | ||
updatePendingOrderPrices, | ||
verifiedQuotesEnabled, | ||
]) | ||
|
||
const updatePendingRef = useRef(updatePending) | ||
updatePendingRef.current = updatePending | ||
|
||
useEffect(() => { | ||
if (!chainId || !account || !isWindowVisible) { | ||
console.debug('[UnfillableOrdersUpdater] No need to fetch unfillable orders') | ||
return | ||
} | ||
|
||
console.debug('[UnfillableOrdersUpdater] Periodically check for unfillable orders') | ||
updatePending() | ||
const interval = setInterval(updatePending, PENDING_ORDERS_PRICE_CHECK_POLL_INTERVAL) | ||
updatePendingRef.current() | ||
const interval = setInterval(() => updatePendingRef.current(), PENDING_ORDERS_PRICE_CHECK_POLL_INTERVAL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updatePending function is the culpit of the re-renders that cause too many queries |
||
return () => clearInterval(interval) | ||
}, [updatePending, chainId, account, isWindowVisible]) | ||
}, [chainId, account, isWindowVisible]) | ||
|
||
return null | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to poll this often