From c0cb7337f2d264243a4863e38798c6b9ffe59a6e Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 4 Nov 2024 13:46:16 -0500 Subject: [PATCH] fix: update last sold price (#1565) --- src/nft/components/mint/NFTAssetCost.tsx | 4 ++- .../components/view/NFTLastSoldPrice.test.tsx | 25 ++++++++++++++++--- src/nft/components/view/NFTLastSoldPrice.tsx | 5 ++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/nft/components/mint/NFTAssetCost.tsx b/src/nft/components/mint/NFTAssetCost.tsx index 895e4f3c55..065dfb4c86 100644 --- a/src/nft/components/mint/NFTAssetCost.tsx +++ b/src/nft/components/mint/NFTAssetCost.tsx @@ -1,5 +1,6 @@ import { multiplyFloats } from '../../../internal/utils/multiplyFloats'; import { cn, text } from '../../../styles/theme'; +import { formatAmount as formatSN } from '../../../swap/utils/formatAmount'; import { formatAmount } from '../../../token/utils/formatAmount'; import { useNFTContext } from '../NFTProvider'; @@ -25,7 +26,8 @@ export function NFTAssetCost({ className }: NFTAssetCostReact) { return (
- {multiplyFloats(Number(price.amount), quantity)} {price.currency} + {formatSN(`${multiplyFloats(Number(price.amount), quantity)}`)}{' '} + {price.currency}
~
diff --git a/src/nft/components/view/NFTLastSoldPrice.test.tsx b/src/nft/components/view/NFTLastSoldPrice.test.tsx index d5335e88b3..10ced254f7 100644 --- a/src/nft/components/view/NFTLastSoldPrice.test.tsx +++ b/src/nft/components/view/NFTLastSoldPrice.test.tsx @@ -33,11 +33,26 @@ describe('NFTLastSoldPrice', () => { it('should render', () => { const { getByText } = render(); - expect(getByText('Mint price')).toBeInTheDocument(); + expect(getByText('Last sale price')).toBeInTheDocument(); expect(getByText('1 ETH')).toBeInTheDocument(); expect(getByText('$3,000.00')).toBeInTheDocument(); }); + it('should render scientific notation', () => { + (useNFTContext as Mock).mockReturnValue({ + lastSoldPrice: { + amount: '5e-05', + currency: 'ETH', + amountUSD: '0.13', + }, + }); + + const { getByText } = render(); + expect(getByText('Last sale price')).toBeInTheDocument(); + expect(getByText('0.00005 ETH')).toBeInTheDocument(); + expect(getByText('$0.13')).toBeInTheDocument(); + }); + it('should render null if price is not available', () => { (useNFTContext as Mock).mockReturnValue({ lastSoldPrice: { @@ -59,11 +74,13 @@ describe('NFTLastSoldPrice', () => { it('should apply custom className', () => { const { getByText } = render(); - expect(getByText('Mint price').parentElement).toHaveClass('custom-class'); + expect(getByText('Last sale price').parentElement).toHaveClass( + 'custom-class', + ); }); it('should display custom label', () => { - const { getByText } = render(); - expect(getByText('Last Sold Price')).toBeInTheDocument(); + const { getByText } = render(); + expect(getByText('Mint Price')).toBeInTheDocument(); }); }); diff --git a/src/nft/components/view/NFTLastSoldPrice.tsx b/src/nft/components/view/NFTLastSoldPrice.tsx index f2aa804a21..0aa34b07c7 100644 --- a/src/nft/components/view/NFTLastSoldPrice.tsx +++ b/src/nft/components/view/NFTLastSoldPrice.tsx @@ -1,5 +1,6 @@ import type { ReactNode } from 'react'; import { cn, color, text } from '../../../styles/theme'; +import { formatAmount as formatSN } from '../../../swap/utils/formatAmount'; import { formatAmount } from '../../../token/utils/formatAmount'; import { useNFTContext } from '../NFTProvider'; @@ -10,7 +11,7 @@ type NFTLastSoldPriceReact = { export function NFTLastSoldPrice({ className, - label = 'Mint price', + label = 'Last sale price', }: NFTLastSoldPriceReact) { const { lastSoldPrice } = useNFTContext(); @@ -29,7 +30,7 @@ export function NFTLastSoldPrice({
{label}
- {amount} {currency} + {formatSN(amount)} {currency}
~