refactor: scientific notation helper fn (#5479)
* fix listing ens to x2y2 * add helper fn for handling scinetific notation Co-authored-by: Charles Bachmeier <charlie@genie.xyz>
This commit is contained in:
parent
e4ae705eb1
commit
8f44adb038
@ -3,6 +3,7 @@ import { parseEther } from 'ethers/lib/utils'
|
|||||||
import useInterval from 'lib/hooks/useInterval'
|
import useInterval from 'lib/hooks/useInterval'
|
||||||
import ms from 'ms.macro'
|
import ms from 'ms.macro'
|
||||||
import { GenieAsset, Trait } from 'nft/types'
|
import { GenieAsset, Trait } from 'nft/types'
|
||||||
|
import { wrapScientificNotation } from 'nft/utils'
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import { fetchQuery, useLazyLoadQuery, usePaginationFragment, useQueryLoader, useRelayEnvironment } from 'react-relay'
|
import { fetchQuery, useLazyLoadQuery, usePaginationFragment, useQueryLoader, useRelayEnvironment } from 'react-relay'
|
||||||
|
|
||||||
@ -125,13 +126,7 @@ type NftAssetsQueryAsset = NonNullable<
|
|||||||
|
|
||||||
function formatAssetQueryData(queryAsset: NftAssetsQueryAsset, totalCount?: number) {
|
function formatAssetQueryData(queryAsset: NftAssetsQueryAsset, totalCount?: number) {
|
||||||
const asset = queryAsset.node
|
const asset = queryAsset.node
|
||||||
const ethPrice = parseEther(
|
const ethPrice = parseEther(wrapScientificNotation(asset.listings?.edges[0]?.node.price.value ?? 0)).toString()
|
||||||
parseFloat(
|
|
||||||
(asset.listings?.edges[0]?.node.price.value?.toLocaleString('fullwide', { useGrouping: false }) ?? '0')
|
|
||||||
.replace(',', '.')
|
|
||||||
.replace(' ', '')
|
|
||||||
).toString()
|
|
||||||
).toString()
|
|
||||||
return {
|
return {
|
||||||
id: asset.id,
|
id: asset.id,
|
||||||
address: asset?.collection?.nftContracts?.[0]?.address,
|
address: asset?.collection?.nftContracts?.[0]?.address,
|
||||||
|
@ -2,6 +2,7 @@ import graphql from 'babel-plugin-relay/macro'
|
|||||||
import { parseEther } from 'ethers/lib/utils'
|
import { parseEther } from 'ethers/lib/utils'
|
||||||
import { DEFAULT_WALLET_ASSET_QUERY_AMOUNT } from 'nft/components/profile/view/ProfilePage'
|
import { DEFAULT_WALLET_ASSET_QUERY_AMOUNT } from 'nft/components/profile/view/ProfilePage'
|
||||||
import { WalletAsset } from 'nft/types'
|
import { WalletAsset } from 'nft/types'
|
||||||
|
import { wrapScientificNotation } from 'nft/utils'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { useLazyLoadQuery, usePaginationFragment, useQueryLoader } from 'react-relay'
|
import { useLazyLoadQuery, usePaginationFragment, useQueryLoader } from 'react-relay'
|
||||||
|
|
||||||
@ -167,13 +168,7 @@ export function useNftBalanceQuery(
|
|||||||
)
|
)
|
||||||
const walletAssets: WalletAsset[] = data.nftBalances?.edges?.map((queryAsset: NftBalanceQueryAsset) => {
|
const walletAssets: WalletAsset[] = data.nftBalances?.edges?.map((queryAsset: NftBalanceQueryAsset) => {
|
||||||
const asset = queryAsset.node.ownedAsset
|
const asset = queryAsset.node.ownedAsset
|
||||||
const ethPrice = parseEther(
|
const ethPrice = parseEther(wrapScientificNotation(asset?.listings?.edges[0]?.node.price.value ?? 0)).toString()
|
||||||
parseFloat(
|
|
||||||
(asset?.listings?.edges[0]?.node.price.value?.toLocaleString('fullwide', { useGrouping: false }) ?? '0')
|
|
||||||
.replace(',', '.')
|
|
||||||
.replace(' ', '')
|
|
||||||
).toString()
|
|
||||||
).toString()
|
|
||||||
return {
|
return {
|
||||||
id: asset?.id,
|
id: asset?.id,
|
||||||
imageUrl: asset?.image?.url,
|
imageUrl: asset?.image?.url,
|
||||||
|
@ -73,3 +73,11 @@ export const formatWeiToDecimal = (amount: string, removeZeroes = false) => {
|
|||||||
if (!amount) return '-'
|
if (!amount) return '-'
|
||||||
return ethNumberStandardFormatter(formatEther(amount), false, removeZeroes, false)
|
return ethNumberStandardFormatter(formatEther(amount), false, removeZeroes, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prevent BigNumber overflow by properly handling scientific notation and comma delimited values
|
||||||
|
export function wrapScientificNotation(value: string | number): string {
|
||||||
|
return parseFloat(value.toString())
|
||||||
|
.toLocaleString('fullwide', { useGrouping: false })
|
||||||
|
.replace(',', '.')
|
||||||
|
.replace(' ', '')
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@ import {
|
|||||||
} from '../queries'
|
} from '../queries'
|
||||||
import { INVERSE_BASIS_POINTS, OPENSEA_DEFAULT_FEE, OPENSEA_FEE_ADDRESS } from '../queries/openSea'
|
import { INVERSE_BASIS_POINTS, OPENSEA_DEFAULT_FEE, OPENSEA_FEE_ADDRESS } from '../queries/openSea'
|
||||||
import { ListingMarket, ListingStatus, WalletAsset } from '../types'
|
import { ListingMarket, ListingStatus, WalletAsset } from '../types'
|
||||||
|
import { wrapScientificNotation } from './currency'
|
||||||
import { createSellOrder, encodeOrder, OfferItem, OrderPayload, signOrderData } from './x2y2'
|
import { createSellOrder, encodeOrder, OfferItem, OrderPayload, signOrderData } from './x2y2'
|
||||||
|
|
||||||
export const LOOKS_RARE_CREATOR_BASIS_POINTS = 50
|
export const LOOKS_RARE_CREATOR_BASIS_POINTS = 50
|
||||||
@ -240,12 +241,7 @@ export async function signListing(
|
|||||||
tokens: [
|
tokens: [
|
||||||
{
|
{
|
||||||
token: asset.asset_contract.address,
|
token: asset.asset_contract.address,
|
||||||
tokenId: BigNumber.from(
|
tokenId: BigNumber.from(wrapScientificNotation(asset.tokenId)),
|
||||||
parseFloat(asset.tokenId)
|
|
||||||
.toLocaleString('fullwide', { useGrouping: false })
|
|
||||||
.replace(',', '.')
|
|
||||||
.replace(' ', '')
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user