From 5d7ed14194f6ea2430802bef080d7dcfdf49a095 Mon Sep 17 00:00:00 2001 From: Jin Date: Tue, 20 Aug 2024 19:59:50 -0700 Subject: [PATCH] Re-adding optional chaining for sellAsset and buyAsset on quote response (#1673) --- .../popup/hooks/swap/useSwapNativeAmounts.tsx | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/entries/popup/hooks/swap/useSwapNativeAmounts.tsx b/src/entries/popup/hooks/swap/useSwapNativeAmounts.tsx index f8a920f657..3b000cd7e0 100644 --- a/src/entries/popup/hooks/swap/useSwapNativeAmounts.tsx +++ b/src/entries/popup/hooks/swap/useSwapNativeAmounts.tsx @@ -31,12 +31,12 @@ export const useSwapNativeAmounts = ({ let nativeDisplay = null; if (isWrapOrUnwrapEth) { nativeDisplay = - !quote?.sellAmount || !quote.sellTokenAsset.price.value + !quote?.sellAmount || !quote?.sellTokenAsset?.price?.value ? null : convertRawAmountToNativeDisplay( quote?.sellAmount?.toString(), - quote.sellTokenAsset.decimals || 18, - quote.sellTokenAsset.price.value, + quote?.sellTokenAsset?.decimals || 18, + quote?.sellTokenAsset?.price?.value, currentCurrency, ); } else if (assetToSell?.native?.price?.amount && assetToSellValue) { @@ -47,12 +47,12 @@ export const useSwapNativeAmounts = ({ ); } else { nativeDisplay = - !quote?.sellAmountInEth || !quote.sellTokenAsset.price.value + !quote?.sellAmountInEth || !quote?.sellTokenAsset?.price?.value ? null : convertRawAmountToNativeDisplay( - quote?.sellAmountInEth.toString(), - quote.sellTokenAsset.decimals || 18, - quote.sellTokenAsset.price?.value, + quote?.sellAmountInEth?.toString(), + quote?.sellTokenAsset?.decimals || 18, + quote?.sellTokenAsset?.price?.value, currentCurrency, ); } @@ -72,8 +72,8 @@ export const useSwapNativeAmounts = ({ assetToSellValue, currentCurrency, quote?.sellAmount, - quote?.sellTokenAsset.price.value, - quote?.sellTokenAsset.decimals, + quote?.sellTokenAsset?.price?.value, + quote?.sellTokenAsset?.decimals, quote?.sellAmountInEth, ]); @@ -97,12 +97,12 @@ export const useSwapNativeAmounts = ({ ); } else { nativeDisplay = - !quote?.buyAmountInEth || !quote.buyTokenAsset.price?.value + !quote?.buyAmountInEth || !quote?.buyTokenAsset?.price?.value ? null : convertRawAmountToNativeDisplay( - quote?.buyAmountInEth.toString(), - quote.buyTokenAsset.decimals || 18, - quote.buyTokenAsset.price?.value, + quote?.buyAmountInEth?.toString(), + quote?.buyTokenAsset?.decimals || 18, + quote?.buyTokenAsset?.price?.value, currentCurrency, ); } @@ -124,8 +124,8 @@ export const useSwapNativeAmounts = ({ quote?.buyAmount, quote?.buyAmountInEth, currentCurrency, - quote?.buyTokenAsset.price?.value, - quote?.buyTokenAsset.decimals, + quote?.buyTokenAsset?.price?.value, + quote?.buyTokenAsset?.decimals, ]); return {