From 389df1683507aeaf217ae90b68af3f83deebacc9 Mon Sep 17 00:00:00 2001 From: Mimi Tran <80493680+mimi-imtbl@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:40:00 +1100 Subject: [PATCH] [NO CHANGELOGS] [Add Funds Widget] Fix/add funds debounce (#2305) --- .../src/widgets/add-funds/views/AddFunds.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/checkout/widgets-lib/src/widgets/add-funds/views/AddFunds.tsx b/packages/checkout/widgets-lib/src/widgets/add-funds/views/AddFunds.tsx index 02722c5cec..0bb33c39bc 100644 --- a/packages/checkout/widgets-lib/src/widgets/add-funds/views/AddFunds.tsx +++ b/packages/checkout/widgets-lib/src/widgets/add-funds/views/AddFunds.tsx @@ -130,7 +130,7 @@ export function AddFunds({ [tokens, inputValue, selectedToken], ); - const setSelectedAmount = debounce((value: string) => { + const setSelectedAmount = useMemo(() => debounce((value: string) => { track({ userJourney: UserJourney.ADD_FUNDS, screen: 'InputScreen', @@ -147,7 +147,7 @@ export function AddFunds({ selectedAmount: value, }, }); - }, 2500); + }, 2500), []); const setSelectedToken = (token: TokenInfo | undefined) => { track({ @@ -477,10 +477,16 @@ export function AddFunds({ const shouldShowBackButton = showBackButton ?? !!onBackButtonClick; const routeInputsReady = !!selectedToken && !!fromAddress - && validateToAmount(selectedAmount).isValid; + && validateToAmount(selectedAmount).isValid + && validateToAmount(inputValue).isValid; + const loading = (routeInputsReady || fetchingRoutes) && !(selectedRouteData || insufficientBalance); - const readyToReview = routeInputsReady && !!toAddress && !!selectedRouteData && !loading; + + const readyToReview = routeInputsReady + && !!toAddress + && !!selectedRouteData + && !loading; const handleWalletConnected = ( providerType: 'from' | 'to',