Skip to content

Commit

Permalink
feat: add fee in native token on swap review sheet (#1725)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Sinclair <[email protected]>
  • Loading branch information
derHowie and DanielSinclair authored Oct 18, 2024
1 parent f45589c commit b3b0051
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/entries/popup/hooks/swap/useSwapReviewDetails.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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,
]);

Expand Down

0 comments on commit b3b0051

Please sign in to comment.