Skip to content

Commit

Permalink
[NO CHANGELOG] [Add Funds Widget] Retry when 429 (#2286)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyounglee authored Oct 11, 2024
1 parent a5ea41d commit 244530c
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { utils } from 'ethers';
import { useRef, useState } from 'react';
import { delay } from '../functions/delay';
import { AmountData, RouteData, Token } from '../types';
import { retry } from '../../../lib/retry';

export const useRoutes = () => {
const [routes, setRoutes] = useState<RouteData[] | undefined>(undefined);
Expand Down Expand Up @@ -86,18 +87,24 @@ export const useRoutes = () => {
parsedFromAmount,
fromToken.decimals,
);

return await squid.getRoute({
fromChain: fromToken.chainId,
fromToken: fromToken.address,
fromAmount: formattedFromAmount.toString(),
toChain: toToken.chainId,
toToken: toToken.address,
fromAddress,
toAddress,
quoteOnly,
enableBoost: true,
});
return await retry(
() => squid.getRoute({
fromChain: fromToken.chainId,
fromToken: fromToken.address,
fromAmount: formattedFromAmount.toString(),
toChain: toToken.chainId,
toToken: toToken.address,
fromAddress,
toAddress,
quoteOnly,
enableBoost: true,
}),
{
retryIntervalMs: 1000,
retries: 5,
nonRetryable: (err: any) => err.response.status !== 429,
},
);
} catch (error) {
return undefined;
}
Expand Down

0 comments on commit 244530c

Please sign in to comment.