Skip to content

Commit

Permalink
fix: increase refetchTime
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed May 23, 2022
1 parent 7fce2fc commit 91fb903
Showing 1 changed file with 49 additions and 50 deletions.
99 changes: 49 additions & 50 deletions packages/widget/src/hooks/useSwapRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SwapFormKey } from '../providers/SwapFormProvider';
import { useWallet } from '../providers/WalletProvider';
import { useCurrentRoute } from './useRouteExecution';

const refetchTime = 30_000;
const refetchTime = 60_000;

export const useSwapRoutes = () => {
const { account } = useWallet();
Expand Down Expand Up @@ -43,11 +43,23 @@ export const useSwapRoutes = () => {
!isNaN(fromTokenAmount) &&
!isNaN(slippage);

const { data, isLoading, isFetching, dataUpdatedAt, status, fetchStatus } =
useQuery(
[
'routes',
account.address,
const { data, isLoading, isFetching, dataUpdatedAt } = useQuery(
[
'routes',
account.address,
fromChainId,
fromTokenAddress,
fromTokenAmount,
toChainId,
toTokenAddress,
slippage,
enabledBridges,
enabledExchanges,
],
async ({
queryKey: [
_,
address,
fromChainId,
fromTokenAddress,
fromTokenAmount,
Expand All @@ -57,56 +69,43 @@ export const useSwapRoutes = () => {
enabledBridges,
enabledExchanges,
],
async ({
queryKey: [
_,
address,
signal,
}) => {
return LiFi.getRoutes(
{
fromChainId,
// TODO: simplify
fromAmount: (
Number(fromTokenAmount) *
10 ** (token?.decimals ?? 0)
).toFixed(0), // new BigNumber(depositAmount).shiftedBy(fromToken.decimals).toFixed(0),
fromTokenAddress,
fromTokenAmount,
toChainId,
toTokenAddress,
slippage,
enabledBridges,
enabledExchanges,
],
signal,
}) => {
return LiFi.getRoutes(
{
fromChainId,
// TODO: simplify
fromAmount: (
Number(fromTokenAmount) *
10 ** (token?.decimals ?? 0)
).toFixed(0), // new BigNumber(depositAmount).shiftedBy(fromToken.decimals).toFixed(0),
fromTokenAddress,
toChainId,
toTokenAddress,
fromAddress: address,
toAddress: address,
options: {
slippage: slippage / 100,
bridges: {
allow: enabledBridges,
},
exchanges: {
allow: enabledExchanges,
},
fromAddress: address,
toAddress: address,
options: {
slippage: slippage / 100,
bridges: {
allow: enabledBridges,
},
exchanges: {
allow: enabledExchanges,
},
},
{ signal },
);
},
{
enabled: isEnabled,
refetchIntervalInBackground: true,
refetchInterval: refetchTime,
staleTime: refetchTime,
// TODO: probably should be removed
cacheTime: refetchTime,
},
);
},
{ signal },
);
},
{
enabled: isEnabled,
refetchIntervalInBackground: true,
refetchInterval: refetchTime,
staleTime: refetchTime,
// TODO: probably should be removed
cacheTime: refetchTime,
},
);

useEffect(() => {
// check that the current route is selected from existing routes
Expand Down

0 comments on commit 91fb903

Please sign in to comment.