diff --git a/apps/cowswap-frontend/src/legacy/state/orders/consts.ts b/apps/cowswap-frontend/src/legacy/state/orders/consts.ts index c376d160b4..d667d60978 100644 --- a/apps/cowswap-frontend/src/legacy/state/orders/consts.ts +++ b/apps/cowswap-frontend/src/legacy/state/orders/consts.ts @@ -11,7 +11,7 @@ export const ContractDeploymentBlocks: Partial> = { export const MARKET_OPERATOR_API_POLL_INTERVAL = ms`2s` // We can have lots of limit orders and it creates a high load, so we poll them no so ofter as market orders export const LIMIT_OPERATOR_API_POLL_INTERVAL = ms`15s` -export const PENDING_ORDERS_PRICE_CHECK_POLL_INTERVAL = ms`15s` +export const PENDING_ORDERS_PRICE_CHECK_POLL_INTERVAL = ms`30s` export const SPOT_PRICE_CHECK_POLL_INTERVAL = ms`15s` export const EXPIRED_ORDERS_CHECK_POLL_INTERVAL = ms`15s` diff --git a/apps/cowswap-frontend/src/legacy/state/orders/updaters/UnfillableOrdersUpdater.ts b/apps/cowswap-frontend/src/legacy/state/orders/updaters/UnfillableOrdersUpdater.ts index 2ee794f560..c8e3080f99 100644 --- a/apps/cowswap-frontend/src/legacy/state/orders/updaters/UnfillableOrdersUpdater.ts +++ b/apps/cowswap-frontend/src/legacy/state/orders/updaters/UnfillableOrdersUpdater.ts @@ -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, + }) const verifiedQuote = verifiedQuotesEnabled && enoughBalance _getOrderPrice(chainId, order, verifiedQuote, strategy) @@ -185,11 +191,13 @@ 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') @@ -197,10 +205,10 @@ export function UnfillableOrdersUpdater(): null { } 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) return () => clearInterval(interval) - }, [updatePending, chainId, account, isWindowVisible]) + }, [chainId, account, isWindowVisible]) return null }