fix: tick before returning quote (#3598)

This commit is contained in:
Zach Pomerantz 2022-03-24 12:33:35 -04:00 committed by GitHub
parent d28607a1c8
commit afe38a2d10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,3 +1,5 @@
import 'setimmediate'
import { Protocol } from '@uniswap/router-sdk'
import { Currency, CurrencyAmount, TradeType } from '@uniswap/sdk-core'
import { ChainId } from '@uniswap/smart-order-router'
@ -75,7 +77,11 @@ export default function useClientSideSmartOrderRouterTrade<TTradeType extends Tr
if (wrapType !== WrapType.NONE) return { error: undefined }
if (!queryArgs || !params) return { error: undefined }
try {
return await getClientSideQuote(queryArgs, params, config)
const quoteResult = await getClientSideQuote(queryArgs, params, config)
// There is significant post-fetch processing, so delay a tick to prevent dropped frames.
// This is only important in the context of integrations - if we control the whole site,
// then we can afford to drop a few frames.
return new Promise((resolve) => setImmediate(() => resolve(quoteResult)))
} catch {
return { error: true }
}