From 036a58acc86a464c72554059c677943074930bc8 Mon Sep 17 00:00:00 2001 From: Alissa Crane Date: Mon, 16 Dec 2024 08:54:41 -0800 Subject: [PATCH] fix optional params - revisit --- src/core/api/getSwapLiteQuote.ts | 4 ++-- src/swap/components/SwapLiteProvider.tsx | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/api/getSwapLiteQuote.ts b/src/core/api/getSwapLiteQuote.ts index 6109bd8a59..f6fd9c598b 100644 --- a/src/core/api/getSwapLiteQuote.ts +++ b/src/core/api/getSwapLiteQuote.ts @@ -16,7 +16,7 @@ type GetSwapLiteQuoteResponse = { }; type GetSwapLiteQuoteParams = Omit & { - fromSwapUnit: SwapUnit; + fromSwapUnit?: SwapUnit; from?: Token; }; @@ -48,7 +48,7 @@ export async function getSwapLiteQuote({ } let formattedFromAmount = ''; - if (response && !isSwapError(response)) { + if (response && !isSwapError(response) && fromSwapUnit) { formattedFromAmount = formatTokenAmount( response.fromAmount, response.from.decimals, diff --git a/src/swap/components/SwapLiteProvider.tsx b/src/swap/components/SwapLiteProvider.tsx index 4742259f5e..359cc03bf1 100644 --- a/src/swap/components/SwapLiteProvider.tsx +++ b/src/swap/components/SwapLiteProvider.tsx @@ -257,13 +257,13 @@ export function SwapLiteProvider({ to.setAmountUSD(''); fromETH.setAmountUSD(''); fromUSDC.setAmountUSD(''); - from.setAmountUSD(''); + from?.setAmountUSD(''); return; } fromETH.setLoading(true); fromUSDC.setLoading(true); - from.setLoading(true); + from?.setLoading(true); updateLifecycleStatus({ statusName: 'amountChange', @@ -276,7 +276,7 @@ export function SwapLiteProvider({ amountFrom: '', tokenFromETH: fromETH.token, tokenFromUSDC: fromUSDC.token, - tokenFrom: from.token, + tokenFrom: from?.token, tokenTo: to.token, // when fetching quote, the destination // amount is missing @@ -353,7 +353,7 @@ export function SwapLiteProvider({ amountTo: amount, tokenFromETH: fromETH.token, tokenFromUSDC: fromUSDC.token, - tokenFrom: from.token, + tokenFrom: from?.token, tokenTo: to.token, // if quote was fetched successfully, we // have all required fields @@ -373,7 +373,7 @@ export function SwapLiteProvider({ // reset loading state when quote request resolves fromETH.setLoading(false); fromUSDC.setLoading(false); - from.setLoading(false); + from?.setLoading(false); } }, [