From b3b005149813e61cfd8dcf2976e7b51245b9fa71 Mon Sep 17 00:00:00 2001 From: Christopher Howard Date: Fri, 18 Oct 2024 00:27:15 -0400 Subject: [PATCH] feat: add fee in native token on swap review sheet (#1725) Co-authored-by: Daniel Sinclair <4412473+DanielSinclair@users.noreply.github.com> --- .../popup/hooks/swap/useSwapReviewDetails.ts | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/entries/popup/hooks/swap/useSwapReviewDetails.ts b/src/entries/popup/hooks/swap/useSwapReviewDetails.ts index e964092890..e3ce7d0a34 100644 --- a/src/entries/popup/hooks/swap/useSwapReviewDetails.ts +++ b/src/entries/popup/hooks/swap/useSwapReviewDetails.ts @@ -1,20 +1,16 @@ import { CrosschainQuote, Quote } from '@rainbow-me/swaps'; import { useMemo } from 'react'; -import { useCurrentCurrencyStore } from '~/core/state'; import { ParsedSearchAsset } from '~/core/types/assets'; import { ChainName } from '~/core/types/chains'; import { convertRawAmountToBalance, convertRawAmountToDecimalFormat, - convertRawAmountToNativeDisplay, divide, handleSignificantDecimals, multiply, } from '~/core/utils/numbers'; -import { useNativeAsset } from '../useNativeAsset'; - const getExchangeIconUrl = (protocol: string): string | null => { if (!protocol) return null; const parsedProtocol = protocol?.replace(' ', '')?.toLowerCase(); @@ -45,11 +41,6 @@ export const useSwapReviewDetails = ({ assetToSell: ParsedSearchAsset; quote: Quote | CrosschainQuote; }) => { - const { currentCurrency } = useCurrentCurrencyStore(); - const nativeAsset = useNativeAsset({ - chainId: assetToSell.chainId, - }); - const bridges = useMemo( () => (quote as CrosschainQuote)?.routes?.[0]?.usedBridgeNames || [], [quote], @@ -84,19 +75,16 @@ export const useSwapReviewDetails = ({ }, ).amount; return [ - convertRawAmountToNativeDisplay( - quote.feeInEth.toString(), - nativeAsset?.decimals || 18, - nativeAsset?.price?.value || '0', - currentCurrency, - ).display, + convertRawAmountToBalance(quote.fee.toString(), { + decimals: quote.feeTokenAsset?.decimals || 18, + symbol: quote.feeTokenAsset?.symbol, + })?.display, `${handleSignificantDecimals(multiply(feePercentage, 100), 2)}%`, ]; }, [ - currentCurrency, - nativeAsset?.decimals, - nativeAsset?.price?.value, - quote.feeInEth, + quote.feeTokenAsset?.decimals, + quote.feeTokenAsset?.symbol, + quote.fee, quote.feePercentageBasisPoints, ]);