From da90738ba182bb83dd88ac8ba7227056e0c503a9 Mon Sep 17 00:00:00 2001 From: Charles Bachmeier Date: Fri, 14 Jul 2023 09:54:48 -0700 Subject: [PATCH] fix: Handle Scientific Notation for NFT Collection Activity Prices (#6936) wrap nft activity price in --- src/graphql/data/nft/NftActivity.ts | 3 ++- src/nft/utils/currency.ts | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/graphql/data/nft/NftActivity.ts b/src/graphql/data/nft/NftActivity.ts index e0d4bcca81..afb90c2dae 100644 --- a/src/graphql/data/nft/NftActivity.ts +++ b/src/graphql/data/nft/NftActivity.ts @@ -1,6 +1,7 @@ import { WatchQueryFetchPolicy } from '@apollo/client' import gql from 'graphql-tag' import { ActivityEvent } from 'nft/types' +import { wrapScientificNotation } from 'nft/utils' import { useCallback, useMemo } from 'react' import { NftActivityFilterInput, useNftActivityQuery } from '../__generated__/types-and-hooks' @@ -120,7 +121,7 @@ export function useNftActivity(filter: NftActivityFilterInput, first?: number, f toAddress: activity.toAddress, transactionHash: activity.transactionHash, orderStatus: activity.orderStatus, - price: activity.price?.value.toString(), + price: wrapScientificNotation(activity.price?.value), symbol: asset?.collection?.image?.url, quantity: activity.quantity, url: activity.url, diff --git a/src/nft/utils/currency.ts b/src/nft/utils/currency.ts index 6be4569d53..8facf44b6a 100644 --- a/src/nft/utils/currency.ts +++ b/src/nft/utils/currency.ts @@ -75,9 +75,8 @@ export const formatWeiToDecimal = (amount: string, 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(' ', '') +export function wrapScientificNotation(value?: string | number): string { + return value + ? parseFloat(value.toString()).toLocaleString('fullwide', { useGrouping: false }).replace(',', '.').replace(' ', '') + : '' }