From 244530c181a711e4e646cf9dae2de7eef8440bb3 Mon Sep 17 00:00:00 2001 From: Ji Young Lee <641712+jiyounglee@users.noreply.github.com> Date: Fri, 11 Oct 2024 11:02:01 +1100 Subject: [PATCH] [NO CHANGELOG] [Add Funds Widget] Retry when 429 (#2286) --- .../src/widgets/add-funds/hooks/useRoutes.ts | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useRoutes.ts b/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useRoutes.ts index 899e255644..04e68b7a59 100644 --- a/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useRoutes.ts +++ b/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useRoutes.ts @@ -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(undefined); @@ -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; }