fix: Handle scientific notation for NFT Details pricing (#6707)
* fix: Handle scientific notation for NFT Details pricing * add test case --------- Co-authored-by: Charles Bachmeier <charlie@genie.xyz>
This commit is contained in:
parent
a4d61d8eaa
commit
cb362f1b2c
38
src/graphql/data/nft/Details.test.ts
Normal file
38
src/graphql/data/nft/Details.test.ts
Normal file
@ -0,0 +1,38 @@
|
||||
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')
|
||||
})
|
||||
})
|
@ -1,6 +1,7 @@
|
||||
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(
|
||||
() => ({
|
||||
|
Loading…
Reference in New Issue
Block a user