Commit cb362f1b authored by Charles Bachmeier's avatar Charles Bachmeier Committed by GitHub

fix: Handle scientific notation for NFT Details pricing (#6707)

* fix: Handle scientific notation for NFT Details pricing

* add test case

---------
Co-authored-by: default avatarCharles Bachmeier <charlie@genie.xyz>
parent a4d61d8e
import { renderHook } from 'test-utils/render'
import { useNftAssetDetails } from './Details'
describe('useNftAssetDetails', () => {
it('should handle listing.price.value of 1e-18 without crashing', () => {
// Mock the useDetailsQuery hook
const mockUseDetailsQuery = jest.fn(() => ({
data: {
nftAssets: {
edges: [
{
node: {
listings: {
edges: [
{
node: {
price: {
value: 1e-18,
},
},
},
],
},
},
},
],
},
},
loading: false,
}))
jest.mock('../__generated__/types-and-hooks', () => ({
useDetailsQuery: mockUseDetailsQuery,
}))
const { result } = renderHook(() => useNftAssetDetails('address', 'tokenId'))
expect(result.current.data[0].priceInfo.ETHPrice).toBe('0')
})
})
import { parseEther } from '@ethersproject/units'
import gql from 'graphql-tag'
import { CollectionInfoForAsset, GenieAsset, Markets, SellOrder } from 'nft/types'
import { wrapScientificNotation } from 'nft/utils'
import { useMemo } from 'react'
import { NftAsset, useDetailsQuery } from '../__generated__/types-and-hooks'
......@@ -105,7 +106,7 @@ export function useNftAssetDetails(
const asset = queryData?.nftAssets?.edges[0]?.node as NonNullable<NftAsset> | undefined
const collection = asset?.collection
const listing = asset?.listings?.edges[0]?.node
const ethPrice = parseEther(listing?.price?.value?.toString() ?? '0').toString()
const ethPrice = parseEther(wrapScientificNotation(listing?.price?.value?.toString() ?? '0')).toString()
return useMemo(
() => ({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment