From 762aedd4ec6b48d02c2ec2f5f5d04c73034e5aba Mon Sep 17 00:00:00 2001 From: viet-nv Date: Sat, 4 Nov 2023 00:25:10 +0700 Subject: [PATCH] refresh rate after 10s --- src/hooks/elasticZap/index.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/hooks/elasticZap/index.ts b/src/hooks/elasticZap/index.ts index 52638f6d2c..83a3fd6a3e 100644 --- a/src/hooks/elasticZap/index.ts +++ b/src/hooks/elasticZap/index.ts @@ -53,6 +53,7 @@ export function useZapInPoolResult(params?: { const [loadingAggregator, setLoadingAggregator] = useState(false) const [getRoute] = useLazyGetRouteQuery() + const [slippage] = useUserSlippageTolerance() const { aggregatorDomain } = useKyberswapGlobalConfig() const url = `${aggregatorDomain}/${NETWORKS_INFO[chainId].aggregatorRoute}${AGGREGATOR_API_PATHS.GET_ROUTE}` @@ -67,7 +68,11 @@ export function useZapInPoolResult(params?: { const [aggregatorOutputs, setAggregatorOutputs] = useState>([]) const { tokenIn, tokenOut, poolAddress } = params || {} - useEffect(() => { + + const getRoutes = useCallback(() => { + if (slippage) { + // added to refresh rate when slippage change, aggregator dont need this + } if (tokenIn && tokenOut && poolAddress) { setAggregatorOutputs([]) if (useAggregatorForZap) { @@ -96,7 +101,15 @@ export function useZapInPoolResult(params?: { }) } } - }, [tokenIn, tokenOut, poolAddress, splitedAmount, getRoute, url, useAggregatorForZap]) + }, [tokenIn, tokenOut, poolAddress, splitedAmount, getRoute, url, useAggregatorForZap, slippage]) + + useEffect(() => { + getRoutes() + const i = setInterval(() => { + getRoutes() + }, 10_000) + return () => i && clearInterval(i) + }, [getRoutes]) const callParams = useMemo( () =>